createEncryptedHook function
Future<HHPlugin>
createEncryptedHook({
- KeyRotationStrategy rotationStrategy = KeyRotationStrategy.passive,
- String secureStorageKey = 'pvcache_encryption_key',
- Uint8List? providedKey,
- bool autoResetKey = false,
- EncryptionHookController? controller,
- Future<
bool> rotationCallback()?,
Creates an encryption plugin using AES-256-CBC.
Example:
final plugin = await createEncryptedHook(
rotationStrategy: KeyRotationStrategy.passive,
);
PVCache.setDefaultPlugins([plugin]);
Implementation
Future<HHPlugin> createEncryptedHook({
KeyRotationStrategy rotationStrategy = KeyRotationStrategy.passive,
String secureStorageKey = 'pvcache_encryption_key',
Uint8List? providedKey,
bool autoResetKey = false,
EncryptionHookController? controller,
Future<bool> Function(Object error, String key)? rotationCallback,
}) async {
final keyManager = EncryptionKeyManager(
storageKey: secureStorageKey,
providedKey: providedKey,
autoResetKey: autoResetKey,
);
await keyManager.initialize();
final hook = _EncryptionTerminalHook(
keyManager: keyManager,
rotationStrategy: rotationStrategy,
controller: controller,
rotationCallback: rotationCallback,
id: 'pvcache_encryption_${_encryptionHookIdCounter++}',
);
return HHPlugin(terminalSerializationHooks: [hook]);
}