generateSecureKey
Type: generateSecureKey(): string
generateSecureKey()
is a static method that generates a secure, random secret key suitable for use with encryption algorithms, particularly AES-256-GCM.
TypeScript
const = .();
Overview
- The generated key is 32 bytes (256 bits) of random binary data, converted to a hexadecimal string.
- The result is a 64-character hex string, ideal for use as the
secretKey
in AES-256-GCM encryption.
Return Value
string
: A secure 64-character hexadecimal key.
Example Usage
TypeScript
const = .();
.();
// Example output: '6f8c2d7e3b91ab94f3a17e2a9e8210a7d8b2f501b2374c9b0c985d3a3e812f42'
Notes
- This method generates a new random key every time it is called. Store the generated key securely in a
.env
file or another secure configuration source. - The generated key should be used consistently for encryption and decryption purposes.
Last updated on