mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
1.3 KiB
1.3 KiB
Function: importSPKI
key/import.importSPKI
▸ importSPKI(spki, alg, options?): Promise<KeyLike>
Imports an PEM-encoded SPKI string as a runtime-specific public key representation (KeyObject or CryptoKey). See Algorithm Key Requirements to learn about key to algorithm requirements and mapping.
example ESM import
import { importSPKI } from 'jose/key/import'
example CJS import
const { importSPKI } = require('jose/key/import')
example Deno import
import { importSPKI } from 'https://deno.land/x/jose@v3.20.1/key/import.ts'
example Usage
const algorithm = 'ES256'
const spki = `-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
-----END PUBLIC KEY-----`
const ecPublicKey = await importSPKI(spki, algorithm)
Parameters
| Name | Type | Description |
|---|---|---|
spki |
string |
- |
alg |
string |
JSON Web Algorithm identifier to be used with the imported key. |
options? |
PEMImportOptions |
- |
Returns
Promise<KeyLike>