java时间戳失效_java-时间戳响应不正确-BouncyCastle

试图通过使用BouncyCastle请求时间戳(RFC 3161)并连接到 http://timestamping.edelweb.fr/service/tsp.我确实从服务器返回了TimestampResponse,但似乎没有实际日期.

这是代码:

public static void main(String[] args) {

String ocspUrl = "http://timestamping.edelweb.fr/service/tsp";

byte[] digest = "hello".getBytes();

OutputStream out = null;

try {

TimeStampRequestGenerator reqgen = new TimeStampRequestGenerator();

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

if (con.getResponseCode() != HttpURLConnection.HTTP_OK) {

throw new IOException("Received HTTP error: " + con.getResponseCode() + " - " + con.getResponseMessage());

}

InputStream in = con.getInputStream();

TimeStampResp resp = TimeStampResp.getInstance(new ASN1InputStream(in).readObject());

TimeStampResponse response = new TimeStampResponse(resp);

response.validate(req);

System.out.println(response.getTimeStampToken().getTimeStampInfo().getGenTime());

} catch (IOException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

}

这是问题:

有没有人使用Bouncycastle的库作为时间戳,并且碰巧知道不同的状态码及其含义?或只是一般而言,为什么这似乎行不通.

我希望看到日期的这一行只会引发NullPointer:

System.out.println(response.getTimeStampToken().getTimeStampInfo().getGenTime());

有人知道免费的其他符合RFC 3161的时间戳服务器吗?

如果您想运行该代码,则需要可以从here下载的bouncycastle jar.您将需要:provider,mail,tsp.

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值