How to use digital sign certificate in Aspose .net

Hi Team,

I have digital sign certificate which is Personal Information Exchange type file with name Certificate_pkcs12 received from IT team (Digital Sign Certificate).
I wanted to try to add the digital sign in my pdf document. So I was trying using previous examples/ topics in this forum but got all the examples with .pfx file extension and now I am not getting as I used the file which I have. It’s throwing exception as the file is not fount.

Though the Personal information exchange is known pfx file but it’s not working form me.

Could you please help me to get the .pfx file from the Personal Information Exchange type of file or how can I directly use it in Aspose.

Please suggest on the issue.

Thanks,

@SonalCR

Can you please clarify the exact error message you are receiving when trying to use the digital sign certificate in your PDF document?

System.IO.FileNotFoundException: 'Could not find file.

As I change the extension .pfx to .p12 now the file found but getting exception for password.
The error is “PKCS12 key store MAC invalid - wrong password or corrupted file.

@SonalCR We suggest you please read the following article about working with digital signatures.
https://docs.aspose.com/words/net/working-with-digital-signatures/

The . pfx file is in a PKCS#12 format that contains the SSL certificate (public keys) and the corresponding private key. You can use CertificateHolder.Create method with this type of file to create CertificateHolder object using path to PKCS12 store and its password.

@alexey.noskov , Thanks for the response. Yes, I am following the article. Using the Sign a Generated PDF Document code for reference but getting the error “PKCS12 key store MAC invalid - wrong password or corrupted file. ”.

@SonalCR There might be several reasons of getting this error:

  1. Wrong Password
  2. Corrupted File. If the file has been truncated or modified (e.g., due to a failed upload, file transfer issue, or encoding problem), it may be unreadable.
  3. File Format Mismatch. Make sure you’re opening a PKCS#12 file (.p12 or .pfx) and not a different keystore format like JKS.

Unfortunately, it is difficult to tell what exactly causes the problem on your side.

Please, try your keystore file with OpenSSL. To test if OpenSSL can read it (might give a clearer error):

openssl pkcs12 -info -in mykeystore.p12