AEncryptionProvider Abstract Class
The foundational abstract base class that powers cryptographic operations in the Katlux ecosystem. It implements IEncryptionProvider, manages key storage and lifecycle, and defines the contract required for custom cipher adapters.
๐ CWebCryptoEncryptionProvider (Default Implementation) ยท ๐ IEncryptionProvider Interface ยท ๐ IProviderEncryptionOptions ยท ๐ Encryption & SSR Security Guide
Extending AEncryptionProvider
Subclass AEncryptionProvider to create custom cipher drivers (e.g., Cloud KMS, WebWorker-offloaded cryptography, or ChaCha20-Poly1305). Alongside ADataProvider and ACacheProvider, it forms the foundational triad of Katlux base classes.
import { AEncryptionProvider, type IEncryptedPayload, type IEncryptionContext } from '@katlux/providers'
export class CMyCustomEncryptionProvider extends AEncryptionProvider {
async encrypt(data: any, options?: IEncryptionContext): Promise<IEncryptedPayload | any> {
const key = options?.key || this.getDefaultKey()
// Implement custom encryption logic
return {
__encrypted: true,
ciphertext: '...',
iv: '...',
alg: 'CUSTOM-CIPHER'
}
}
async decrypt(payload: IEncryptedPayload | any, options?: IEncryptionContext): Promise<any> {
if (!payload?.__encrypted) return payload
const key = options?.key || this.getDefaultKey()
// Implement custom decryption logic
return JSON.parse(decryptedText)
}
}