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<KeyLikeType
>(alg
, options
?): Promise
<KeyLikeType
| Uint8Array
>
Generates a symmetric secret key for a given JWA algorithm identifier.
Note: Under Web Crypto API runtime the secret key is generated with extractable
set to false
by default.
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'
.
Type Parameter | Default type |
---|---|
KeyLikeType extends KeyLike |
KeyLike |
Parameter | Type | Description |
---|---|---|
alg |
string |
JWA Algorithm Identifier to be used with the generated secret. |
options ? |
GenerateSecretOptions |
Additional options passed down to the secret generation. |
Promise
<KeyLikeType
| Uint8Array
>
const secret = await jose.generateSecret('HS256')
console.log(secret)