2

我正在尝试在使用 ADF Mobile 开发的移动应用程序中加密一些安全信息。我正在使用“javax.crypto.Cipher”。根据我的理解,ADF Mobile 将它自己的 JVM 与应用程序的 apk/ipa 一起打包用于部署目的。但在部署过程中,我们面临以下问题

java.lang.ExceptionInInitializerError
at java.lang.Class.runStaticInitializers(Unknown Source)
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.getInstance(Unknown Source)

Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
01-08 16:10:19.758: D/CVM(769): at javax.crypto.SunJCE_b.<clinit>(Unknown Source)
01-08 16:10:19.768: D/CVM(769): ... 14 more
01-08 16:10:19.768: D/CVM(769): Caused by: java.lang.SecurityException: Cannot locate    policy or framework files!
01-08 16:10:19.768: D/CVM(769): at javax.crypto.SunJCE_b.g(Unknown Source)
01-08 16:10:19.768: D/CVM(769): at javax.crypto.SunJCE_b.f(Unknown Source)
01-08 16:10:19.768: D/CVM(769): at javax.crypto.SunJCE_t.run(Unknown Source)

在以下行: Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

这些政策文件将在哪里?如何检查它们是否存在?

任何帮助将不胜感激。如果您需要更多信息,请告诉我。

4

1 回答 1

0

看起来像 Sun JCE 提供程序中的问题,并且与 ADF 无关。$JRE_HOME/lib/jce.jar我可以通过替换来在 jdk 1.4_2.19 和 JCE 1.2.2 中重现jce1_2_2.jar. 在这种情况下,得到

Exception in thread "main" java.lang.ExceptionInInitializerError
    at javax.crypto.Cipher.a(DashoA6275)
    at javax.crypto.Cipher.getInstance(DashoA6275)
    at Test.main(Test.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs: java.security.PrivilegedActionException: java.net.MalformedURLException: no protocol: US_export_policy.jar
    at javax.crypto.SunJCE_b.<clinit>(DashoA6275)
    ... 8 more

作为解决方法,您可以使用 BouncyCastle 提供程序(返回原始文件$JRE_HOME/lib/jce.jar并删除与 中的所有 SunJCE 相关的内容$JRE_HOME/lib/ext)。

public class Test {
    static {
        Security.addProvider(new BouncyCastleProvider());
    }
    public static void main(String[] args) throws Exception {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
于 2013-01-10T10:39:06.173 回答