簡體   English   中英

將時間戳添加到數字簽名

[英]Add TimeStamp to digital signature

我有一個代碼可以在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"));
    }

外部時間戳記提供程序使用RFC3161在包含哈希的application/timestamp-query上發布application/timestamp-query 您可以使用BouncyCastle構建請求(請參見此處的示例)

要將時間戳結果嵌入簽名中,您不能使用基本的RSA結果。 您需要使用CMS(二進制)或XMLDsig(XML)之類的高級簽名容器,並將時間戳記添加為未簽名的屬性。 請參閱此處使用CMS的實現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM