encrypt function

Future<String> encrypt({
  1. required String str,
  2. String? key,
})

Implementation

Future<String> encrypt({required String str, String? key}) async {
  key = key ?? MD<ApiConstants>().encryptKey;
  try {
    final encrypter = _buildEncrypter(key);
    final encrypted =
        encrypter.encrypt(str, iv: IV(Uint8List.fromList(_buildIV(key))));
    return encrypted.base64;
  } catch (e) {
    throw Exception('Encryption error: $e');
  }
}