当前位置: 代码迷 >> 综合 >> 【常用工具】java base64加密工具类
  详细解决方案

【常用工具】java base64加密工具类

热度:37   发布时间:2024-01-17 10:06:12.0

java base64加密工具类

import org.apache.commons.codec.binary.Base64;public class Base64Method {
    public static String EncryptBase64(String a_strString) throws Exception {
    Base64 base64 = new Base64();String base64str = new String(base64.encode(a_strString.getBytes("utf-8")), "utf-8");base64str = base64str.replace("\n", "").replace("\r", "").replace('+', '-').replace('/', '_');return base64str;}public static String EncryptBase64(byte[] bytes) throws Exception {
    Base64 base64 = new Base64();String base64str = new String(base64.encode(bytes), "utf-8");base64str = base64str.replace("\n", "").replace("\r", "").replace('+', '-').replace('/', '_');return base64str;}public static String DecryptBase64(String a_strString) throws Exception {
    Base64 base64 = new Base64();byte[] bytes = base64.decode(a_strString.replace('-', '+').replace('_', '/').getBytes("utf-8"));String str = new String(bytes, "utf-8");return str;}public static byte[] DecryptBase64ForByte(String a_strString)throws Exception {
    Base64 base64 = new Base64();byte[] bytes = base64.decode(a_strString.replace('-', '+').replace('_', '/').getBytes("utf-8"));return bytes;}
}
  相关解决方案