Crypt
class Crypt (View source)
Utility class for cryptographically-secure string handling routines.
Methods
Returns a string of highly randomized bytes (over the full 8-bit range).
Calculates a base-64 encoded, URL-safe sha-256 hmac.
Calculates a base-64 encoded, URL-safe sha-256 hash.
Returns a URL-safe, base64 encoded string of highly randomized bytes.
Details
static string
randomBytes(int $count)
deprecated
deprecated
Returns a string of highly randomized bytes (over the full 8-bit range).
This function is better than simply calling mt_rand() or any other built-in PHP function because it can return a long string of bytes (compared to < 4 bytes normally from mt_rand()) and uses the best available pseudo-random source.
In PHP 7 and up, this uses the built-in PHP function random_bytes(). In older PHP versions, this uses the random_bytes() function provided by the random_compat library, or the fallback hash-based generator from Drupal 7.x.
static string
hmacBase64(mixed $data, mixed $key)
Calculates a base-64 encoded, URL-safe sha-256 hmac.
static string
hashBase64(string $data)
Calculates a base-64 encoded, URL-safe sha-256 hash.
static bool
hashEquals(string $known_string, string $user_string)
deprecated
deprecated
Compares strings in constant time.
static string
randomBytesBase64($count = 32)
Returns a URL-safe, base64 encoded string of highly randomized bytes.