I have to pass a value and have it encrypted to the following spec:
我必须传递一个值并将其加密到以下规范:
"256-bit key length, 256-bit block length, 32-byte blocks, ECB mode, with ASCII encoding (encrypted data is expected to be provided as a string with each character having been converted to a 2-byte HEX value)"
“256位密钥长度,256位块长度,32字节块,ECB模式,带ASCII编码(加密数据应作为字符串提供,每个字符已转换为2字节HEX值)”
However I must be missing something. This is for verification purposes with a webservice but I keep getting rejected due to a decryption failure.
但是我必须遗漏一些东西。这是出于网络服务的验证目的,但由于解密失败,我一直被拒绝。
Here's what I have:
这就是我所拥有的:
$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;
I'm hoping there's something basic in the encryption requirements that I'm missing in my step 1 of my process.
我希望加密要求中有一些基本内容,我在我的过程的第一步中缺少这些内容。
2 个解决方案
#1
2
If your requirement is a 256-bit key, shouldn't your $key
variable be 32 bytes? (in other words, 32 characters long) ?
如果您的需求是256位密钥,那么$ key变量不应该是32个字节吗? (换句话说,32个字符长)?
#2
1
This has been solved... (un?)fortunately I was simply given a wrong parameter.
这已经解决了......(un?)幸运的是我只是给了一个错误的参数。
#1
2
If your requirement is a 256-bit key, shouldn't your $key
variable be 32 bytes? (in other words, 32 characters long) ?
如果您的需求是256位密钥,那么$ key变量不应该是32个字节吗? (换句话说,32个字符长)?
#2
1
This has been solved... (un?)fortunately I was simply given a wrong parameter.
这已经解决了......(un?)幸运的是我只是给了一个错误的参数。