Android 和 BouncyCastle 的 IllegalAccessError

发布于 2024-11-01 09:25:32 字数 2567 浏览 0 评论 0原文

我正在尝试实现时间戳请求,如下所示: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文