I have tried implementing the code provided by https://stackoverflow.com/users/9014097/topaco from Trying to create an encypted private key in PowerShell the same way Openssl does it
But it fails with the below error
6788:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:./crypto/asn1/tasn_dec.c:1294: 6788:error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error:./crypto/asn1/tasn_dec.c:830: 6788:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:./crypto/asn1/tasn_dec.c:749:Field=n, Type=RSA 6788:error:0D09A00D:asn1 encoding routines:d2i_PrivateKey:ASN1 lib:./crypto/asn1/d2i_pr.c:99: 6788:error:0907B00D:PEM routines:PEM_READ_BIO_PRIVATEKEY:ASN1 lib:./crypto/pem/pem_pkey.c:125:
Also I am not able to use ExportRSAPrivateKey() function.
CAn you please help me here
Basically i have a certificate in PFX format from that i am able to fetch the private key like this -----BEGIN RSA PRIVATE KEY------Value----END RSA PRIVATE KEY-----. Now i want to convert this to encrypted private key and it should look like -----BEGIN ENCRYPTED PRIVATE KEY-----Value-----END ENCRYPTED PRIVATE KEY-----
I know using openssl its possible but i dont have openssl installed in the server and we are not planning to install as well. Is there any possibility that we can get this done using powershell?