lwx-apllo

java加密算法之base64篇

转码

String转码byte数组

public static byte[] encodeStringForByte(String source) {
    return source == null ? new byte[]{} : Base64.encodeBase64(source.getBytes());
}

byte数组转码byte数组

public static byte[] encodeStringForByte(byte[] source) {
   return source == null ? new byte[]{} : Base64.encodeBase64(source);
}

string转码string

public static String encodeStringForString(String source) {
   return source == null ? "" : new String(Base64.encodeBase64(source.getBytes()));
}

byte数组转码string

 public static String encodeByteForString(byte[] source) {
    return source == null ? "" : new String(Base64.encodeBase64(source));
}

解码

string解码byte数组

public static byte[] decodeStringForByte(String source) {
    return source == null ? new byte[]{} : Base64.decodeBase64(source.getBytes());
}

byte数组解码byte数组

public static byte[] decodeByteForByte(byte[] source) {
   return source == null ? new byte[]{} : Base64.decodeBase64(source);
}

string解码string

public static String decodeStringForString(String source) {
    return source == null ? "" : new String(Base64.decodeBase64(source.getBytes()));
}

byte数组解码string

public static String decodeByteForString(byte[] source) {
    return source == null ? "" : new String(Base64.decodeBase64(source));
}

>>>源码下载链接>>>

posted on 2021-06-05 15:46  lwx-apllo  阅读(79)  评论(0)    收藏  举报