引入以下包才能支持PKCS7Padding
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.55</version>
</dependency>
public String decrypt(String encryptedData,String sessionKey) throws Exception {
encryptedData="UZeNiVw1V11+TQcs4ZHGAMOU6MNAqXE+U8TVA9mJUoE=";
//解密之前先把Base64格式的数据转成原始格式
Base64.Decoder decoder = Base64.getDecoder();
byte[] dataByte = decoder.decode(encryptedData);
//指定算法,模式,填充方法 创建一个Cipher实例
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS7Padding",new BouncyCastleProvider());
//生成Key对象
Key sKeySpec = new SecretKeySpec(key2, "DESede");
//指定用途,密钥,参数 初始化Cipher对象
cipher.init(Cipher.DECRYPT_MODE, sKeySpec);
//执行解密
byte[] result = cipher.doFinal(dataByte);
//解密后转成字符串
data = new String(result);
logger.info("输出:"+data);
return data;
}
好文
DES加密与3DES加密