encryptMyData method
- Info: Encyrpting the data.
- Params:
_key
is is Key String, iv
is IV String.
- Returns: String?
- Notes: Key length must be == 32 , IV length must be == 16.
Implementation
String? encryptMyData(String _key, String iv) {
try {
if (_key.length == 32 && iv.length == 16) {
final e = Encrypter(
AES(Key.fromUtf8(_key), mode: AESMode.ctr, padding: null));
final encryptedData = e.encrypt(this, iv: IV.fromUtf8(iv));
String urlEncData = Uri.encodeComponent(encryptedData.base64);
return urlEncData;
} else {
throw Exception("Length error. Check Key and IV Length.");
}
} catch (e) {
printLog(e.toString(), LogLevel.error);
return null;
}
}