gpt4 book ai didi

c# - BouncyCaSTLe 时间戳协议(protocol) |如何从 TimeStampToken 获取原始哈希值?

转载 作者:太空宇宙 更新时间:2023-11-03 12:11:12 33 4
gpt4 key购买 nike

我从散列数据创建了一个 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值进行比较了

关于c# - BouncyCaSTLe 时间戳协议(protocol) |如何从 TimeStampToken 获取原始哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52224410/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com