Digital signature on Local IIS vs IIS Express. XAdES

49 views Asked by At

I have a problem with my ASP.Net WebForms application for digitally signing documents. When I host the application via Local IIS, an exception pops up: invalid flags. But when I host the application on IIS Express, the application works normally. I perform the signing with the help of RSACryptoServiceProvider.

First, I return the canonical transformation in the form of bits from the Xml file to the DataBytes variable. After that, I extract HashBuffer using DataBytes and HashAlgorithm, and using method ComputeHash(DataBytes). After extracting the HashBuffer, if the algorithm type is: RSACryptoServiceProvider and HashAlgoritam.SHA512. I assign a private key to RSACryptoServiceProvider: RSACryptoServiceProvider = (RSACryptoServiceProvider)Certificate.PrivateKey;

And I calculate the hash of the signature using the method RSACryptoServiceProvider.SignHash(HashBuffer, HashAlgorithmName.SHA512.Name); Which I place in the SignatureBytes variable.

The exception moment occurs when I extract the signature hash with the method: RSACryptoServiceProvider.SignHash. Where should the Windows Security Smart Card Dialog pop up for me to enter the pin.

Exception.Message:

  • Invalid flags.

Exception.StackTrace:

  • at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 cbHash, ObjectHandleOnStack retSignature) at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash) at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, Int32 calgHash) at Osa.Unidocs.ElektronskiPotpisStandardModul.XAdES_EPES.OSASignatureBytes(X509Certificate2 Certificate, Byte[] DataBytes, Byte[]& SignatureBytes) in C:\Novi Elektronski\ElektronskiPotpisModul\ElektronskiPotpis\XAdES-EPES.cs:line 752

Exception.Source:

  • mscorlib

Please help. I assume that some permissions are in question or some configuration. The code is huge, so there's no way I can share it completely. So I described in brief.

0

There are 0 answers