$hashType
$hashType : string
Default hash method. If `$type` param for `Security::hash()` is not specified this value is used. Defaults to 'sha1'.
Security Library contains utility methods related to security
hash(string $string, string|null $algorithm = null, mixed $salt = false) : string
Create a hash from string using given method.
string | $string | String to hash |
string|null | $algorithm | Hashing algo to use (i.e. sha1, sha256 etc.).
Can be any valid algo included in list returned by hash_algos().
If no value is passed the type specified by |
mixed | $salt | If true, automatically prepends the application's salt value to $string (Security.salt). |
Hash
randomBytes(integer $length) : string
Get random bytes from a secure source.
This method will fall back to an insecure source an trigger a warning if it cannot find a secure source of random data.
integer | $length | The number of bytes you want. |
Random bytes in binary.
engine(\Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt|null $instance = null) : \Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt
Get the crypto implementation based on the loaded extensions.
You can use this method to forcibly decide between mcrypt/openssl/custom implementations.
\Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt|null | $instance | The crypto instance to use. |
When no compatible crypto extension is available.
Crypto instance.
rijndael(string $text, string $key, string $operation) : string
Encrypts/Decrypts a text using the given key using rijndael method.
string | $text | Encrypted string to decrypt, normal string to encrypt |
string | $key | Key to use as the encryption key for encrypted data. |
string | $operation | Operation to perform, encrypt or decrypt |
When there are errors.
Encrypted/Decrypted string.
encrypt(string $plain, string $key, string|null $hmacSalt = null) : string
Encrypt a value using AES-256.
Caveat You cannot properly encrypt/decrypt data with trailing null bytes. Any trailing null bytes will be removed on decryption due to how PHP pads messages with nulls prior to encryption.
string | $plain | The value to encrypt. |
string | $key | The 256 bit/32 byte key to use as a cipher key. |
string|null | $hmacSalt | The salt to use for the HMAC process. Leave null to use Security.salt. |
On invalid data or key.
Encrypted data.
None found |
decrypt(string $cipher, string $key, string|null $hmacSalt = null) : string|boolean
Decrypt a value using AES-256.
string | $cipher | The ciphertext to decrypt. |
string | $key | The 256 bit/32 byte key to use as a cipher key. |
string|null | $hmacSalt | The salt to use for the HMAC process. Leave null to use Security.salt. |
On invalid data or key.
Decrypted data. Any trailing null bytes will be removed.
None found |
constantEquals(string $original, string $compare) : boolean
A timing attack resistant comparison that prefers native PHP implementations.
string | $original | The original value. |
string | $compare | The comparison value. |
since | 3.6.2 |
---|
getSalt() : string
Gets the HMAC salt to be used for encryption/decryption routines.
The currently configured salt
None found |
setSalt(string $salt) : void
Sets the HMAC salt to be used for encryption/decryption routines.
string | $salt | The salt to use for encryption routines. |
None found |
salt(string|null $salt = null) : string
Gets or sets the HMAC salt to be used for encryption/decryption routines.
string|null | $salt | The salt to use for encryption routines. If null returns current salt. |
The currently configured salt
None found |
_checkKey(string $key, string $method) : void
Check the encryption key for proper length.
string | $key | Key to check. |
string | $method | The method the key is being checked for. |
When key length is not 256 bit/32 bytes
None found |