当前位置: 首页 > 工具软件 > Bouncy Castle > 使用案例 >

bouncycastle android,Android和BouncyCastle的IllegalAccessError

孔彭祖
2023-12-01

|

我正在尝试实现时间戳请求,如下所示:

http://bouncy-castle.1462172.n4.nabble.com/Timestamp-request-and-response-td1558231.html

在j2se中,它工作正常,但是在android上,我收到IllegalAccessError。

Logcat输出:

致命异常:主要

java.lang.IllegalAccessError: tried to access method org.bouncycastle.asn1.DERBoolean.:(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中索取证书。

Android 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();

 类似资料: