Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Trying to decrypt an private key secure with a passphrase

I try with the crypto nodejs module. But I don't succeed to make it works.

import * as crypto from 'crypto';
import { RsaPrivateKey } from 'crypto';

const privateKey = crypto.privateDecrypt(rsaPrivateKey, Buffer.from('')).toString();

I got a passphrase. I need to do this so I can import my certificate inside AWS. Someone have an idea?

I know that we can do it in golang with

if x509.IsEncryptedPEMBlock(block) {
  der, wrongPass := x509.DecryptPEMBlock(block, []byte(o.passphrase))
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,XXXXXXXXX
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Decryption is easily possible with the crypto module of NodeJS using the two functions crypto.createPrivateKey() for importing the encrypted key and keyObject.export() for exporting the unencrypted key:

crypto = require('crypto');

encryptedPkcs1 = `-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,B2FBBDCE627586CB04423335D9D4EC59

ekUVpHooHO3d5Ao0gTovipGK9DAP0MBXffEvBrtvcNcxhd9vaE6PsIxQPGwxnc/C
v9Y5RiClNwgZHtRol+i+QeZYLQHUQdOs3toymUgpIcN19IHyxU4C17PCWLZQpuVy
7hcD150dxkGv6Ai53QHIIl4Zybk6neBSbHpJtCnKjRMc6dNONpmFGqO/9SCmH/Bv
lHtPNZ9VsCDI67OO9fMQ3AqfpeGmCwJF8HgXf0nquQH1BJkZsYc4bq/xfGLFII0N
odWD1XEnwL4DWQ1r2wH0IvAXyVQUpwUmDeuDeeslQe9S5IERxovlFKIGsJnIrDLu
j420LLuiMjvj4Cipl91zZjlypsxCXgP7Ta8SDNNWo6yi0qAk1VbMAaeu2GsI6mn5
IUmGr0mkZsSxGFSc9614z+2aJjXEuX1jZ1q83nnZMTz0zEKu/0B6M5h+2B7kG5W1
-----END RSA PRIVATE KEY-----`

encryptedKey = crypto.createPrivateKey({
  key: encryptedPkcs1,
  passphrase: 'myPassword'})

decryptedKey = encryptedKey.export({
  format: 'pem',
  type: 'pkcs1',})

Note that in practice nowadays the key should not be smaller than 2048 bits for security reasons. The 512 bit key here is only used for testing.

The output is:

-----BEGIN RSA PRIVATE KEY-----
MIIBPAIBAAJBAL2D8iI9YRKCxsqDrw9WDFddW+xD2FBx383pxiW4el8M2OangbWH
FzOf8Y8ZQiw5tfocUqTvMhOcS1gThT5zUusCAwEAAQJBAJjTO0IzPwF/ZjFPKa9z
U3ZsOcF4IIsWmUTivMAUWNImFS0XiecmhiOpdgjP4LQ5gkphcC7f9VYS6Xw4suen
ZOECIQDp3GtcMdHJzQKn4fDnmTStHeEVDoqvs2tVE/HaWoYhMQIhAM900ZGxJIxK
GYrdkGU2ETvvkyRH7JStGlj3dIJDGE7bAiEAiSIFmpRkLm+XJRbqiwRdzT3+JLjY
Plt5jvQZGC+JA6ECICzJB0TwfPdcN89mrXlsBqRtv9IhRM2D4SA7q4dDfMfpAiEA
s9/2kHpLVmtpEDyw+u4Qrgt6/xUR1B39nceE1bEBo+U=
-----END RSA PRIVATE KEY----- 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!