【发布时间】:2017-12-21 09:49:11
【问题描述】:
我有一个代码可以在 C# 中成功使用 A1 证书对字符串进行签名。 我需要在此签名中添加时间戳。这个时间戳需要来自像http://www.cryptopro.ru/tsp/tsp.srf这样的时间戳服务器 我不知道如何将时间戳放到签名中。 它不是 PDF 符号,而是字符串符号。 谁能帮帮我?
用于签名的代码:
private byte[] Sign(string text)
{
// Find the certificate we’ll use to sign
X509Certificate2 cert = new X509Certificate2(@"C:\Users\1000084016.pfx", "Password");
RSACryptoServiceProvider csp = null;
// Get its associated CSP and private key
csp = (RSACryptoServiceProvider)cert.PrivateKey;
// Hash the data
SHA1Managed sha1 = new SHA1Managed();
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data;
data = encoding.GetBytes(text);
byte[] hash = sha1.ComputeHash(data);
// Sign the hash
return csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
}
【问题讨论】:
-
这取决于您的数字签名的外观。如果是 XML 文档,签名哈希、时间戳和混合哈希应该有单独的字段
标签: c# timestamp digital-signature x509certificate rsacryptoserviceprovider