我想更改给定数据库的所有密码。所有这些密码都是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=
有没有办法获得与在线工具相同的字符串?
答案 0 :(得分:3)
您需要从Base64解码您的密钥和IV:
$key = base64_decode("RRZy0njZDzw=");
$iv = base64_decode("p/34qWLNYfg=");