package com.ots.project.tool.exam; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class DecryptUtil { public static byte[] AES_CBC_Decrypt(byte[] data, byte[] key, byte[] iv) throws Exception{ Cipher cipher = getCipher(Cipher.DECRYPT_MODE, key, iv); return cipher.doFinal(data); } private static Cipher getCipher(int mode, byte[] key, byte[] iv) throws Exception{ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES"); cipher.init(mode, secretKeySpec, new IvParameterSpec(iv)); return cipher; } public static void main(String[] args) throws Exception { byte[] bytes = "db2139561c9fe068".getBytes(); String base64Str = Base64.encodeBase64String(bytes); System.out.println(base64Str); String crypto = "34439a96e68b129093105b67de81c0fc"; byte[] data = Hex.decodeHex(crypto.toCharArray()); byte[] s = AES_CBC_Decrypt(data, bytes, bytes); System.out.println(new String(s)); } }