secKeyEncryptWithHeaderAppKey static method
Implementation
static Map<String, String>? secKeyEncryptWithHeaderAppKey(String auth) {
try {
final iv = IV.fromUtf8(UFUtils.encryptionIV);
final key = Key.fromSecureRandom(32).bytes;
final appKeyData = DateTime.now().toUtc().toString();
final jsonMap = {DATE_KEY: appKeyData, ACCOUNT_TYPE: UFUtils.xPortal};
if (auth.isNotEmpty) jsonMap['authorization'] = "Bearer $auth";
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),
DEVICE_TYPE_KEY: 'android',
} : jsonMap;
return result;
} catch (e) {
return null;
}
}