mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
1.7 KiB
1.7 KiB
Function: importPKCS8
💗 Help the project
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.
â–¸ importPKCS8<T>(pkcs8, alg, options?): Promise<T>
Imports a PEM-encoded PKCS#8 string as a runtime-specific private key representation (KeyObject or CryptoKey).
Type parameters
| Name | Type |
|---|---|
T |
extends KeyLike = KeyLike |
Parameters
| Name | Type | Description |
|---|---|---|
pkcs8 |
string |
- |
alg |
string |
(Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used with the imported key, its presence is only enforced in Web Crypto API runtimes. See Algorithm Key Requirements. |
options? |
PEMImportOptions |
- |
Returns
Promise<T>
Example
const algorithm = 'ES256'
const pkcs8 = `-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
-----END PRIVATE KEY-----`
const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)