Back to Jose

Function: generateSecret()

docs/key/generate_secret/functions/generateSecret.md

6.2.91.8 KB
Original Source

Function: generateSecret()

šŸ’— Help the project

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>(alg, options?): Promise<GeneratedSecret<Alg>>

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/key/generate/secret'.

Type Parameters

Type Parameter
Alg extends string

Parameters

ParameterTypeDescription
algAlgJWA Algorithm Identifier to be used with the generated secret. See Algorithm Key Requirements.
options?GenerateSecretOptionsAdditional options passed down to the secret generation.

Returns

Promise<GeneratedSecret<Alg>>

Example

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