我尝试使用http://www.debenu.com/kb/advanced-options-signing-pdf-files/
签署pdf但是在调用时会抛出异常
// Sign the file data (generates an SHA-1 hash and
// signs that hash)
byte[] enc = SignData(fileData, cert); //throw exception
这是我的SignData函数
private static byte[] SignData(byte[] inputData, X509Certificate2 cert)
{
// Create an SHA-1 hash of the file data
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] sha1Result = sha.ComputeHash(inputData);
CmsSigner cmsSigner = new CmsSigner(cert);
cmsSigner.IncludeOption = X509IncludeOption.WholeChain;
cmsSigner.DigestAlgorithm = new Oid("SHA1");
// Sign the hash using the certificate
// This could be changed to use a hardware device (eg. smartcard)
ContentInfo content = new ContentInfo(sha1Result);
SignedCms signedCms = new SignedCms(SubjectIdentifierType.IssuerAndSerialNumber, content, true);
signedCms.ComputeSignature(cmsSigner, false); //throw "The parameter is incorrect."
return signedCms.Encode();
}
获取testSig
时没关系 byte[] randomData = new byte[1];
randomData[0] = 123;
byte[] testSig = SignData(randomData, cert);
EDIT 当我使用来自usb令牌的cert时抛出此错误。如果我选择其他证书有私钥,则不会抛出错误