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加解密源码(可直接调用)
最新推荐文章于 2022-09-06 19:26:55 发布
本文介绍了一个简单的Base64编码与解码的Java实现方法。该方法使用了Android平台提供的Base64工具类进行编码和解码操作,并定义了一个固定的字符集UTF-8。文章中的类提供了两个静态方法,分别用于将字符串转换为Base64编码格式及从Base64格式还原为原始字符串。
351

被折叠的 条评论
为什么被折叠?



