PHP OpenSSL 使用 DES-CBC 算法加密意外输出
PHP OpenSSL encrypt with DES-CBC algorithm unexpected output
我想更改给定数据库的所有密码。所有这些密码都是用 DES CBC PKCS7 加密的,我有密钥和初始化向量。我已经使用下一个网页 http://www.txtwizard.net/crypto 解密了一个密码,结果符合预期(使用选项 DES、CBC 和 PKCS7)。
键: RRZy0njZDzw=
iv: p/34qWLNYfg=
纯文本123123
密文 x541kJ4KvJo=
但是当下一个代码写在PHP我无法复制结果:
<?php
$key = "RRZy0njZDzw=";
$iv = "p/34qWLNYfg=";
$data = "123123";
$cipher='DES-CBC';
var_dump(openssl_get_cipher_methods());
$encrypted = openssl_encrypt($data,$cipher, $key,OPENSSL_RAW_DATA,$iv);
echo base64_encode($encrypted);
?>
这段代码的输出是:
PHP Warning: openssl_encrypt(): IV passed is 12 bytes long which is longer than the 8 expected by selected cipher, truncating in /home/sergio/Documents/DevEnvTest/siaf/aes2hash.php on line 7
Warning: openssl_encrypt(): IV passed is 12 bytes long which is longer than the 8 expected by selected cipher, truncating in /home/sergio/Documents/DevEnvTest/siaf/aes2hash.php on line 7
gB7ahDoYZqI=
有没有办法得到与在线工具相同的字符串?
您需要从 Base64 解码您的密钥和 IV:
$key = base64_decode("RRZy0njZDzw=");
$iv = base64_decode("p/34qWLNYfg=");
我想更改给定数据库的所有密码。所有这些密码都是用 DES CBC PKCS7 加密的,我有密钥和初始化向量。我已经使用下一个网页 http://www.txtwizard.net/crypto 解密了一个密码,结果符合预期(使用选项 DES、CBC 和 PKCS7)。
键: RRZy0njZDzw=
iv: p/34qWLNYfg=
纯文本123123
密文 x541kJ4KvJo=
但是当下一个代码写在PHP我无法复制结果:
<?php
$key = "RRZy0njZDzw=";
$iv = "p/34qWLNYfg=";
$data = "123123";
$cipher='DES-CBC';
var_dump(openssl_get_cipher_methods());
$encrypted = openssl_encrypt($data,$cipher, $key,OPENSSL_RAW_DATA,$iv);
echo base64_encode($encrypted);
?>
这段代码的输出是:
PHP Warning: openssl_encrypt(): IV passed is 12 bytes long which is longer than the 8 expected by selected cipher, truncating in /home/sergio/Documents/DevEnvTest/siaf/aes2hash.php on line 7
Warning: openssl_encrypt(): IV passed is 12 bytes long which is longer than the 8 expected by selected cipher, truncating in /home/sergio/Documents/DevEnvTest/siaf/aes2hash.php on line 7
gB7ahDoYZqI=
有没有办法得到与在线工具相同的字符串?
您需要从 Base64 解码您的密钥和 IV:
$key = base64_decode("RRZy0njZDzw=");
$iv = base64_decode("p/34qWLNYfg=");