Security Library contains utility methods related to security
object
string
string
Default hash method. If $type
param for Security::hash()
is not specified this value is used. Defaults to 'sha1'.
Gets or sets the HMAC salt to be used for encryption/decryption routines.
Sets the default hash method for the Security object. This affects all objects using Security::hash().
_checkKey( string $key , string $method )
Check the encryption key for proper length.
$key
$method
_constantEquals( string $hmac , string $compare )
A timing attack resistant comparison that prefers native PHP implementations.
$hmac
$compare
decrypt( string $cipher , string $key , string|null $hmacSalt null )
Decrypt a value using AES-256.
$cipher
$key
$hmacSalt
optional null encrypt( string $plain , string $key , string|null $hmacSalt null )
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.
$plain
$key
$hmacSalt
optional null engine( object|null $instance null )
Get the crypto implementation based on the loaded extensions.
You can use this method to forcibly decide between mcrypt/openssl/custom implementations.
$instance
optional null hash( string $string , string|null $type null , mixed $salt false )
Create a hash from string using given method.
$string
$type
optional null 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 Security::$hashType
is used.
$salt
optional false If true, automatically prepends the application's salt value to $string (Security.salt).
insecureRandomBytes( integer $length )
Like randomBytes() above, but not cryptographically secure.
$length
randomBytes( integer $length )
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.
$length
rijndael( string $text , string $key , string $operation )
Encrypts/Decrypts a text using the given key using rijndael method.
$text
$key
$operation
salt( string|null $salt null )
Gets or sets the HMAC salt to be used for encryption/decryption routines.
$salt
optional null setHash( string $hash )
Sets the default hash method for the Security object. This affects all objects using Security::hash().
$hash
public static string
Default hash method. If $type
param for Security::hash()
is not specified this value is used. Defaults to 'sha1'.
'sha1'
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.Utility.Security.html