class Crypt (View source)

Utility class for cryptographically-secure string handling routines.

Methods

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 string
randomBytesBase64($count = 32)

Returns a URL-safe, base64 encoded string of highly randomized bytes.

Details

static string hmacBase64(mixed $data, mixed $key)

Calculates a base-64 encoded, URL-safe sha-256 hmac.

Parameters

mixed $data

Scalar value to be validated with the hmac.

mixed $key

A secret key, this can be any scalar value.

Return Value

string

A base-64 encoded sha-256 hmac, with + replaced with -, / with _ and any = padding characters removed.

static string hashBase64(string $data)

Calculates a base-64 encoded, URL-safe sha-256 hash.

Parameters

string $data

String to be hashed.

Return Value

string

A base-64 encoded sha-256 hash, with + replaced with -, / with _ and any = padding characters removed.

static string randomBytesBase64($count = 32)

Returns a URL-safe, base64 encoded string of highly randomized bytes.

Parameters

$count

The number of random bytes to fetch and base64 encode.

Return Value

string

A base-64 encoded string, with + replaced with -, / with _ and any = padding characters removed.