Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda