encrypt method
Encrypts the private key using the secret specified earlier and returns a json representation of its data as a v3-wallet file.
Implementation
String encrypt({SecretWalletEncoding encoding = SecretWalletEncoding.json}) {
final ciphertextBytes = _encryptPrivateKey();
final map = {
'crypto': {
'cipher': 'aes-128-ctr',
'cipherparams': {'iv': bytesToHex(_iv)},
'ciphertext': bytesToHex(ciphertextBytes),
'kdf': _derivator.name,
'kdfparams': _derivator.encode(),
'mac': _generateMac(_derivator.deriveKey(_password), ciphertextBytes),
},
'id': uuid,
'version': 3,
};
final toString = json.encode(map);
if (encoding == SecretWalletEncoding.json) {
return toString;
}
return base64Encode(utf8.encode(toString));
}