package com.example.rog_pc.myapplication;
import android.util.Base64;
import java.io.UnsupportedEncodingException;
/**
* Created by m on 2016/7/31.
*/
public class amBase64String {
// char set name
public final static String CHARSET = "UTF-8";
/**
* Base64
*
* @param strText
* @return String
* @throws Exception
*/
public static String encode(String strText) {
String strRet = null;
byte[] bytes = new byte[0];
try {
bytes = Base64.encode(strText.getBytes(CHARSET), Base64.DEFAULT);
strRet = new String(bytes, CHARSET);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return strRet;
}
/**
* Base64
*
* @param strEncode
* @return String
* @throws Exception
*/
public static String decode(String strEncode) {
String strRet = null;
try {
byte[] bytes = Base64.decode(strEncode.getBytes(CHARSET), Base64.DEFAULT);
strRet = new String(bytes, CHARSET);
}catch (Exception e){
e.printStackTrace();
}
return strRet;
}
}
base64加解密源码(可直接调用)
最新推荐文章于 2024-05-18 16:45:44 发布