我试图从 tsa 服务器获取时间戳,但出现此错误。我不知道问题出在哪里。
java.lang.IllegalArgumentException: unknown object in 'TimeStampResp' factory : org.bouncycastle.asn1.DERUnknownTag
在这份声明中
TimeStampResp resp = TimeStampResp.getInstance(new ASN1InputStream(in).readObject());
这是我的代码:
String TSA_URL = "http://tsa.starfieldtech.com/";
//String TSA_URL = "http://ca.signfiles.com/TSAServer.aspx";
//String TSA_URL = "http://timestamping.edelweb.fr/service/tsp";
try {
//byte[] digest = calcularMessageDigest(leerByteFichero("C:\\deskSign.txt"));
byte[] digest = leerByteFichero("C:\\deskSign.txt");
TimeStampRequestGenerator reqgen = new TimeStampRequestGenerator();
TimeStampRequest req = reqgen.generate(TSPAlgorithms.SHA1, digest);
byte request[] = req.getEncoded();
URL url = new URL(TSA_URL);
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));
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());
任何人都可以帮助我吗?