问题
I have one application which is in PHP encrypting text using openssl_encrypt with following method. (Using same value for salt and iv as '239422ae7940144f')
function encrypt_password($password) {
define('AES_256_CBC', 'aes-256-cbc');
$sessionId = $password;
//random number for encrtyption(salt)
$salt = '239422ae7940144f';
$iv = $salt; //cipher length
$encryptedSession = openssl_encrypt($sessionId, AES_256_CBC, $salt, 0, $iv);
return array('encryptedPassword' => $encryptedSession, 'salt' => $salt);
}
function decrypt_password($result) {
define('AES_256_CBC', 'aes-256-cbc');
$vPassword = 'xUP9PwhcXm5xbKIfiSxMCA==';
//random number for descrypt(salt)
$salt = '239422ae7940144f';
$iv = $salt; //cipher length.
$decrypted = openssl_decrypt($vPassword, AES_256_CBC, $salt, 0, $iv);
return $decrypted;
}
Encrypt of password 'abc123' provides 'xUP9PwhcXm5xbKIfiSxMCA==' and decrypting it gives back 'abc123'.
How to find equivalent java program which would do the same. I tried using the example on Using Java to decrypt openssl aes-256-cbc using provided key and iv, but it fails with
java.lang.IllegalArgumentException: IV buffer too short for given offset/length combination.
Following are the secretKey and initVector lines in java program I am using.
final byte[] secretKey = javax.xml.bind.DatatypeConverter.parseHexBinary("239422ae7940144f");
final byte[] initVector = javax.xml.bind.DatatypeConverter.parseHexBinary("239422ae7940144f");
来源:https://stackoverflow.com/questions/38603153/illegalargumentexception-iv-buffer-too-short-for-given-offset-length-combinatio