cfusion_encrypt php替代方案

时间:2010-10-12 23:20:43

标签: php encryption coldfusion

有人知道对coldfusion的cfusion_encrypt的任何替代PHP吗?

目前cfusion_encrypt仍然通过curl使用,因为cf服务器一直在运行,因此麻烦很多。如果有人能给我一个替代这个功能的php会好得多。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用mcrypt(http://php.net/manual/en/book.mcrypt.php

喜欢这个?请参阅清单4 http://onlamp.com/pub/a/php/2001/07/26/encrypt.html?page=3

<?php

// Designate string to be encrypted
$string = "Applied Cryptography, by Bruce Schneier, is 
a wonderful cryptography reference.";

// Encryption/decryption key
$key = "Four score and twenty years ago";

// Encryption Algorithm
$cipher_alg = MCRYPT_RIJNDAEL_128;

// Create the initialization vector for added security.
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, 
MCRYPT_MODE_ECB), MCRYPT_RAND);

// Output original string
print "Original string: $string <p>";

// Encrypt $string
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, 
$string, MCRYPT_MODE_CBC, $iv);

// Convert to hexadecimal and output to browser
print "Encrypted string: ".bin2hex($encrypted_string)."<p>";

$decrypted_string = mcrypt_decrypt($cipher_alg, $key, 
$encrypted_string, MCRYPT_MODE_CBC, $iv);

print "Decrypted string: $decrypted_string";

?>

执行清单4将产生以下输出:

原始字符串:Bruce Schneier的Applied Cryptography,是一个很棒的加密参考。

加密字符串:02a7c58b1ebd22a9523468694b091e60411cc4dea8652bb8072 34fa06bbfb20e71ecf525f29df58e28f3d9bf541f7ebcecf62b c89fde4d8e7ba1e6cc9ea24850478c11742f5cfa1d23fe22fe8 bfbab5e

解密字符串:Bruce Schneier编写的“应用密码学”,是一本精彩的密码学参考书。