我从散列数据创建了一个 TimeStampRequest 并将其发送到 tsa。
TSA 回复了一个 Granted 响应,我得到了带有时间戳的字节数组。
如何获取原始散列数据,以便验证 TSA 发送的时间戳是我声称拥有的时间戳?
提前致谢。
请求
TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator();
SHA1 sha1 = SHA1CryptoServiceProvider.Create();
ValidateInput(data);
reqGen.SetCertReq(true);
Hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(data));
TimeStampRequest request = reqGen.Generate(
TspAlgorithms.Sha1, Hash, BigInteger.ValueOf(100));
byte[] reqData = request.GetEncoded();
record.DtRequest = DateTime.Now;
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(stampURI);
httpReq.Method = "POST";
httpReq.ContentType = "application/timestamp-query";
httpReq.ContentLength = reqData.Length;
// Write the request content
Stream reqStream = httpReq.GetRequestStream();
reqStream.Write(reqData, 0, reqData.Length);
reqStream.Close();
HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();
// Read the response
Stream respStream = new BufferedStream(httpResp.GetResponseStream());
TimeStampResponse response = new
TimeStampResponse(respStream);
respStream.Close();
TimeStamp = response.TimeStampToken.GetEncoded();
验证
var TSToken = new TimeStampToken(new CmsSignedData(TSPTimeStamp.DataContent));
//Here, I should reverse the TimeStampToken to the original hash
您可以使用此方法获取 TimeStampToken 的已签名摘要
byte[] digest = TSToken.TimeStampInfo.GetMessageImprintDigest();
然后就可以和原来的Hash
值进行比较了
我是一名优秀的程序员,十分优秀!