Skip to main content
Module

x/jose/index.ts>importPKCS8

"JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto in Node.js, Browser, Cloudflare Workers, Electron, and Deno.
Extremely Popular
Go to Latest
function importPKCS8
import { importPKCS8 } from "https://deno.land/x/jose@v4.8.3/index.ts";

Imports a PEM-encoded PKCS8 string as a runtime-specific private key representation (KeyObject or CryptoKey). See Algorithm Key Requirements to learn about key to algorithm requirements and mapping. Encrypted keys are not supported.

Examples

Usage

const algorithm = 'ES256'
const pkcs8 = `-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
-----END PRIVATE KEY-----`
const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)

Parameters

pkcs8: string

PEM-encoded PKCS8 string

alg: string

JSON Web Algorithm identifier to be used with the imported key.

optional
options: PEMImportOptions