mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
Correct subpath names that otherwise lead users to unexported entries, and fix examples, links, and missing descriptions in published JSDoc. Use instanceof in JWKS recovery examples so strict TypeScript can narrow caught errors. Signed-off-by: Filip Skokan <[email protected]>
1.8 KiB
1.8 KiB
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
extractableset tofalseby 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
| Parameter | Type | Description |
|---|---|---|
alg |
Alg |
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<GeneratedSecret<Alg>>
Example
const secret = await jose.generateSecret('HS256')
console.log(secret)