我有用Java加密和解密的方法。如何使用MySQL命令进行复制?
public static String encrypt(String plainString) throws Exception{
byte[] encr = AESBouncyCastle.encrypt(plainString.getBytes("UTF-8"), "secretKey");
String encryptedString= Hex.encodeHexString(encr);
return encryptedString;
}
public static String decrypt(String encryptedString) throws Exception{
byte[] retr = AESBouncyCastle.decrypt(Hex.decodeHex(encryptedString.toCharArray()), "secretKey");
String decryptedString = new String(retr, "UTF-8");
return decryptedString .trim();
}知道我哪里做错了吗?最后,我想看看是否可以在AES_DECRYPT中使用MySQL函数解密字符串。
更新
首先,我需要找出与Java的Hex.decodeHex等价的Mysql。我们正在使用Apache的通用编解码器库。
我在MySQL中尝试了UNHEX,在Java中做了同样的尝试,但是结果是不同的。
当我执行UNHEX('956cafe431f5bfc0e66ca7d89359d2e9b63060a3ed5793e60c67aacaca43117c')时,它会返回类似于•l¯ä1õ¿Àæl§Ø“YÒé¶0`£íW“ægªÊÊC|的内容。而Java返回类似于Hex.decodeHex("956cafe431f5bfc0e66ca7d89359d2e9b63060a3ed5793e60c67aacaca43117c".toCharArray())的[B@32267cbc ]
发布于 2016-11-03 07:58:23
当然,您可以在AES_DECRYPT中使用MySQL函数解密字符串。
这里的链接:http://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html
https://stackoverflow.com/questions/40396286
复制相似问题