我正在尝试在java上解密我从客户端收到的加密邮件,该邮件使用sjcl进行encriptyon 我使用sjcl和默认参数
这是我到目前为止所拥有的
public static void decrypt(){
try {
String salt="yIv/YH1+pBs=";
String iv="xmzopU9UqwM=";
String password="password";
String cipherText="5xy76uy4oOIHA8PKeD3Uyjp9ex6zh449";
//Security.setProperty("crypto.policy", "unlimited");
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 10000, 128);
SecretKey tmp = factory.generateSecret(spec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding",new BouncyCastleProvider());
cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv.getBytes()));
cipher.doFinal(cipherText.getBytes());
System.out.println(cipher.doFinal(cipherText.getBytes()));
}catch(Exception e) {
e.printStackTrace();
}
}
从调用此方法我得到下一个异常
javax.crypto.AEADBadTagException: mac check in CCM failed
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$AEADGenericBlockCipher.doFinal(Unknown Source)
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineDoFinal(Unknown Source)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at probaDeMicrofon.AdvancedEncryptionStandard.decrypt(AdvancedEncryptionStandard.java:84)
at probaDeMicrofon.AdvancedEncryptionStandard.main(AdvancedEncryptionStandard.java:115)
有人可以帮我吗?