Wiki: Tutorial for reading PKCS5 RSA private key with password

TOP | static wiki | wiki | DOWNLOADS | TUTORIALS | API REFERENCE | DEMOS |

TOP | DOWNLOADS | TUTORIALS | API REFERENCE | DEMOS


(DELETED)

PKCS5PKEY class is deleted and merged into KEYUTIL class. Thanks.

PKCS5PKEY class provides password protected PKCS#5 PEM formatted RSA private key parser in JavaScript.

Getting Started

Here is an example of such private key.

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,40555967F759530864FE022E257DE34E

jV7uXajRw4cccDaliagcqiLOiQEUCe19l761pXRxzgQP+DH4rCi12T4puTdZyy6l
(snip)
1El24sGa3eBXi3lnpAytX7dOOBQKRh1uJyL3IuKyuFcNJj3OOGjBkR6imZwD895e
qxLS+BASmyGm4DME6m+kltZ12LXwPgNU6+d+XQ4NXSA=
-----END RSA PRIVATE KEY-----

NOTE: Please take care that header is "BEGIN RSA PRIVATE KEY". If header is "BEGIN PRIVATE KEY" it is PKCS#8 format which if differ with PKCS#5 and can be handle with PKCS5PKEY class.

To read a key as RSAKey object here is an example code:

var encryptedKey = '-----BEGIN RSA PRIVATE KEY--(snip)Proc-Type: 4,ENCRYPTED(snip)';
var decryptedKeyHex = PKCS5PKEY.getDecryptedKeyHex(encryptedKey, passcode);
var rsa = new RSAKey();
rsa.readPrivateKeyFromASN1HexString(decryptedKeyHex);

The private key you just loaded will be used for signing or encryption.

Supported Key Encryption Algorithm

Here are supported algorithms.