Rumah >pembangunan bahagian belakang >tutorial php >关于PHP的MCRYPT的解密有关问题
关于PHP的MCRYPT的解密问题
最近想找一个PHP的密匙可逆加密函数
几经周折找到了MCRYPT。并在网上找到了一个DEMO
<?php <br />// Designate string to be encrypted <br />$string = "song"; <br />// Encryption/decryption key <br />$key = "memeda"; <br />// Encryption Algorithm <br />$cipher_alg = MCRYPT_RIJNDAEL_128; <br />// Create the initialization vector for added security. <br />$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND); <br />// Output original string <br />print "Original string: $string <p>"; <br />// Encrypt $string <br />$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv); <br />// Convert to hexadecimal and output to browser <br />print "Encrypted string: ".bin2hex($encrypted_string)."<p>"; <br />$decrypted_string = mcrypt_decrypt($cipher_alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv); <br />print "Decrypted string: $decrypted_string"; <br />?>