gpt4 book ai didi

java - 时间戳响应不正确 - BouncyCaSTLe

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:49 24 4
gpt4 key购买 nike

尝试使用 BouncyCaSTLe 并连接到 http://timestamping.edelweb.fr/service/tsp 来请求时间戳 (RFC 3161) .我确实从服务器返回了一个 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 .您将需要:提供商、邮件、茶匙。

谢谢

最佳答案

分析与 wireshark 的通信,这个例子给了我一个“错误的消息摘要”错误。对我有用的摘要代码是:

    MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update("messageImprint".getBytes());
byte[] digest = messageDigest.digest();

关于java - 时间戳响应不正确 - BouncyCaSTLe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/915039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com