java encription -BouncyCastleProvider:java.lang.NoSuchFieldError:md2

时间:2018-10-16 16:19:49

标签: java encryption

我在main()方法中调用以下方法:

 private static String tripleDesEncrypt(String message, String key) throws Exception {
    SecretKey secretKey = new SecretKeySpec(Base64.decode(key.getBytes()), "DESede");
    Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS7Padding", new org.bouncycastle.jce.provider.BouncyCastleProvider());
    cipher.init(Cipher.ENCRYPT_MODE, secretKey);
    byte[] buf = cipher.doFinal(message.getBytes("UTF-8"));
    return Base64.toBase64String(buf);

}

它在运行时出现此错误:

  

线程“ main”中的异常java.lang.NoSuchFieldError:md2       在org.bouncycastle.jcajce.provider.digest.MD2 $ Mappings.configure(未知来源)       在org.bouncycastle.jce.provider.BouncyCastleProvider.loadAlgorithms(未知来源)       在org.bouncycastle.jce.provider.BouncyCastleProvider.setup(未知来源)       位于org.bouncycastle.jce.provider.BouncyCastleProvider.access $ 000(来源不明)       在org.bouncycastle.jce.provider.BouncyCastleProvider $ 1.run(未知源)       在java.security.AccessController.doPrivileged(本机方法)       在org.bouncycastle.jce.provider.BouncyCastleProvider中。(未知来源)

为什么会发生此异常以及如何解决? 谢谢!

0 个答案:

没有答案