0

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?

Ekta
  • 261
  • 1
  • 2
  • 11
  • [Edit] the question and show _exactly_ what you tried. For all we know, maybe you made a copy-paste error from the other answer. – vonPryz Aug 04 '22 at 08:34
  • Did you notice the line `Note that using this method requires Powershell 7.x.` (in topaco's answer) about the method `ExportRSAPrivateKey`? – notjustme Aug 04 '22 at 08:36
  • @vonPryz I tried the code from https://stackoverflow.com/questions/72127462/trying-to-create-an-encypted-private-key-in-powershell-the-same-way-openssl-does/72134640?noredirect=1#comment129334296_72134640 but it fails while decrypting – Ekta Aug 04 '22 at 08:36
  • @notjustme yes i noticed that. But what is other way round for this? – Ekta Aug 04 '22 at 08:37

0 Answers0