2011-01-06 235 views
0
 
set_include_path('./phpseclib0.2.1a'); //http://phpseclib.sourceforge.net/ 
include('Crypt/AES.php'); 

$plaintext = 'PLAINTEXT'; 

$aes = new Crypt_AES(CRYPT_AES_MODE_CBC); 
$aes->setKey('1234123412341234'); 
$ciphertext = $aes->encrypt($plaintext); 
$fp = fopen("ciphertextAES", "wb"); 
fwrite($fp, $ciphertext); 
fclose($fp); 


--------------------------- 

openssl enc -aes-128-cbc -d -in ciphertextAES -out plaintext.txt -pass pass:1234123412341234 -nosalt 
bad decrypt ????????????????????????? 
3840:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:.\crypto\evp\evp_enc.c:466: 

+2

這段代碼有問題嗎?你想做什麼?請更具描述性,以便我們可以幫助你。 – Andre 2011-01-06 16:52:40

回答

1
openssl enc -aes-128-cbc -e -in plaintext.txt -out ciphertext -nosalt -K AA 
-iv AA -p 

-p說明你的密鑰和IV使用:

key=AA000000000000000000000000000000 
iv =AA000000000000000000000000000000 

略去-K-iv參數和使用-pass,而是和你」你會發現密碼和密鑰並不完全相同。無論是否使用-nosalt選項,情況都是如此。