Skip to main content

Zymba Documentation

Crypt

object @Crypt() {
convertPublicKeyRSAToPEM(string $exponent, string $modulus): string {}
createIV(string $cipher): string {}
createJWT(object $claims, string $key, string $algorithm, object $header): string {}
createNonce(int $size): string {}
createNonceRaw(int $size): string {}
createPassword(int $length): string {}
createTimeOrderedUUID(): string {}
createUUID(): string {}
decrypt(string $string, string $key, string $cipher, string $iv): string {}
encrypt(string $string, string $key, string $cipher, string $iv): string {}
equalsTimeConstant(string $secret, string $input): bool {}
hash(string $string, string $algorithm, ?string $key): string {}
hashFile(string $path, string $algorithm, ?string $key): string {}
hashFileRaw(string $path, string $algorithm, ?string $key): string {}
hashRaw(string $string, string $algorithm, ?string $key): string {}
listCiphers(): object {}
listHashAlgorithms(): object {}
pbkdf2(string $password, string $salt, string $algorithm, int $iterations, int $length): string {}
pbkdf2Raw(string $password, string $salt, string $algorithm, int $iterations, int $length): string {}
verifyJWT(string $jwt, string $key): object {}
verifyPasswordPHP(string $password, string $hash): bool {}
}

Static cryptographic functions.

Functions

Converts a raw RSA exponent and modulus to a public key in PEM format.

@Crypt.convertPublicKeyRSAToPEM(string $exponent, string $modulus): string
Parameters
NameTypeValueDefault
exponentstring""
modulusstring""
Returns
TypeValue
string

Creates a suitable initialization vector for a specific cipher from a random source.

@Crypt.createIV(string $cipher): string
Parameters
NameTypeValueDefault
cipherstring"aes-192-ecb"
Returns
TypeValue
string

Creates a JSON Web Token (JWT) according to RFC 7519.

@Crypt.createJWT(object $claims, string $key, string $algorithm, object $header): string
Parameters
NameTypeValueDefault
claimsobject[name: value][]
keystring""
algorithmstring"HS256"
headerobject[name: value][]
Returns
TypeValue
string

Creates a nonce of a specific size in number of bytes from a random source in its hexadecimal string representation.

@Crypt.createNonce(int $size): string
Parameters
NameTypeValueDefault
sizeint20
Returns
TypeValue
string

Creates a nonce of a specific size in number of bytes from a random source as raw binary data.

@Crypt.createNonceRaw(int $size): string
Parameters
NameTypeValueDefault
sizeint20
Returns
TypeValue
string

Creates a secure password of a specific length in number of characters from a random source.

@Crypt.createPassword(int $length): string
Parameters
NameTypeValueDefault
lengthint10
Returns
TypeValue
string

Creates a version 7 universally unique identifier (UUID) from the current timestamp and a random source according to RFC 4122.

@Crypt.createTimeOrderedUUID(): string
Returns
TypeValue
string

Creates a version 4 universally unique identifier (UUID) from a random source according to RFC 4122.

@Crypt.createUUID(): string
Returns
TypeValue
string

Decryptes a string with a specific key.

@Crypt.decrypt(string $string, string $key, string $cipher, string $iv): string
Parameters
NameTypeValueDefault
stringstring""
keystring""
cipherstring"aes-192-ecb"
ivstring""
Returns
TypeValue
string
null

Encryptes a string with a specific key.

@Crypt.encrypt(string $string, string $key, string $cipher, string $iv): string
Parameters
NameTypeValueDefault
stringstring""
keystring""
cipherstring"aes-192-ecb"
ivstring""
Returns
TypeValue
string

Determines whether two strings are equal based on time-constant string comparison that guards against timing attacks.

@Crypt.equalsTimeConstant(string $secret, string $input): bool
Parameters
NameTypeValueDefault
secretstring""
inputstring""
Returns
TypeValue
bool

Generates the hash of a string in its hexadecimal string representation using a specific algorithm.

@Crypt.hash(string $string, string $algorithm, ?string $key): string
Parameters
NameTypeValueDefault
stringstring""
algorithmstring"sha1"
key?stringnon-HMAC
Returns
TypeValue
string

Generates the hash of the content of an existing file in its hexadecimal string representation using a specific algorithm.

@Crypt.hashFile(string $path, string $algorithm, ?string $key): string
Parameters
NameTypeValueDefault
pathstring""
algorithmstring"sha1"
key?stringnon-HMAC
Returns
TypeValue
string

Generates the hash of the content of an existing file as raw binary data using a specific algorithm.

@Crypt.hashFileRaw(string $path, string $algorithm, ?string $key): string
Parameters
NameTypeValueDefault
pathstring""
algorithmstring"sha1"
key?stringnon-HMAC
Returns
TypeValue
string

Generates the hash of a string as raw binary data using a specific algorithm.

@Crypt.hashRaw(string $string, string $algorithm, ?string $key): string
Parameters
NameTypeValueDefault
stringstring""
algorithmstring"sha1"
key?stringnon-HMAC
Returns
TypeValue
string

Lists all available ciphers.

@Crypt.listCiphers(): object
Returns
TypeValue
object[cipher, ...]

Lists all available hash algorithms.

@Crypt.listHashAlgorithms(): object
Returns
TypeValue
object[algorithm, ...]

Generatesa a PBKDF2 key derived from a password along with a salt in its hexadecimal string representation using a specific algorithm according to RFC 2898.

@Crypt.pbkdf2(string $password, string $salt, string $algorithm, int $iterations, int $length): string
Parameters
NameTypeValueDefault
passwordstring""
saltstring""
algorithmstring"sha1"
iterationsint10000
lengthintfull key length
Returns
TypeValue
string

Generates a PBKDF2 key derived from a password along with a salt as raw binary data using a specific algorithm according to RFC 2898.

@Crypt.pbkdf2Raw(string $password, string $salt, string $algorithm, int $iterations, int $length): string
Parameters
NameTypeValueDefault
passwordstring""
saltstring""
algorithmstring"sha1"
iterationsint10000
lengthintfull key length
Returns
TypeValue
string

Verify a JSON Web Token (JWT) against a specific key according to RFC 7519 and returns it's header parameters and claims.

@Crypt.verifyJWT(string $jwt, string $key): object
Parameters
NameTypeValueDefault
jwtstring""
keystring""
Returns
TypeValue
object["header": [name: value, ...], "claims": [name: value, ...]]
null

Verify a password against a specific PHP password hash.

@Crypt.verifyPasswordPHP(string $password, string $hash): bool
Parameters
NameTypeValueDefault
passwordstring""
hashstring""
Returns
TypeValue
bool