2010-08-26 104 views
0

我devloping需要簽署文件的系統。我已經有一個函數接收要簽名的數據的字節[]和X509證書,並使用System.Security.Cryptography.Pkcs命名空間計算簽名。需要注意的是,我們需要將簽名分開,因此爲了驗證,我們使用文件,簽名和證書。C#PKCS簽名

事情是這個函數返回一個byte []作爲簽名。現在序列化它我使用Base64編碼,但我看到標準是使用.p7s文件。

那麼,如何從解密簽名的byte []生成一個.p7s文件?

另一個問題,有沒有辦法在簽名上添加時間戳,然後檢索它?

謝謝! Juan

回答

0

p7s是一個獨立的PKCS#7簽名本身。它可以(可選)base64編碼,這就是所有,沒有其他格式需要應用。

是的,您可以爲PKCS#7簽名添加時間戳。您需要閱讀RFC 3161並自行實施。您可以使用我們的SecureBlackbox產品的PKI components。我們的組件允許您使用PKCS#7和CMS(PKCS#7的擴展和後代)對數據進行簽名和時間戳記。我不知道爲PKCS#7提供免費的時間戳客戶端,儘管有些可能存在。

0

現在可以使用X509Certificate2類

public static byte[] Sign(byte[] data, X509Certificate2 certificate) 
{ 
    if(data == null) 
     throw new ArgumentNullException("data"); 
    if(certificate == null) 
     throw new ArgumentNullException("certificate"); 

    // setup the data to sign 
    ContentInfo content = new ContentInfo(data); 
    SignedCms signedCms = new SignedCms(content, false); 
    CmsSigner signer = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, certificate); 

    // create the signature 
    signedCms.ComputeSignature(signer); 
    return signedCms.Encode(); 
} 
相關問題