BouncyCastle TimeStampProtocol |如何从TimeStampToken获取原始哈希?

时间:2018-09-07 14:16:42

标签: c# timestamp bouncycastle

我已经从散列数据创建了 TimeStampRequest 并将其发送到tsa。

TSA的响应为Granted,并且我得到了带有时间戳的字节数组。

如何获取原始的哈希数据,以便可以验证TSA发送的TimeStamp是我所拥有的那个?

谢谢。

请求

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

1 个答案:

答案 0 :(得分:1)

您可以使用此方法获取TimeStampToken的签名摘要

byte[] digest = TSToken.TimeStampInfo.GetMessageImprintDigest();

然后您可以将值与原始Hash值进行比较