13,100
社区成员
发帖
与我相关
我的任务
分享
public class Aes256Encryptor {
private static final byte[] iv = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
private static final String transform = "AES/CBC/NoPadding";
private static final String algorithm = "AES";
private static SecretKeySpec keySpec;
private static BASE64Decoder base64Decoder = new BASE64Decoder();
private static BASE64Encoder base64Encoder = new BASE64Encoder();
/**
*/
public static String decrypt(String pHexText, String key) throws Exception {
Cipher cipher = Cipher.getInstance(transform);
keySpec = new SecretKeySpec(key.getBytes(), algorithm);
byte[] encryptedBytes = base64Decoder.decodeBuffer(pHexText);
cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv));
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
String result = new String(decryptedBytes); // encryptedBytes
return result.trim();
}
}