Android base64 encryption Chinese garbage problem solving record

1, recently do a react-native projects require interfaces required base64 encryption, the encryption using js found Chinese will not decrypt base64

Solution

 1, into two packages, if not then please download

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; } }

 If you can not use the Android package directly above, please download the file below, effective pro-test 

Download Link: Link: https://pan.baidu.com/s/1UI-cFwK_cfWDPAybI79Ndw extraction code: crh2

Guess you like

Origin www.cnblogs.com/pxjbk/p/12585182.html