File: key_import.importSPKI.md

package info (click to toggle)
node-jose 4.11.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 4,264 kB
  • sloc: javascript: 16,258; sh: 111; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Function: importSPKI

[💗 Help the project](https://github.com/sponsors/panva)

â–¸ **importSPKI**(`spki`, `alg`, `options?`): `Promise`<[`KeyLike`](../types/types.KeyLike.md)\>

Imports a PEM-encoded SPKI string as a runtime-specific public key representation (KeyObject or
CryptoKey). See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to learn
about key to algorithm requirements and mapping.

**`example`** Usage

```js
const algorithm = 'ES256'
const spki = `-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
-----END PUBLIC KEY-----`
const ecPublicKey = await jose.importSPKI(spki, algorithm)
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `spki` | `string` | - |
| `alg` | `string` | JSON Web Algorithm identifier to be used with the imported key. |
| `options?` | [`PEMImportOptions`](../interfaces/key_import.PEMImportOptions.md) | - |

#### Returns

`Promise`<[`KeyLike`](../types/types.KeyLike.md)\>