2010-08-26 94 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(); 
}