bassemAgmi / EInvoicingSigner

A command prompt application used to serialize and sign tax payers documents before sending the documents to Egyptian Tax Authority.
71 stars 57 forks source link

Error When signing #4

Closed saadwardany closed 2 years ago

saadwardany commented 3 years ago

D:\EInvoicing>D:\EInvoicing\publish/EInvoicingSigner.exe D:\EInvoicing 10182735 "Egypt Trust Sealing CA" First argument D:\EInvoicing Second argument 10182735 Third argument Egypt Trust Sealing CA Unhandled exception. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: An internal error occurred. at Internal.Cryptography.CngCommon.TrySignHash(SafeNCryptKeyHandle keyHandle, ReadOnlySpan1 hash, Span1 signature, AsymmetricPaddingMode paddingMode, Void* pPaddingInfo, Int32& bytesWritten) at System.Security.Cryptography.RSACng.TrySignHash(ReadOnlySpan1 hash, Span1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Int32& bytesWritten) at System.Security.Cryptography.Pkcs.CmsSignature.RSAPkcs1CmsSignature.Sign(ReadOnlySpan1 dataHash, HashAlgorithmName hashAlgorithmName, X509Certificate2 certificate, AsymmetricAlgorithm key, Boolean silent, String& signatureAlgorithm, Byte[]& signatureValue) at System.Security.Cryptography.Pkcs.CmsSignature.Sign(ReadOnlySpan1 dataHash, HashAlgorithmName hashAlgorithmName, X509Certificate2 certificate, AsymmetricAlgorithm key, Boolean silent, String& oid, ReadOnlyMemory1& signatureValue) at System.Security.Cryptography.Pkcs.CmsSigner.Sign(ReadOnlyMemory1 data, String contentTypeOid, Boolean silent, X509Certificate2Collection& chainCerts) at System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature(CmsSigner signer, Boolean silent) at System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature(CmsSigner signer) at TokenSigner.SignWithCMS(String serializedJson) at TokenSigner.Main(String[] args)

this error appear

bassemAgmi commented 3 years ago

Please check your token using token manager. If login succeeded, try to run our program as administrator.

saadwardany commented 3 years ago

I can login by token manager as in next screen shoot https://files.fm/f/rgpjpg2qt and i tried by administrator but the same issue

bassemAgmi commented 3 years ago

Can you check the Windows Event Viewer under the category of “Application”.

Seif-Abaza commented 3 years ago

I fix this issue , just you need to change this line cms.ComputeSignature(signer); to cms.ComputeSignature(signer,false);

bassemAgmi commented 3 years ago

To check the recommended fix, please update the publish folder by https://github.com/bassemAgmi/EInvoicingSigner/blob/master/publishUpdatedFile.rar . If is it ok, please tell us to commit the change

saadwardany commented 2 years ago

I updated the publish folder but it did not work the token working fine with another lib

D:\EInvoicing>D:\EInvoicing\publish/EInvoicingSigner.exe D:\EInvoicing 10182735 "Egypt Trust" First argument D:\EInvoicing Second argument 10182735 Third argument Egypt Trust Unhandled exception. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: An internal error occurred. at Internal.Cryptography.CngCommon.TrySignHash(SafeNCryptKeyHandle keyHandle, ReadOnlySpan1 hash, Span1 signature, AsymmetricPaddingMode paddingMode, Void* pPaddingInfo, Int32& bytesWritten) at System.Security.Cryptography.RSACng.TrySignHash(ReadOnlySpan1 hash, Span1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Int32& bytesWritten) at System.Security.Cryptography.Pkcs.CmsSignature.RSAPkcs1CmsSignature.Sign(ReadOnlySpan1 dataHash, HashAlgorithmName hashAlgorithmName, X509Certificate2 certificate, AsymmetricAlgorithm key, Boolean silent, String& signatureAlgorithm, Byte[]& signatureValue) at System.Security.Cryptography.Pkcs.CmsSignature.Sign(ReadOnlySpan1 dataHash, HashAlgorithmName hashAlgorithmName, X509Certificate2 certificate, AsymmetricAlgorithm key, Boolean silent, String& oid, ReadOnlyMemory1& signatureValue) at System.Security.Cryptography.Pkcs.CmsSigner.Sign(ReadOnlyMemory1 data, String contentTypeOid, Boolean silent, X509Certificate2Collection& chainCerts) at System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature(CmsSigner signer, Boolean silent) at TokenSigner.SignWithCMS(String serializedJson) in D:\work\Workspace\EInvoicingSigner\EInvoicingSigner\Signer.cs:line 185 at TokenSigner.Main(String[] args) in D:\work\Workspace\EInvoicingSigner\EInvoicingSigner\Signer.cs:line 76

Seif-Abaza commented 2 years ago

To check the recommended fix, please update the publish folder by https://github.com/bassemAgmi/EInvoicingSigner/blob/master/publishUpdatedFile.rar . If is it ok, please tell us to commit the change

It's Binary file bro !! can you provide the source code or upgrade the repo please

bassemAgmi commented 2 years ago

The repository has been updated. You are welcome to take a fork and submit changes to the original repository with pull requests.

melamrey commented 2 years ago

i was have this problem the problem in epass2003 driver change the version you use download another one

Seif-Abaza commented 2 years ago

Notes : there is Error in ePass if you use Windows Server 2016

socertis commented 2 years ago

i was have this problem the problem in epass2003 driver change the version you use download another one

Good Point! I have downloaded a new driver from Here and it worked fine.