I need to retrieve the PrivateKey either as string or
PEM from a
PKCS12 file which uses
ECDSA-SHA256 signing algorithm. Public key retrieval is fine but for signing purpose I need to retrieve the PrivateKey.
I am using ManagedOpenSSL.dll as the wrapper for my purpose but it doesn't contain a method like:
PEM_write_PrivateKey(IntPtr bp, IntPtr x,IntPtr enc, byte kstr,int klen, pem_password_cb cb, IntPtr user_data)
When I tried to call the same method from underlying libeay32.dll in ManagedOPENSSL source it throws the following error while executing the above statement:
The libeay32.dll and ssleay32.dll versions are 1.0.21.
bio = BIO.MemoryBuffer();
byte rootcert = System.IO.File.ReadAllBytes(path);
PKCS12 pk = new PKCS12(bio, passwd);
OpenSSL.X509.X509Certificate cert1 = pkcs.Certificate;
OpenSSL.Crypto.CryptoKey evp = cert1.PrivateKey;
ManagedOPENSLL source in Native.cs I added
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int PEM_write_PrivateKey(IntPtr bp, IntPtr x,IntPtr enc, byte kstr,int klen, pem_password_cb cb, IntPtr user_data);
when OpenSSL.Crypto.CryptoKey evp is expanded in Visual Studio intellisense
Can anyone please tell me where I am going wrong or is there a better way to retrieve the Private Key?