Extract private key from PFX file which doesn't contain certificate using Bouncy Castle

Viewed 269

Here is my scenario: Using the following openssl command to generate the pfx file which doesn't contains cert:

openssl.exe genrsa -aes256 -out E:\Temp\test.pem -passout pass:123456 2048 2

openssl.exe pkcs12 -keypbe PBE-SHA1-3DES -aes256 -export -nocerts -inkey E:\Temp\test.pem -out E:\Temp\test.pfx -passin pass:123456 -passout pass:123456

I am trying to parse the key out of the pfx file using bouncy castle. here is the simple code:

    string psw = "123456";
    string pfxPath = @"E:\Temp\test.pfx";
    using (Stream stream = File.Open(pfxPath, FileMode.Open))
    {
        Pkcs12Store pkcs = new Pkcs12StoreBuilder().Build();
        pkcs.Load(stream, psw.ToArray());
    }

However, pkcs is empty. I think it is because the PFX file doesn't have a certificate. So my question is: is there a way that bouncy castle can handle this situation?

0 Answers
Related