Android的Base64加密解密
2019-01-15 本文已影响0人
Small_Cake
import android.util.Base64;
import java.io.UnsupportedEncodingException;
public class Base64Utils {
/**
* 字符Base64加密
* @param str
* @return
*/
public static String encodeToString(String str){
try {
return Base64.encodeToString(str.getBytes("UTF-8"), Base64.DEFAULT);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
/**
* 字符Base64解密
* @param str
* @return
*/
public static String decodeToString(String str){
try {
return new String(Base64.decode(str.getBytes("UTF-8"), Base64.DEFAULT));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
}