secKeyEncryptWithHeaderAppKey static method
Implementation
static Map<String, String>? secKeyEncryptWithHeaderAppKey(String auth, Map<String, dynamic>? jsonDecode) {
try {
final iv = IV.fromUtf8(UFUtils.encryptionIV);
final key = Key.fromSecureRandom(32).bytes;
final appKeyData = DateTime.now().toUtc().toString();
final jsonMap = {dataKey: appKeyData, accountType: UFUtils.xPortal};
if (auth.isNotEmpty) jsonMap['authorization'] = "Bearer $auth";
if (jsonDecode != null) {
jsonDecode.forEach((key, value) {
jsonMap[key] = "$value";
});
}
debugPrint("Headers ----------- $jsonMap");
final encrypter = Encrypter(AES(Key(key), mode: AESMode.cbc));
final randomString = jsonEncode(jsonMap);
final encrypted = encrypter.encrypt(randomString, iv: iv);
final result = UFUtils.applyEncryption
? {
sek: hex.encode(encrypted.bytes),
hash: hex.encode(key),
deviceTypeKey: 'android',
} : jsonMap;
return result;
} catch (e) {
return null;
}
}