@withstudiocms/auth-kit
Version:
Utilities for managing authentication
23 lines (22 loc) • 1.69 kB
TypeScript
import { Effect } from '@withstudiocms/effect';
/**
* Factory function to create an encryption module using AES-128-GCM.
*
* @param CMS_ENCRYPTION_KEY - The base64-encoded encryption key to use for encryption and decryption.
* @returns An Effect that yields an object containing encryption and decryption utilities:
* - `encrypt`: Encrypts a Uint8Array and returns the encrypted data as a Uint8Array.
* - `encryptToString`: Encrypts a string and returns the encrypted data as a Uint8Array.
* - `decrypt`: Decrypts an encrypted Uint8Array and returns the decrypted data as a Uint8Array.
* - `decryptToString`: Decrypts an encrypted Uint8Array and returns the decrypted data as a string.
*
* @remarks
* The encrypted data format is: [IV (16 bytes)] + [encrypted content] + [auth tag (16 bytes)].
* The encryption key must be a valid base64-encoded string suitable for AES-128-GCM.
* Throws errors if encryption or decryption fails, or if the input data is invalid.
*/
export declare const Encryption: (CMS_ENCRYPTION_KEY: string) => Effect.Effect<{
readonly encrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("../errors.js").EncryptionError, never>;
readonly encryptToString: (data: string) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("../errors.js").EncryptionError, never>;
readonly decrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("../errors.js").DecryptionError, never>;
readonly decryptToString: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<string, import("../errors.js").DecryptionError, never>;
}, import("../errors.js").EncryptionError, never>;