我有被发送到我这是使用AES基于数字ID生成MD5哈希
从请求中的MD5哈希加密的密码,我可以在我与其他属性数据库中获取的ID保持 因此,在服务器端,我需要获取id,根据该id获取MD5哈希,并使用AES算法和生成的MD5哈希清除密码。
我使用以下代码来获取MD5哈希
try {
byte[] bytesOfMessage = id.getBytes("UTF-8");
log.error "bytesOfMessage length: " + bytesOfMessage.length
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(bytesOfMessage);
md5Value = new String(thedigest);
log.error "md5Value length: " + md5Value.length()
log.error "md5Value bytes length: " + md5Value.getBytes().length
} catch (UnsupportedEncodingException e) {
log.error "[getMD5EncryptionKey]UnsupportedEncodingException: " + e;
} catch (NoSuchAlgorithmException e) {
log.error "[getMD5EncryptionKey]NoSuchAlgorithmException: " + e;
}
的md5Value长度是基于1的ID 16,但是当我从这个md5value的字节数,有34个字节
当我去使用这个MD5哈希和javax.crypto.Cipher中的库来解密密码,我得到以下信息
java.security.InvalidKeyException:无效的AES密钥长度:34个字节
任何想法我在这里做错了吗?
我用它来解密消息的代码如下
try {
byte [] encryptionKeyBytes = md5EncryptionKey.getBytes("UTF-8");
Key key = new SecretKeySpec(encryptionKeyBytes, "AES");
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.DECRYPT_MODE, key);
byte[] decodedValue = new Base64().decode(encryptedData);
byte[] decValue = c.doFinal(decodedValue);
String decryptedValue = new String(decValue);
return decryptedValue;
} catch (InvalidKeyException e) {
log.error "[getDecryptedValue] InvalidKeyException: " + e
} catch (IllegalBlockSizeException e) {
log.error "[getDecryptedValue] InvalidKeyException: " + e
} catch (BadPaddingException e) {
log.error "[getDecryptedValue] InvalidKeyException: " + e
} catch (NoSuchAlgorithmException e) {
log.error "[getDecryptedValue] InvalidKeyException: " + e
} catch (NoSuchPaddingException e) {
log.error "[getDecryptedValue] InvalidKeyException: " + e
} catch (Exception e) {
log.error "[getDecryptedValue] InvalidKeyException: " + e
}
wasnt知道这个库,用它和它做的伎俩。欢呼家伙 – Damien