Read pfx file that is protected by a password

Viewed 36

I’m trying to read the pkcs12store to extract the private certificate and the chain of certificate. The pfx file is protected by a password. If the password is empty everything works fine, but if it holds a value it fails with the following error. Any help to resolve this would be appreciated.

var pk12 = new Pkcs12Store(new MemoryStream(privateKeyBytes), "test".ToCharArray());

Exception:

System.AggregateException: One or more errors occurred. (PKCS12 key store MAC invalid - wrong password or corrupted file.) System.IO.IOException: PKCS12 key store MAC invalid - wrong password or corrupted file at Org.BouncyCastle.Pkcs.Pkcs12Store.Load(Stream input, Char[] password)

1 Answers

Solved: In this case the certificate was stored under certificates in the keyvault. Since we need the password to import it, it looks like we don't need to pass it here again. In a way it makes sense.

Related