我必须从 tsa 服务器获取时间戳。我正在发送一个文件(转换为byte[]
)。
但是当我试图得到回应时,它会给我一个NullPointerException
.
这是我的代码:
public static void timeStampServer () throws IOException{
//String TSA_URL1 = "http://tsa.starfieldtech.com/";
String TSA_URL2 = "http://ca.signfiles.com/TSAServer.aspx";
//String TSA_URL3 = "http://timestamping.edelweb.fr/service/tsp";
try {
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_URL2);
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());
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
我尝试使用 3 个 tsa 服务器,但其中任何一个都返回给我一个有效的 TSA。所有一个都在“ ”
中抛出 NullPointerException 。抛出一个TimeStampResponse response = new TimeStampResponse(resp);
TSA_URL2
java.io.IOException:收到 HTTP 错误:411 - 需要长度。
我不知道问题出在 tsa 服务器还是我的代码中。任何人都可以帮助我吗?