Home > Article > Backend Development > Simple AES encryption and decryption algorithm implemented in PHP
This article mainly introduces the simple AES encryption and decryption algorithm implemented by PHP, and analyzes the related operation skills of PHP for string encryption and decryption based on mcrypt_encrypt, bin2hex, mcrypt_decrypt and other methods based on specific examples. Friends in need can refer to the following
The example in this article describes the simple AES encryption and decryption algorithm of PHP. Share it with everyone for your reference, the details are as follows:
/* * 实现AES加密 * $str : 要加密的字符串 * $keys : 加密密钥 * $iv : 加密向量 * $cipher_alg : 加密方式 */ function ecryptdString($str,$keys="6461772803150152",$iv="8105547186756005",$cipher_alg=MCRYPT_RIJNDAEL_128){ $encrypted_string = bin2hex(mcrypt_encrypt($cipher_alg, $keys, $str, MCRYPT_MODE_CBC,$iv)); return $encrypted_string; } /* * 实现AES解密 * $str : 要解密的字符串 * $keys : 加密密钥 * $iv : 加密向量 * $cipher_alg : 加密方式 */ function decryptStrin($str,$keys="6461772803150152",$iv="8105547186756005",$cipher_alg=MCRYPT_RIJNDAEL_128){ $decrypted_string = mcrypt_decrypt($cipher_alg, $keys, pack("H*",$str),MCRYPT_MODE_CBC, $iv); return $decrypted_string; }
## Related recommendations:
php implements DES that is consistent with c#encryption and decryptionmethod
PHP’s RSA Encryption and decryptionUsage analysis of development interface cases
Encryption and decryption, verification and signature
##
The above is the detailed content of Simple AES encryption and decryption algorithm implemented in PHP. For more information, please follow other related articles on the PHP Chinese website!