2010-05-25 4 views
0

Chilkat 라이브러리를 사용하여 암호화 된 PHP를 사용하여 문자열의 암호를 해독하려고합니다.PHP mcrypt // Chilkat AES 암호화 - 통합

VB 암호화 :

Dim password As String 
password = "foobar" 

crypt.CryptAlgorithm = "aes" 
crypt.CipherMode = "cbc" 
crypt.KeyLength = 128 

' Generate a binary secret key from a password string 
' of any length. For 128-bit encryption, GenEncodedSecretKey 
' generates the MD5 hash of the password and returns it 
' in the encoded form requested. The 2nd param can be 
' "hex", "base64", "url", "quoted-printable", etc. 
Dim hexKey As String 
hexKey = crypt.GenEncodedSecretKey(password,"hex") 
crypt.SetEncodedKey hexKey,"hex" 

crypt.EncodingMode = "base64" 
Dim text As String 
text = "The quick brown fox jumped over the lazy dog." 

' Encrypt a string and return the binary encrypted data 
' in a base-64 encoded string. 
Dim encText As String 
encText = crypt.EncryptStringENC(text) 

PHP의 암호 해독 :

$filename = "test.txt"; 
$handle = fopen($filename, "r"); 
$contents = fread($handle, filesize($filename)); 
fclose($handle); 
// remove newlines, etc 
$contents = rtrim($contents); 
// remove base64 encoding 
$contents = base64_decode($contents); 

$key = "foobar"; 
// make a hex of this key 
$key = md5($key); 
// notice the iv is NOT set 
$crypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $contents, MCRYPT_MODE_CBC); 
echo "Decrypted: $crypttext \n"; 

출력은 ... 어떤 아이디어 쓰레기? 필자는 Chilkat이 사용하는 기본 IV 및 Padding 설정이 무엇인지 정확히 알지 못합니다. 또한 PHP에서이 기본값을 에뮬레이트하는 방법도 확실하지 않습니다.

미리 감사드립니다.

답변

0

내 추측 : md5 ($ key) 대신 md5 ($ key, true)를 사용해보십시오.

관련 문제