PHP에 java decrypter 코드를 이식하고 있습니다. - 그것은 AES/CBC/NoPadding (128) 너 한테 데이터를 암호화되어있어Java javax.crypto와 PHP openssl_decrypt가 동일하지 않습니다
- encrypted.data : 나는 3 개 파일이 있습니다.
- aes.key - 비밀 키입니다.
- initialization.vector는 - 그것은
내가 해독 된 데이터를 AES/CBC/NoPadding (128) 알고리즘 자바 javax.crypto의 패키지 사용에 사용 link
여기를 참조 초기화 벡터입니다.
- 은 OpenSSL 라이브러리 버전 LibreSSL 2.4.4
- 은 OpenSSL 헤더 버전 LibreSSL 2.4.4
PHP 버전 7.1.0 PHP 정보 (OpenSSL을)를 사용 코드의
내 예 :
내 자바 코드 :
0 필요에 따라 1,233,418,446,226,833,057,513,210내 휴대용 PHP 코드
<?php
$AesKeyData = file_get_contents('./Cipher2PHP/aes.key');
$InitializationVectorData = file_get_contents('./Cipher2PHP/initialization.vector');
$EncryptedData = file_get_contents('./Cipher2PHP/encrypted.data');
$decrypted = openssl_decrypt(
$EncryptedData,
'AES-128-CBC',
$AesKeyData,
OPENSSL_NO_PADDING,
$InitializationVectorData
);
printf("Your data: %s\n", $decrypted);
자바 코드가 작동합니다. PHP 코드가 불일치로 작동합니다.
자바 코드 출력 :
Your data: My very secure data. Very secure
Process finished with exit code 0
PHP 코드 출력 :
Your data: �j��2��䈤�n�h�/sEH�,/-��-�^[
Process finished with exit code 0
를 Base64 인코딩 datas :
PHP :
Base64 AES Key: "Kl/LF5HSL7YCRbPYNp7QssJzcVY/vx88nt9rEYJaXQo="
Base64 InitializationVector: "QXF/8HO4te38LhhuFP9+hA=="
Base64 EncryptedData: "eA1w+ysqsHIdaXsQRSgt9nLPDj7ILcqyZdCW3wDBcy0="
Decrypted Result: "xmqJ0TKgx+SIpP1u/hNoyS9zRUjEAAEsLy251S2hXls="
자바 :
콘솔에서Base64 AES Key: "Kl/LF5HSL7YCRbPYNp7QssJzcVY/vx88nt9rEYJaXQo="
Base64 InitializationVector: "QXF/8HO4te38LhhuFP9+hA=="
Base64 EncryptedData: "eA1w+ysqsHIdaXsQRSgt9nLPDj7ILcqyZdCW3wDBcy0="
Decrypted Result: "TXkgdmVyeSBzZWN1cmUgZGF0YS4gVmVyeSBzZWN1cmU="
파일 :
./Cipher2PHP mac$ file -I *
aes.key: application/octet-stream; charset=binary
initialization.vector: application/octet-stream; charset=binary
encrypted.data: application/octet-stream; charset=binary
./Cipher2PHP mac$ xxd aes.key
0000000: 2a5f cb17 91d2 2fb6 0245 b3d8 369e d0b2 *_..../..E..6...
0000010: c273 7156 3fbf 1f3c 9edf 6b11 825a 5d0a .sqV?..<..k..Z].
./Cipher2PHP mac$ xxd initialization.vector
0000000: 4171 7ff0 73b8 b5ed fc2e 186e 14ff 7e84 Aq..s......n..~.
./Cipher2PHP mac$ xxd encrypted.data
0000000: 780d 70fb 2b2a b072 1d69 7b10 4528 2df6 x.p.+*.r.i{.E(-.
0000010: 72cf 0e3e c82d cab2 65d0 96df 00c1 732d r..>.-..e.....s-
./Cipher2PHP mac$ xxd -b aes.key
0000000: 00101010 01011111 11001011 00010111 10010001 11010010 *_....
0000006: 00101111 10110110 00000010 01000101 10110011 11011000 /..E..
000000c: 00110110 10011110 11010000 10110010 11000010 01110011 6....s
0000012: 01110001 01010110 00111111 10111111 00011111 00111100 qV?..<
0000018: 10011110 11011111 01101011 00010001 10000010 01011010 ..k..Z
000001e: 01011101 00001010 ].
./Cipher2PHP mac$ xxd -b initialization.vector
0000000: 01000001 01110001 01111111 11110000 01110011 10111000 Aq..s.
0000006: 10110101 11101101 11111100 00101110 00011000 01101110 .....n
000000c: 00010100 11111111 01111110 10000100 ..~.
./Cipher2PHP mac$ xxd -b encrypted.data
0000000: 01111000 00001101 01110000 11111011 00101011 00101010 x.p.+*
0000006: 10110000 01110010 00011101 01101001 01111011 00010000 .r.i{.
000000c: 01000101 00101000 00101101 11110110 01110010 11001111 E(-.r.
0000012: 00001110 00111110 11001000 00101101 11001010 10110010 .>.-..
0000018: 01100101 11010000 10010110 11011111 00000000 11000001 e.....
000001e: 01110011 00101101
둘 다 출력 할 수 있습니까? IV/Key는 어떤 형식입니까? Java에서 문자열로 변환하는 대신 결과를 모두 base64로 인쇄 해보십시오. 바이너리 데이터와 문자열은 행복한 암호 작성자가 아닙니다. –
예, 어느 것이 예상 한 결과를 제공합니까? 입력 (키, iv, 암호문/암호문)도 도움이됩니다. 그렇지 않으면 올바른 코드를 식별 할 수 없으므로 주제를 벗어나야합니다. –
base64 데이터를 추가했습니다. –