Skip to content

Latest commit

 

History

History
35 lines (22 loc) · 1.95 KB

generateSecret.md

File metadata and controls

35 lines (22 loc) · 1.95 KB

Function: generateSecret()

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.

generateSecret(alg, options?): Promise<Uint8Array | CryptoKey>

Generates a symmetric secret key for a given JWA algorithm identifier.

Note: The secret key is generated with extractable set to false by default.

Note: Because A128CBC-HS256, A192CBC-HS384, and A256CBC-HS512 secrets cannot be represented as CryptoKey this method yields a Uint8Array for them instead.

This function is exported (as a named export) from the main 'jose' module entry point as well as from its subpath export 'jose/generate/secret'.

Parameters

Parameter Type Description
alg string JWA Algorithm Identifier to be used with the generated secret. See Algorithm Key Requirements.
options? GenerateSecretOptions Additional options passed down to the secret generation.

Returns

Promise<Uint8Array | CryptoKey>

Example

const secret = await jose.generateSecret('HS256')
console.log(secret)