descryptWallet static method

String descryptWallet(
  1. String encriptedWallet,
  2. String password
)

This method decrypts an encrypted string using the AES-256 algorithm with the given password and initialization vector (IV). It uses the Encrypter class from the encrypt library to perform the decryption. The encrypted string is expected to be in JSON format and contains an initialization vector and a ciphertext. The method returns the decrypted string in JSON format after converting it to the correct format using the StringUtilities.jsonNotEscapedToCorrectFormat method.

Implementation

static String descryptWallet(String encriptedWallet, String password){
  dynamic a = jsonDecode(encriptedWallet);

  EncKeyBean ekb = EncKeyBean.fromJson(a);
  final saltBytes = Uint8List.fromList(utf8.encode("TakamakaWallet"));
  final key = _generatePbkdf2Key(password, saltBytes);

  String ivD = ekb.wallet[0];
  final iv = base64Decode(ivD);

  // Create an AES block cipher with CBC mode of operation
  final encrypter = Encrypter(
      AES(encrypt.Key(Uint8List.fromList(key)), mode: AESMode.cbc));

  final ciphertext = Encrypted.fromBase64(ekb.wallet[1]);

  // Decifra il ciphertext utilizzando AES-256 con la chiave e l'IV
  String decryptedWallet = encrypter.decrypt(
      ciphertext, iv: IV(Uint8List.fromList(iv)));

  String escapedJson = StringUtilities.jsonNotEscapedToCorrectFormat(decryptedWallet);

  return escapedJson;
}