crypt.generatekey
Generates a random encryption key.
Syntax
crypt.generatekey() -> stringReturns
| Type | Description |
|---|---|
string | A Base64-encoded random key |
Description
crypt.generatekey generates a cryptographically secure random key suitable for use with encryption functions.
Example
-- Generate a key
local key = crypt.generatekey()
print("Generated key:", key)
-- Use the key for encryption
local data = "Secret message"
local encrypted = crypt.encrypt(data, key)
local decrypted = crypt.decrypt(encrypted, key)
print("Original:", data)
print("Decrypted:", decrypted)Notes
- The key is suitable for AES encryption
- Keys should be stored securely and not shared
Related Functions
crypt.encrypt- Encrypt datacrypt.decrypt- Decrypt datacrypt.generatebytes- Generate raw bytes