First of all, signing documents with self-signed certificates does not make sense if you do not have a custom PKI hierarchy in your organization (and in the latter case, you need to know well what you are doing, which seems to be wrong),
PFX is a container for one or more certificates with associated private keys. This way you are not creating a "PFX file". You create a key pair and create a certificate, which can then be exported to a PFX file or to another format.
As mentioned above, BouncyCastle can create certificates, and our SecureBlackbox library can also create certificates and save and upload them to / from different formats.
source share