-
-
Notifications
You must be signed in to change notification settings - Fork 644
Tutorial for reading PKCS5 RSA private key with password
Kenji Urushima edited this page May 8, 2021
·
1 revision
TOP | DOWNLOADS | TUTORIALS | API REFERENCE | DEMOS
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.
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.
Here are supported algorithms.
- DES-EDE3-CBC
- AES-256-CBC
- AES-192-CBC
- AES-128-CBC