postRead method

  1. @override
void postRead(
  1. PHiveCtx ctx
)

Decrypts a previously encrypted string value using the stored nonce.

Implementation

@override
/// Decrypts a previously encrypted string value using the stored nonce.
void postRead(PHiveCtx ctx) {
  if (ctx.value is! String || !ctx.metadata.containsKey(_nonceMetadataKey)) {
    return;
  }

  final nonce = Uint8List.fromList(
    base64Url.decode(ctx.metadata[_nonceMetadataKey] as String),
  );
  final ciphertext = Uint8List.fromList(base64Url.decode(ctx.value as String));
  final key = PhiveMetaRegistry.requireSeedSync(seedId);
  final cipher = _buildCipher(false, key, nonce);

  final plaintext = cipher.process(ciphertext);
  ctx.value = utf8.decode(plaintext);
}