decryptVault function

String decryptVault(
  1. VaultBlob blob,
  2. String password
)

Open a blob. Throws VaultException when the password is wrong or the blob was tampered with.

Implementation

String decryptVault(VaultBlob blob, String password) {
  try {
    final cipher = GCMBlockCipher(AESEngine())
      ..init(
          false,
          AEADParameters(KeyParameter(_key(password, base64.decode(blob.salt))),
              128, base64.decode(blob.iv), Uint8List(0)));
    return utf8.decode(cipher.process(base64.decode(blob.ct)));
  } on VaultException {
    rethrow;
  } on Object catch (e) {
    throw VaultException('wrong password or corrupted vault ($e)');
  }
}