如何通过闪存驱动器上的证书以签名处的形式传输密码(PIN)?
How to transfer the password (PIN) in the form at the signature by means of the certificate which is on a flash drive?
我需要签署很多文档,此代码有效。问题是每次我看到输入密码的表格。
如何通过闪存驱动器上的证书以签名处的形式传输密码(PIN)?
信息:无法从闪存驱动器导出私钥(密钥市场未导出)
static public byte[] SignToken(Byte[] tokenToSignBytes, X509Certificate2 signerCert)
{
// Place message in a ContentInfo object.
// This is required to build a SignedCms object.
ContentInfo contentInfo = new ContentInfo(tokenToSignBytes);
// Instantiate SignedCms object with the ContentInfo above.
// Has default SubjectIdentifierType IssuerAndSerialNumber.
// Has default Detached property value false, so message is
// included in the encoded SignedCms.
SignedCms signedCms = new SignedCms(contentInfo, true);
// Formulate a CmsSigner object for the signer.
CmsSigner cmsSigner = new CmsSigner(signerCert);
Console.WriteLine(cmsSigner);
// Sign the CMS/PKCS #7 message.
Console.Write("Computing signature with signer subject name {0} ... ", signerCert.SubjectName.Name);
signedCms.ComputeSignature(cmsSigner, false);
//signedCms.ComputeSignature(cmsSigner, true); // it's not working
Console.WriteLine("Done.");
// Encode the CMS/PKCS #7 message.
return signedCms.Encode();
}
我不会传递 PIN,而是重构代码以在外部定义 cmsSigner
变量,并且只定义一次。然后将此参数传递给 SignToken
方法。然后,当您第一次访问 cmsSigner
变量时,系统只会提示您输入一次 PIN。然后您重用该实例,当您使用相同的 cmsSigner
实例多次调用 SignToken
方法时,不会出现任何提示。
我需要签署很多文档,此代码有效。问题是每次我看到输入密码的表格。 如何通过闪存驱动器上的证书以签名处的形式传输密码(PIN)?
信息:无法从闪存驱动器导出私钥(密钥市场未导出)
static public byte[] SignToken(Byte[] tokenToSignBytes, X509Certificate2 signerCert)
{
// Place message in a ContentInfo object.
// This is required to build a SignedCms object.
ContentInfo contentInfo = new ContentInfo(tokenToSignBytes);
// Instantiate SignedCms object with the ContentInfo above.
// Has default SubjectIdentifierType IssuerAndSerialNumber.
// Has default Detached property value false, so message is
// included in the encoded SignedCms.
SignedCms signedCms = new SignedCms(contentInfo, true);
// Formulate a CmsSigner object for the signer.
CmsSigner cmsSigner = new CmsSigner(signerCert);
Console.WriteLine(cmsSigner);
// Sign the CMS/PKCS #7 message.
Console.Write("Computing signature with signer subject name {0} ... ", signerCert.SubjectName.Name);
signedCms.ComputeSignature(cmsSigner, false);
//signedCms.ComputeSignature(cmsSigner, true); // it's not working
Console.WriteLine("Done.");
// Encode the CMS/PKCS #7 message.
return signedCms.Encode();
}
我不会传递 PIN,而是重构代码以在外部定义 cmsSigner
变量,并且只定义一次。然后将此参数传递给 SignToken
方法。然后,当您第一次访问 cmsSigner
变量时,系统只会提示您输入一次 PIN。然后您重用该实例,当您使用相同的 cmsSigner
实例多次调用 SignToken
方法时,不会出现任何提示。