encrypt
Type: encrypt(content: string): APIResult<string>
The encrypt()
method encrypts a given string using the AES-GCM algorithm.
Overview
This method enhances security by encrypting data using the AES-GCM algorithm with a 96-bit Initialization Vector (IV). The result is returned in the following format:
iv:encryptedData:authTag
Parameters
Option | Type | Description |
---|---|---|
content | string | The plaintext string to encrypt |
Return Value
- On success: Returns an
APIResult<string>
object containing the encrypted string. - On failure: Returns an
APIResult<string>
object with error information.
Example Usage
TypeScript
const = .().("hello world");
if (.) {
.(.); // "abc123:encrypted:tag456"
} else {
.(.);
}
Notes
- The
secretKey
must be a 64-character (32-byte) hexadecimal string. - This method executes synchronously.
Last updated on