0

我正在尝试在 java 上解密从客户端收到的加密消息,该消息使用 sjcl 进行加密我使用带默认参数的 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)

任何人都可以帮助我吗?

4

0 回答 0