decrypt function
Future<String?>
decrypt(
- String cipher,
- EncryptionKey key, {
- AuthClient? client,
- String? additionalAuthenticatedData,
Decrypts a value using Google Cloud KMS.
Implementation
Future<String?> decrypt(
String cipher,
EncryptionKey key, {
AuthClient? client,
String? additionalAuthenticatedData,
}) async {
final authClient = client ?? await clientViaMetadataServer();
final kmsApi = CloudKMSApi(authClient);
final keyPath = await _keyPath(key);
final decryptRequest = DecryptRequest(
ciphertext: cipher,
additionalAuthenticatedData: _base64Encode(additionalAuthenticatedData),
);
final decryptResponse = await kmsApi.projects.locations.keyRings.cryptoKeys
.decrypt(decryptRequest, keyPath);
if (decryptResponse.plaintext == null) {
return null;
}
return utf8.decode(base64.decode(decryptResponse.plaintext!));
}