encrypt method

String encrypt({
  1. SecretWalletEncoding encoding = SecretWalletEncoding.json,
})

Encrypts the sensitive wallet data using the specified encoding format and returns the encrypted representation.

  • encoding: The encoding format to use for the encrypted output (default is JSON).

Implementation

String encrypt({SecretWalletEncoding encoding = SecretWalletEncoding.json}) {
  if (encoding == SecretWalletEncoding.cbor) {
    return _crypto.encodeCbor(_password, _data, uuid);
  }

  // Prepare the JSON representation of the encrypted data.
  final Map<String, dynamic> toJson = {
    "crypto": _crypto.encode(_password, _data),
    "id": uuid,
    "version": 3,
  };

  // Convert the JSON to a string.
  final toString = StringUtils.fromJson(toJson);

  // Based on the specified encoding format, return the encrypted data as a string.
  if (encoding == SecretWalletEncoding.json) {
    return toString;
  }
  return StringUtils.decode(
    StringUtils.encode(toString),
    type: StringEncoding.base64,
  );
}