Home > Article > Backend Development > Php Aes encryption program code sharing_PHP tutorial
Today I had nothing to do with a Php Aes encryption program. It is an extension suitable for Yii. If it is not used in the Yii framework, replace Yii::app()->params['encryptKey'] in the code with your corresponding default key. That's it.
AES Encryption Algorithm – Algorithm Principle
The AES algorithm is based on permutation and permutation operations. Permutation is the rearrangement of data, and permutation is the replacement of one data unit with another. AES uses several different methods to perform permutation and permutation operations.
AES is an iterative, symmetric key-blocked cipher that can use 128-, 192-, and 256-bit keys and encrypt and decrypt data in 128-bit (16-byte) blocks. Unlike public key ciphers which use key pairs, symmetric key ciphers use the same key to encrypt and decrypt data. The encrypted data returned by the block cipher has the same number of bits as the input data. Iterative encryption uses a loop structure in which the input data is repeatedly permuted and replaced.
The code is as follows | Copy code |
/** /* Encrypt data */ /* Terminate encryption handler */ /** $ciphertext_dec = base64_decode($encrypted); $iv = substr(md5($key),0,mcrypt_enc_get_iv_size($module)); /* Initialize encryption module for decryption */ /* Decrypt encrypted string */ /* Terminate decryption handle and close module */
private static function substr($string,$start,$length) private static function PKCS5Padding ($text, $blocksize) { private static function UnPKCS5Padding($text) |
How to use
The code is as follows
|
Copy code | ||||
//$aes = new AES();