当前位置:   article > 正文

flutter开发AES加密、SHA-1验签、base64加密、请求参数按key按ASCII排序key1=value1&key2=value2&...&keyN=valueN_flutter解密ios的加密数据

flutter解密ios的加密数据

1、AES用的是encrypt

  1. static String aesKey = 'sxcbk2gFGcODQp0daccgAh==';
  2. //AES加密
  3. static String aesEncode(String content) {
  4. try {
  5. final key = Key.fromUtf8(base64Encode(aesKey.codeUnits));
  6. final encrypter = Encrypter(AES(key, mode: AESMode.ecb));
  7. final encrypted = encrypter.encrypt(content, iv: IV.fromLength(16));
  8. return encrypted.base64;
  9. } catch (err) {
  10. print("aes encode error:$err");
  11. return content;
  12. }
  13. }
  14. //AES解密
  15. static dynamic aesDecode(dynamic base64) {
  16. try {
  17. final key = Key.fromUtf8(base64Encode(aesKey.codeUnits));
  18. final encrypter = Encrypter(AES(key, mode: AESMode.ecb));
  19. return encrypter.decrypt64(base64, iv: IV.fromLength(16));
  20. } catch (err) {
  21. print("aes decode error:$err");
  22. return base64;
  23. }
  24. }

2、SHA-1使用的是crypto

String sign = sha1.convert(utf8.encode(str)).toString();

3、请求参数按key按ASCII排序key1=value1&key2=value2&...&keyN=valueN

  1. List attrKeys = paramMap.keys.toList();
  2. attrKeys.sort(); //排序 ASCII 字符顺序进行排序
  3. var str = '';
  4. for (var i = 0; i < paramMap.length; i++) {
  5. if (i == paramMap.length - 1) {
  6. str += "${attrKeys[i]}=${paramMap[attrKeys[i]]}";
  7. } else {
  8. str += "${attrKeys[i]}=${paramMap[attrKeys[i]]}&";
  9. }
  10. }
  11. print(str);

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/820077
推荐阅读
相关标签
  

闽ICP备14008679号