Android 和 BouncyCastle 的 IllegalAccessError
我正在尝试实现时间戳请求,如下所示: http://bouncy-castle.1462172.n4 .nabble.com/Timestamp-request-and-response-td1558231.html 在 j2se 中它工作正常,但在 android 上我收到 IllegalAccessError。 Logcat 输出:
致命异常:main
java.lang.IllegalAccessError: tried to access method org.bouncycastle.asn1.DERBoolean.<init>:(Z)V from class org.bouncycastle.tsp.TimeStampRequestGenerator
at org.bouncycastle.tsp.TimeStampRequestGenerator.setCertReq(Unknown Source)
at org.ats.ats.onCreate(ats.java:30)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 59): Force finishing activity org.ats/.ats
我有必要在 TSResponse 中请求证书。 安卓API是2.2 我的代码:
TimeStampRequestGenerator reqgen = new TimeStampRequestGenerator();
reqgen.setCertReq(true);
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update("messageImprint".getBytes());
byte[] digest = messageDigest.digest();
String ocspUrl = "http://egtstamp.egroup.hu:80/tsa";
OutputStream out = null;
TimeStampRequest req = reqgen.generate(TSPAlgorithms.SHA1, digest);
byte request[] = req.getEncoded();
URL url = new URL(ocspUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-type", "application/timestamp-query");
con.setRequestProperty("Content-length", String.valueOf(request.length));
out = con.getOutputStream();
out.write(request);
out.flush();
I am trying to implement a timestamp request as seen here:
http://bouncy-castle.1462172.n4.nabble.com/Timestamp-request-and-response-td1558231.html
In j2se it works fine, but on android I get an IllegalAccessError.
Logcat output :
FATAL EXCEPTION: main
java.lang.IllegalAccessError: tried to access method org.bouncycastle.asn1.DERBoolean.<init>:(Z)V from class org.bouncycastle.tsp.TimeStampRequestGenerator
at org.bouncycastle.tsp.TimeStampRequestGenerator.setCertReq(Unknown Source)
at org.ats.ats.onCreate(ats.java:30)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 59): Force finishing activity org.ats/.ats
It is necessary for me to ask for the Certificate in the TSResponse.
Android api is 2.2
My code:
TimeStampRequestGenerator reqgen = new TimeStampRequestGenerator();
reqgen.setCertReq(true);
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update("messageImprint".getBytes());
byte[] digest = messageDigest.digest();
String ocspUrl = "http://egtstamp.egroup.hu:80/tsa";
OutputStream out = null;
TimeStampRequest req = reqgen.generate(TSPAlgorithms.SHA1, digest);
byte request[] = req.getEncoded();
URL url = new URL(ocspUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-type", "application/timestamp-query");
con.setRequestProperty("Content-length", String.valueOf(request.length));
out = con.getOutputStream();
out.write(request);
out.flush();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论