decryptWallet method

BasicWallet decryptWallet(
  1. EncryptedWallet wallet,
  2. String password
)

Decrypts a basic wallet

BasicWallet maybeWallet = new WalletFactory().decryptWallet(encryptedWallet, password);

Implementation

BasicWallet decryptWallet(EncryptedWallet wallet, String password) {
  var key = _toSha256I(password);
  var iv = hex.decode(wallet.salt.value!);
  var message = hex.decode(wallet.cipherText.value!);

  CipherParameters params = new PaddedBlockCipherParameters(
      new ParametersWithIV(new KeyParameter(key as Uint8List), iv as Uint8List), null);

  BlockCipher decryptionCipher = new PaddedBlockCipher("AES/CBC/PKCS7");
  decryptionCipher.init(false, params);
  String decrypted = utf8.decode(decryptionCipher.process(message as Uint8List));
  Map map = jsonDecode(decrypted);
  BasicWallet basicWallet = BasicWallet.fromJson(map as Map<String, dynamic>);
  return basicWallet;
}