\Disco\classesCrypt

Crypt class.

Provides easy wrapper around mycrpt_php module.

Summary

Methods
Properties
Constants
generateNewCryptKey()
encrypt()
decrypt()
hash()
hashAndGenerateNewSalt()
timingSafeCompare()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

generateNewCryptKey()

generateNewCryptKey() : string

Generate a new key that can be used with the `crypt` and `decrypt` methods of this class.

Uses \Defuse\Crypto\Key::createNewRandomKey()->saveToAsciiSafeString() to generate the key.

Returns

string —

The key.

encrypt()

encrypt(string  $input, null|string  $key256 = null) : string

Encrypt with AES256.

This method relies on the settings in application config AES_KEY256 which is generated at install to a unique key for your application. You can use a different key by passing it in at $key256.

Parameters

string $input

Value to encrypt using AES256.

null|string $key256

An options key used to perform the decryption with instead of the AES_KEY256.

Returns

string —

The encrypted value of $input.

decrypt()

decrypt(string  $crypt, null|string  $key256 = null) : string

Decrypt with AES256.

This method relies on the settings in application config AES_KEY256 which is generated at install to a unique key for your application. You can use a different key by passing it in at $key256.

Parameters

string $crypt

Value to decrypt using AES256.

null|string $key256

An options key used to perform the decryption with instead of the AES_KEY256.

Returns

string —

The decrypted value of $crypt.

hash()

hash(string  $value, null|string  $salt = '') : string

Hash with sha512.

If no salt is provided the salt stored in app/config/config.php with key SHA512_SALT will be used as the salt value.

Parameters

string $value

Value to hash using SHA512.

null|string $salt

The salt to use in the hash.

Returns

string —

The hashed value of $s.

hashAndGenerateNewSalt()

hashAndGenerateNewSalt(string  $value, integer  $saltLength = 128) : array

Hash with sha512.

Generate a new salt and hash the value with it, returning both the salt and hash.

Parameters

string $value

The value to hash using sha512.

integer $saltLength

The length of the salt to generate, defaults to 128.

Returns

array —

An array with two keys, salt and hash, containing the salt and hash value respectivly.

timingSafeCompare()

timingSafeCompare(string  $safe, string  $user) : boolean

Perform a timing safe compare.

Parameters

string $safe
string $user

Returns

boolean