public static function weakDigest($string, $key)
Digest a string using HMAC+SHA1.
Because a SHA1 collision is now known, this method should be considered weak. Callers should prefer digestWithNamedKey().
string | $string | Input string. |
$key |
string | 32-byte hexadecimal SHA1+HMAC hash. |
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, mostly-alphanumeric hash of the string. |
public static function digestForAnchor($string)
Digest a string for use in HTML page anchors. This is similar to digestForIndex() but produces purely alphanumeric output.
This tries to be mostly compatible with the index digest to limit how much stuff we're breaking by switching to it. For additional discussion, see T13045.
string | $string | Input string. |
string | 12-byte, case-sensitive, purely-alphanumeric hash of the string. |
public static function digestToRange($string, $min, $max)
$string | ||
$min | ||
$max |
wild |
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. |
public static function digestWithNamedKey($message, $key_name)
$message | ||
$key_name |
wild |
public static function digestHMACSHA256($message, $key)
$message | ||
$key |
wild |
private static function getNamedHMACKey($hmac_name)
$hmac_name |
wild |
private static function newHMACKey($hmac_name)
$hmac_name |
wild |
private static function writeHMACKey($hmac_name, $hmac_key)
$hmac_name | ||
$hmac_key |
wild |
private static function readHMACKey($hmac_name)
$hmac_name |
wild |