BouncyCastle TimeStampProtocol |如何从TimeStampToken获取原始哈希? [英] BouncyCastle TimeStampProtocol | How Do I get the original hash from a TimeStampToken?

查看:128
本文介绍了BouncyCastle TimeStampProtocol |如何从TimeStampToken获取原始哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've created a TimeStampRequest from an hashed data and sent it to a tsa.

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

The TSA responded with a Granted response and I've got the byte array with the timestamp.

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

How do I get the original hashed data so I can validate that the TimeStamp sent by the TSA is the one I clain to have?

谢谢.

请求

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的签名摘要

You can use this method to get the signed digest of the TimeStampToken

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

然后,您可以将值与原始 Hash

Then you can compare the value with the original Hash value

这篇关于BouncyCastle TimeStampProtocol |如何从TimeStampToken获取原始哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆