我必须传递一个值并将其加密为以下规范:
“256 位密钥长度,256 位块长度,32 字节块,ECB 模式,带 ASCII 编码(加密数据预计以字符串形式提供,每个字符都已转换为 2 字节 HEX 值)”
但是,我必须遗漏一些东西。这是出于对 Web 服务的验证目的,但由于解密失败,我一直被拒绝。
这是我所拥有的:
$key = '1324mykey';
$string = 'Ron Swanson';
// 1. Encrypt the string with the key using Rijndael 256 in ECB mode
$td = mcrypt_module_open('rijndael-256', '','ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_string = mcrypt_generic($td, $string);
// 2. Base64 encode my string
$encrypted_string = base64_encode($encrypted_string);
// 3. Convert each character of encrypted_string to it's 2-byte HEX value
$hex='';
for ($i=0; $i < strlen($encrypted_string); $i++)
{
$hex .= dechex(ord($encrypted_string[$i]));
}
// Now $encrypted_string should match up with the recipe, but it isn't.
$encrypted_string = $hex;
我希望在我的流程的第 1 步中缺少一些基本的加密要求。