2010-10-12 56 views
0

有沒有人知道任何PHP的替代coldfusion的cfusion_encrypt?cfusion_encrypt php替代

目前cfusion_encrypt仍然通過curl使用,並且由於cf服務器不斷關閉而出現問題。如果有人能給我一個這個函數的php替代品,那將會好很多。

謝謝。

+2

您應該鏈接到該功能的文檔資源,以便熟悉PHP但不是CF的人可以找出它的功能 – 2010-10-12 23:22:16

+0

http://www.fusionauthority.com/techniques/2613-crypto-in-coldfusion.htm – uji 2010-10-12 23:32:42

回答

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將產生以下的輸出:

原始字符串:應用密碼學,由布魯斯,是一個美妙的密碼參考。

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

解密的字符串:應用密碼學,由布魯斯,是一個美妙的密碼參考。

+0

喜。謝謝回覆。你知道我必須使用什麼密碼才能使用cfusion_encrypt獲得相同的結果嗎? – uji 2010-10-14 02:02:00

+0

默認情況下,CF將使用CFMX_COMPAT算法......我不確定您將不得不進行實驗,但如果它是專有的,它可能無法用於PHP。 – jfrobishow 2010-10-14 17:35:27

+1

你不希望它也可用。 CFMX_COMPAT是遺留的,不推薦使用的,並且非常不安全。不要使用它。 ColdFusion和PHP都有很多*遠*更好的算法可用。 – 2011-10-05 18:22:48