1、最近做个react-native 项目,要求有个接口需要base64加密,使用js加密后发现中文会无法base64解密

解决办法

 1、导入2个包,如果没有则请自行下载

import java.io.UnsupportedEncodingException;
import sun.misc.BASE64Decoder;
//base64 encode
public static String encode(String s) { if (s == null) return null; String res = ""; try { res = new sun.misc.BASE64Encoder().encode(s.getBytes("GBK")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return res; }

  

//base64 decode
public static String decode(String s) { if (s == null) return null; BASE64Decoder decoder = new BASE64Decoder(); try { byte[] b = decoder.decodeBuffer(s); return new String(b,"GBK"); } catch (Exception e) { return null; } }

 如果Android 无法直接使用上面的包 ,请下载下面这个文件,亲测有效 

下载链接:链接: https://pan.baidu.com/s/1UI-cFwK_cfWDPAybI79Ndw 提取码: crh2

相关文章:

  • 2022-01-09
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-04-23
猜你喜欢
  • 2022-12-23
  • 2022-02-15
  • 2021-11-04
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案