SymmetricKeyBuilder
A builder class for creating and importing symmetric keys. This class provides methods to configure key properties and generate or import symmetric keys.
Extends
BaseCryptoClass
Accessors
algorithm
Set Signature
set algorithm(
algorithm
):void
Set the algorithm this key will be used with. Defaults to AES-256.
Throws
InvalidArgumentError If the algorithm is not supported.
Parameters
algorithm
The symmetric algorithm to use.
Returns
void
bits
Set Signature
set bits(
bits
):void
Set the number of bits for the key. Defaults to 256 for AES.
Parameters
bits
number
The number of bits for the key.
Returns
void
exportable
Set Signature
set exportable(
exportable
):void
Set whether the key is exportable.
Remarks
A key is NOT exportable unless explicitly set so.
Parameters
exportable
boolean
A boolean value indicating whether the key is exportable.
Returns
void
purposes
Set Signature
set purposes(
purposes
):void
Set the purposes for which the key can be used.
Throws
InvalidArgumentError If any argument is not a valid purpose.
Parameters
purposes
An array of key purposes.
Returns
void
Methods
buildFromRaw()
buildFromRaw(
rawKey
):Promise
<SymmetricKey
>
Build a symmetric key from raw bytes.
Parameters
rawKey
ArrayBuffer
The actual bytes to be used as the symmetric key.
Returns
Promise
<SymmetricKey
>
A promise that resolves to the built symmetric key.
Remarks
The created key will inherit the properties (algorithm, purposes, exportability) set on this builder.
buildGenerated()
buildGenerated():
Promise
<SymmetricKey
>
Build a new symmetric key based on the configured properties.
Returns
Promise
<SymmetricKey
>
A promise that resolves to the generated symmetric key.
Throws
InvalidArgumentError If the chosen key size is invalid.
Last updated: Sep 30, 2025