encryptWallet method
Encrypts a basic wallet
EncryptedWallet encryptedBasicWallet = new WalletFactory().encryptWallet(wallet, password);
Implementation
EncryptedWallet encryptWallet(BasicWallet wallet, String password) {
String walletJson = json.encode(wallet);
var key = _toSha256I(password);
var iv = _toSha256I(walletJson).sublist(0, 16);
CipherParameters params = new PaddedBlockCipherParameters(
new ParametersWithIV(new KeyParameter(key as Uint8List), iv as Uint8List), null);
BlockCipher encryptionCipher = new PaddedBlockCipher("AES/CBC/PKCS7");
encryptionCipher.init(true, params);
Uint8List encrypted = encryptionCipher.process(utf8.encode(walletJson) as Uint8List);
String cipherText = hex.encode(encrypted);
return EncryptedWallet(Source("flutter"), CipherText(cipherText),
wallet.address, Salt(hex.encode(iv)));
}