How can I generate a .pfx file?

37,851

Solution 1

There is a Microsoft command-line tool makecert that can be used to generate certificates. It's part of the Windows SDK. On my machine there are half a dozen versions e.g. in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64. Then in your code you can start a process to run the executable with the appropriate parameters.

Solution 2

You could check out the Bouncy Castle API, it can be used to generate certificates using C#.

Solution 3

First of all, signing documents with self-signed certificates makes no sense unless you have custom PKI hierarchy in your organization (and in the latter case you need to know well what you are doing, which seems to be not the case).

PFX is a container for one or more certificates with associated private keys. So you don't generate "PFX file". You generate a keypair and create a certificate, which can then be exported to PFX file or to other format.

As mentioned above, BouncyCastle can generate certificates, and our SecureBlackbox library also can generate certificates and save and load them to/from many different formats.

Share:
37,851
user773456
Author by

user773456

Updated on July 19, 2022

Comments

  • user773456
    user773456 almost 2 years

    Is there any way to create .pfx files in order to sign documents, I've found a program called x509 Certificate Generate,but I want to know if it can be generated in code using c#.

  • user773456
    user773456 over 12 years
    Is there any sample of BC API?
  • Gangnus
    Gangnus almost 4 years
    It has a great sense if you are a developer and want to create and test some code that will work with .pfx file.
  • Eugene Mayevski 'Callback
    Eugene Mayevski 'Callback almost 4 years
    @Gangnus before commenting, please read the topic. The OP didn't want to test anything. He wants to sign documents for users (read the OP's comments to the question). Please, do read the answers in context of the question and not as some abstraction.