mysql aes java解密_加密/解密的Java函數,如Mysql的AES_ENCRYPT和AES_DECRYPT

1

If you need the code to decrypt the algorithm is here JAVA

如果你需要代碼解密算法就在這里JAVA

public static String aes_decrypt(String passwordhex, String strKey) throws Exception {

try {

byte[] keyBytes = Arrays.copyOf(strKey.getBytes("ASCII"), 16);

SecretKey key = new SecretKeySpec(keyBytes, "AES");

Cipher decipher = Cipher.getInstance("AES");

decipher.init(Cipher.DECRYPT_MODE, key);

char[] cleartext = passwordhex.toCharArray();

byte[] decodeHex = Hex.decodeHex(cleartext);

byte[] ciphertextBytes = decipher.doFinal(decodeHex);

return new String(ciphertextBytes);

} catch (Exception e) {

e.getMessage();

}

return null;

}

It received a standard hex format string but variable and returns the password. Test with those in main method

它收到一個標准的十六進制格式字符串但變量並返回密碼。用主方法測試

System.out.println(aes_encrypt("your_string_password", "your_string_key"));

System.out.println(aes_decrypt("standard_hex_format_string ", "your_string_key"));

firstable test only with encrypt, then just with decrypt. By the way you must install 'commons-codec-1.6.jar' so you can use the Hex class http://commons.apache.org/proper/commons-codec/download_codec.cgi

只有加密才能進行第一次測試,然后只需要解密。順便說一下,你必須安裝'commons-codec-1.6.jar',這樣你才能使用Hex類http://commons.apache.org/proper/commons-codec/download_codec.cgi

Greetings from Ecuador, Ibarra

來自厄瓜多爾的問候,Ibarra

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值