BeechCMS / @beechcms/core / PrivacyService
Class: PrivacyService
Concrete Edge-native implementation of IPrivacyService. Employs Web Crypto API (crypto.subtle) for zero-dependency execution in Cloudflare Workers.
Implements
Constructors
Constructor
new PrivacyService(
masterKey):PrivacyService
Initializes the PrivacyService with a Master Encryption Key.
Parameters
masterKey
string
Secret key used to derive cryptographic keys for AES-GCM and HMAC.
Returns
PrivacyService
Throws
Error if masterKey is empty or undefined.
Methods
decrypt()
decrypt(
ciphertext):Promise<string>
Decrypts a v1:<iv_base64>:<ciphertext_base64> string back to its plaintext value. If the input string is not prefixed with v1:, returns the raw string as unencrypted legacy data.
Parameters
ciphertext
string
Returns
Promise<string>
Implementation of
encrypt()
encrypt(
plaintext):Promise<string>
Encrypts a plaintext string with AES-256-GCM and a fresh 96-bit (12-byte) IV. Output is formatted as v1:<iv_base64>:<ciphertext_base64>.
Parameters
plaintext
string
Returns
Promise<string>
Implementation of
hash()
hash(
plaintext):Promise<string>
Computes a deterministic HMAC SHA-256 hex digest for blind index generation.
Parameters
plaintext
string
Returns
Promise<string>