decryptV2 function
Future<List<int> >
decryptV2({
- required EncryptedPrivateKeyModel encryptedData,
- required List<
int> secret,
AES-GCM Decryption
Implementation
Future<List<int>> decryptV2({
required EncryptedPrivateKeyModel encryptedData,
required List<int> secret,
}) async {
final key = await hkdf(secret, hexToBytes(encryptedData.salt!));
final algorithm = AesGcm.with256bits(nonceLength: AESGCMNonceSize);
final cipherBytes = hexToBytes(encryptedData.ciphertext.toString());
final cypherBytesSubstring = cipherBytes.sublist(0, cipherBytes.length - 16);
final mac = cipherBytes.sublist(cipherBytes.length - 16);
// Construct the secret box
final secretBox = SecretBox(cypherBytesSubstring,
nonce: hexToBytes(encryptedData.nonce!), mac: Mac(mac));
// Decrypt
final decryptedText = await algorithm.decrypt(
secretBox,
secretKey: key,
);
return decryptedText;
}