Android的Base64加密解密
程序员文章站
2024-03-14 13:24:52
...
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 "";
}
}
上一篇: Base64加密与解密