Constructor
(package) new PublicKey() → {CryptoKey}
- Description:
Create a empty public key
- Source:
Returns:
- Type
- CryptoKey
Methods
(async) fromCose(cose) → {Promise.<PublicKey>}
- Description:
Import public key from COSE data. Throws on any type of failure.
Internally this function converts COSE to a JWK, then calls .fromJwk() to import key to CryptoKey
- Source:
Parameters:
Name | Type | Description |
---|---|---|
cose |
object | COSE data |
Returns:
- Returns itself for chaining
- Type
- Promise.<PublicKey>
fromCryptoKey(key, algopt) → {CryptoKey}
- Description:
Import a CryptoKey, makes basic checks and throws on failure
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
CryptoKey | CryptoKey to import |
|
alg |
object |
<optional> |
Algorithm override |
Returns:
- Returns this for chaining
- Type
- CryptoKey
(async) fromJWK(jwk) → {Promise.<PublicKey>}
- Description:
Import public key from JWK. Throws on any type of failure.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
jwk |
object | JWK object |
Returns:
- Returns itself for chaining
- Type
- Promise.<PublicKey>
(async) fromPem(pem) → {Promise.<PublicKey>}
- Description:
Import public key from SPKI PEM. Throws on any type of failure.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
pem |
string | PEM formatted string |
Returns:
- Returns itself for chaining
- Type
- Promise.<PublicKey>
getAlgorithm() → {object|undefined}
- Description:
Returns internal algorithm, which should be of one of the following formats
- RsaHashedImportParams
- EcKeyImportParams
- undefined
- Source:
Returns:
- Internal algorithm representation, or undefined
- Type
- object | undefined
getKey() → {CryptoKey}
- Description:
Returns internal key in CryptoKey format
- Mainly intended for internal use
- Throws if internal CryptoKey does not exist
- Source:
Returns:
- Internal CryptoKey instance, or undefined
- Type
- CryptoKey
setAlgorithm(algorithmInput) → {object|undefined}
- Description:
Sets internal algorithm identifier in format used by webcrypto, should be one of
- Allows adding missing properties
- Makes sure
alg.hash
is is{ hash: { name: 'foo'} }
format - Syncs back updated algorithm to this._key
- Source:
Parameters:
Name | Type | Description |
---|---|---|
algorithmInput |
object | RsaHashedImportParams, EcKeyImportParams, JWK or JWK-like |
Returns:
- Internal algorithm representation, or undefined
- Type
- object | undefined
toCose() → {object}
- Description:
Exports public key to COSE data
- Only works if original cose data from 'fromCose()' is available
- Throws on any kind of failure
- Source:
Returns:
- Returns COSE data object
- Type
- object
toJwk() → {object}
- Description:
Exports public key to JWK.
- Only works if original jwk from 'fromJwk()' is available
- Throws on any kind of failure
- Source:
Returns:
- Returns JWK object
- Type
- object
(async) toPem(forcedExportopt) → {Promise.<string>}
- Description:
Exports public key to PEM.
- Reuses original PEM string if present.
- Possible to force regeneration of PEM string by setting 'forcedExport' parameter to true
- Throws on any kind of failure
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
forcedExport |
boolean |
<optional> |
Force regeneration of PEM string even if original PEM-string is available |
Returns:
- Returns PEM string
- Type
- Promise.<string>