1、AES用的是encrypt
static String aesKey = 'sxcbk2gFGcODQp0daccgAh==';
//AES加密
static String aesEncode(String content) {
try {
final key = Key.fromUtf8(base64Encode(aesKey.codeUnits));
final encrypter = Encrypter(AES(key, mode: AESMode.ecb));
final encrypted = encrypter.encrypt(content, iv: IV.fromLength(16));
return encrypted.base64;
} catch (err) {
print("aes encode error:$err");
return content;
}
}
//AES解密
static dynamic aesDecode(dynamic base64) {
try {
final key = Key.fromUtf8(base64Encode(aesKey.codeUnits));
final encrypter = Encrypter(AES(key, mode: AESMode.ecb));
return encrypter.decrypt64(base64, iv: IV.fromLength(16));
} catch (err) {
print("aes decode error:$err");
return base64;
}
}
2、SHA-1使用的是crypto
String sign = sha1.convert(utf8.encode(str)).toString();
3、请求参数按key按ASCII排序key1=value1&key2=value2&...&keyN=valueN
List attrKeys = paramMap.keys.toList();
attrKeys.sort(); //排序 ASCII 字符顺序进行排序
var str = '';
for (var i = 0; i < paramMap.length; i++) {
if (i == paramMap.length - 1) {
str += "${attrKeys[i]}=${paramMap[attrKeys[i]]}";
} else {
str += "${attrKeys[i]}=${paramMap[attrKeys[i]]}&";
}
}
print(str);