Page MenuHomePhabricator

final class PhabricatorHash
Phabricator Technical Documentation ()

This class is not documented.

Methods

public static function digest($string, $key)

Digest a string for general use, including use which relates to security.

Parameters
string$stringInput string.
$key
Return
string32-byte hexidecimal SHA1+HMAC hash.

public static function digestPassword($envelope, $salt)

Digest a string into a password hash. This is similar to digest(), but requires a salt and iterates the hash to increase cost.

Parameters
PhutilOpaqueEnvelope$envelope
$salt
Return
wild

public static function digestForIndex($string)

Digest a string for use in, e.g., a MySQL index. This produces a short (12-byte), case-sensitive alphanumeric string with 72 bits of entropy, which is generally safe in most contexts (notably, URLs).

This method emphasizes compactness, and should not be used for security related hashing (for general purpose hashing, see digest()).

Parameters
string$stringInput string.
Return
string12-byte, case-sensitive alphanumeric hash of the string which

public static function digestToLength($string, $length)

Shorten a string to a maximum byte length in a collision-resistant way while retaining some degree of human-readability.

This function converts an input string into a prefix plus a hash. For example, a very long string beginning with "crabapplepie..." might be digested to something like "crabapp-N1wM1Nz3U84k".

This allows the maximum length of identifiers to be fixed while maintaining a high degree of collision resistance and a moderate degree of human readability.

Parameters
string$stringThe string to shorten.
int$lengthMaximum length of the result.
Return
stringString shortened in a collision-resistant way.