des encryption is an encryption method that is widely used on the Internet in symmetric encryption. PHP supports des encryption through the mcrypt extension library. To use des encryption in Php, you need to install the mcrypt extension library first
The following is Examples of encryption and decryption
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $key = "This is a very secret key";//密钥 $text = "Meet me at 11 o'clock behind the monument.";//需要加密的内容 echo ($text) . "\n"; $crypttext =base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv)); echo $crypttext . "\n";//加密后的内容 echo mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$key,base64_decode($crypttext),MCRYPT_MODE_ECB,$iv);//解密后的内容
In the AES encryption algorithm, MCRYPT_RIJNDAEL_128, MCRYPT_RIJNDAEL_192, and MCRYPT_RIJNDAEL_256 are usually used. The following 128, 192, and 256 represent the number of bits of the secret key (that is, the encrypted Key). For example, using is MCRYPT_RIJNDAEL_128, then the secret key length is 128 bit when encrypted using this algorithm, for example $key = 'fjjda0&9^$$#+*%$fada' is 20 characters. In actual encryption, only the first 16 characters are used for encryption (16*8=128). PHP with less than 128bit will use '