I'm trying to decrypt a string using mcrypt_decrypt, but I'm not sure how to get the key into a 'string' type:
$key = array(-2, -2, -2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);
pkcs5_unpad(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv));
the key w开发者_如何学运维as generated using a random key generator, I used it on the encryption side (which happens to be java):
byte[] key = new byte[] { -2, -2, -2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
bytes are signed, so having negative numbers should be legal - I'm just not sure how to use this with mcrypt_decrypt since it wants a 'string' type for $key?
Thanks
You can use chr()
to convert the byte values in ASCII characters:
$strkey = "";
foreach($key as $char) {
$strkey .= chr($char);
}
精彩评论