我正在尝试加密使用ADF移动正在开发的移动应用程序中的一些安全信息。我使用"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. getinstance ("AES/CBC/PKCS5Padding");
这些策略文件在哪里?如何检查它们是否存在?
任何帮助都将非常感激。如果您需要其他信息,请告诉我。
看起来像Sun JCE提供程序中的问题,与ADF无关。通过将$JRE_HOME/lib/jce.jar
替换为jce1_2_2.jar
,我可以在jdk 1.4_2.19和JCE 1.2.2中进行复制。在本例中,a
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
并删除所有与$JRE_HOME/lib/ext
相关的SunJCE)。
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();
}
}
}