public static function digest($string, $key)
Digest a string for general use, including use which relates to security.
| string | $string | Input string. |
| $key |
| string | 32-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.
| PhutilOpaqueEnvelope | $envelope | |
| $salt |
| 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()).
| string | $string | Input string. |
| string | 12-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.
| string | $string | The string to shorten. |
| int | $length | Maximum length of the result. |
| string | String shortened in a collision-resistant way. |