尝试通过使用BouncyCastle并连接到http://timestamping.edelweb.fr/service/tsp来请求时间戳(RFC3161)。我确实从服务器得到了一个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());有没有人知道其他免费的符合RFC3161标准的时间戳服务器?
如果你想运行代码,你需要bouncycastle jars,它可以从here下载。您将需要:提供商,邮件,tsp。
谢谢
发布于 2009-05-28 14:28:47
问题似乎是内容的格式/长度错误。
TimeStampRequest req = reqgen.generate(TSPAlgorithms.SHA1, digest);但我发来的信息是:
"hello".getBytes();从“hello”创建一个合适的SHA1Digest,这样就可以正常工作了。
static public byte[] calculateMessageDigest()
throws NoSuchAlgorithmException, IOException {
SHA1Digest md = new SHA1Digest();
byte[] dataBytes = "helloooooooooooooo".getBytes();
int nread = dataBytes.length;
md.update(dataBytes, 0, nread);
byte[] result = new byte[32];
md.doFinal(result, 0);
return result;我也最终使用Digistamp作为我的TSA,因为他们支持http身份验证,这是一个要求。
发布于 2011-04-01 03:08:35
通过分析与wireshark的通信,这个示例给出了一个“错误消息摘要”错误。适用于我的摘要代码是:
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update("messageImprint".getBytes());
byte[] digest = messageDigest.digest();发布于 2009-05-27 14:42:05
我找到了this站点,这是一个相当好的时间戳资源,它也有一个服务器列表,并且至少有几个服务器似乎仍然在运行。
https://stackoverflow.com/questions/915039
复制相似问题