VicentePulsoInformtica-8241 avatar image
0 Votes"
VicentePulsoInformtica-8241 asked ·

CMSSigner.ComputeSignature throws WindowsCryptographicException

When trying to make a signature with CmsSigner class invoking the ComputeSignature method, it throws the following exception:
{"Invalid type specified."} System.Exception {Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException}

The certificate is obtained from the certificate store and stored in an X509Certificate2 object. The private key exists. The problem is that when ComputeSignature is performed, the provider's Dialog PIN does not jump (in this case Siemens CARD API CSP) and throws the exception. This problem happens to us in .NET Core and with certificates whose private key is located on a Smart Card and is not exportable. With the .NET Framework it works correctly and if we use a certificate whose private key is in the store, it also works correctly in both .NET Core and .NET FrameWork.
In .NET Core it works indicating SubjectIdentifierType.NoSignature, but in this way the signer is not identified and this solution is not worth it.

public static byte [] sign (X509Certificate2 cert, byte [] data, bool compress, int SignOption)
ContentInfo info;
if (compress)
info = new ContentInfo (ZipXML (data));
info = new ContentInfo (data);
SignedCms signedMes = new SignedCms (info, true);
CmsSigner signature = new CmsSigner (cert);
signedMes.ComputeSignature (signature, false); -> Throws Exception !!!!
return signedMes.Encode ();
} catch (Exception e)
throw new Exception ("Signature error." + e.Message + "\ n" + e.Source + ". \ n" + e.StackTrace);

· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@VicentePulsoInformtica-8241: as this question is more related to .NET Framework SignedCms.ComputeSignature function, I suggest you could create a new thread in .NET Security Forum:

ASP.NET Forums/General ASP.NET/Security

As this forum mainly talked about Partner Center API Related question.


Best Regards

0 Votes 0 ·

0 Answers