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 the HMAC salt to be used for encryption/decryption routines.
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().
Sets the HMAC salt to be used for encryption/decryption routines.
_checkKey( string $key , string $method )
Check the encryption key for proper length.
$key
$method
constantEquals( string $original , string $compare )
A timing attack resistant comparison that prefers native PHP implementations.
$original
$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( Cake\Utility\Crypto\OpenSsl|Cake\Utility\Crypto\Mcrypt|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 getSalt( )
Gets the HMAC salt to be used for encryption/decryption routines.
hash( string $string , string|null $algorithm = null , mixed $salt = false )
Create a hash from string using given method.
$string
$algorithm
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
randomString( integer $length = 64 )
Creates a secure random string.
$length
optional 64 rijndael( string $text , string $key , string $operation )
Encrypts/Decrypts a text using the given key using rijndael method.
3.6.3 This method relies on functions provided by mcrypt extension which has been deprecated in PHP 7.1 and removed in PHP 7.2. There's no 1:1 replacement for this method. Upgrade your code to use Security::encrypt()/Security::decrypt() with OpenSsl engine instead.
$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
setSalt( string $salt )
Sets the HMAC salt to be used for encryption/decryption routines.
$salt
public static string
Default hash method. If $type
param for Security::hash()
is not specified this value is used. Defaults to 'sha1'.
'sha1'
© 2005–present 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.8/class-Cake.Utility.Security.html