Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,可用于在HTTP环境下传递较长的标识信息。详细的Base64信息,可以参见维基百科:https://en.wikipedia.org/wiki/Base64。今天,我们开始java中base64算法的使用。

结构导航

  1. Java自带的Base64算法
  2. commons-codec的Base64算法
  3. bouncycastle的Base64算法
  4. 自定义的base64算法
  5. 友情链接

Java自带的Base64算法

项目结构如下

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASkAAAFZCAIAAABL2U4UAAAgAElEQVR4nO2d+XsTR76v+TvuD/e5z5xzuOcMmTOXkAGiJIRAEpLcDCQ5d05gMlkmmVGGhElmQhKWsIONcSAo2MRhX8xiDDZhsTAGY2wwEGMgLDZgYbwBXmQZ2xi7bWz6/qCt1u6SuqXukr7v0w+P1equLol6VdWtro+GqRHi8/maGhs7Ozu7kpvOzs6mxkafzxfpGwgAfoZFsY/P57tdW1uT3NyurQXxACNE4x4AAMYB9wDAGoy6197RuS57f8bm3IzNuRt37H/Q8xB9trnjwTvL9xs8BAAkJEbdc63f3XK31tfa0N5af6Pql4x12eizd7zdE7/O5u0LAMlM9O61tvmWLM+4XrL04a3V/bdW9VYtbzs1f92KOV/NS/9qXvqS5RmtbT7z3HM7hzlcHjNKAgB7EL17S5ZndN8rVrvKGMtQ39Cj3vv3u/jueVyOYU631gocUffczmFhTLQ1XC5eSY/LYepxgOQhevdmLcxUO46xF1X1n+ZZ4l5oO7eTNCVKuAf3uBwOhwPcA6JBy72SkpK0tDTeszPnbVLbDrCXx0MTv84+Wlmbuvv0n1ceZO0dD/d0ihTF43LwzXN5YDQMRAfXveLi4hEjRgwfPpy3wadfblPv7vIvQ007j+3fsWhZzuczsz+fmV19/e7BszXjZ25/efbOn2/czT9widqb7x76TPhvt3OYw+VyouM+j8sR6tdCXRxiAn4Ij8tBjRpZ68KDy0A5HpcDOXJYs6CS4B4QHWz3/OJNnTpVw713nVvVho1qw8a+mk3zl+Rk/FR1oGHIvxxuHPIpj/2bVbf2ffxFHrU30u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sYeISKbiIYPy4FAlGSA5ncM5TXgjTaUG/FyWih3dMMVgnCco+VjKIdlwKBKEmDNO4ZzWuRpdHKUk/AMNK4ZzCvRZbbRWSpJ2AcadwzmNciwXV5CERJMqRxzw/ktQAJg2TuAUDCAO4BgDWAewBgDeAeAFiDUffaOzrXZe/P2JybsTl34479D3oeos82dzx4Z/l+g4cAgITk/wNgsw2B1Gt9vwAAAABJRU5ErkJggg==" alt="" />

一、 引入jdk自带的rt.jar包

要使用Base64Encoder,却发现在Eclipse中无法找到该类,原来Base64Encoder并不属于JDK标准库范畴,但是又包含在了JDK中。

问题的解决方案: Project->Properties,选择Java Build Path设置项,再选择Libraries标签,Add External Jars添加%JAVA_HOME%\jre\lib\rt.jar就行。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVkAAACvCAIAAADYLDo8AAAgAElEQVR4nO1d+1sUR7ruvyI/7A/n7LOXnN0ku3vQgCzZaLJmrycxydmTRU9WVMxOjrvmsrks6y0JEcRRooSEaBBdjZeAIhIvI95RgxdEEBgQZwRhUGCYGZ2BAQbU7fNDz0zXtbuH6Rmm4Xufeh5mqqu++uqrqrerm+m3Ba/X6/V6zflFDx48GJh0ePDggTm/aLL2joY5v0ic8jDnF030OBgSwhTngq7uO5t27C/cWla4taz4q/29fc44e6gvxscFAac14LTqviYnCgpc0N18pOfm5XiOiIEgc8H9+/d9kw7379+XuIDXu41f7um70+5xdrmdnW0t1z7dtCPOHuqLSLng4dhw/4mszpKn+o4siXjN2QvShLQCe/CTyRKxAUWb44c5v4iOzD13b/3X/1v96bSjeY/VW3LjPzSJD4wLvJqx+cMs7YUnECgXEIdutndmrym8fmb10M2Nozc/GW7J6z+/6kvzsvdXrnt/5brsNYU32zsnxOdooMAF1n4vkW54Bv718IHjq1+7q57o3Pb0gyG36jLFFnwCcwEdmf7ulnMbH3s43H23vfyweXr8hybxgXHBPQrOzta6kr/Ubs6s3ZxZv+Nv7740e8nsGUtmz1jy3Azpw8p5L9C1Egco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Wwldulz3e/Emq8/JBjgHufQHkgIZ7h9gtR8RemsmUJn8tIMmFxz6ixYSfNpU+Y31RukbA/hfHWue479wLEqJfOHAuQKLINk5ZYxZjR3i8XMC+mYP3AbhAP8Tp/whVS5+7lvdfdLq6+ndVS5/ru1hhzZ/h2PPYVfMf6LrUFSjj5Bm+0Cc37zjQEujstJiw4tx/kSvdM4uMCzA3iXO7if4NBKvLUm3533CMJUf0iziEXhExN/74//gwZuAVY0VYfVyoMuHxRPmGdf8TuEA/xOn3BYdMMxtyf0enK9m/PWSaOTZ479xb0z3Hf1T9xnR/zwToRkzWSaXQL/ZdBGNhsg7bBCFOvzvcOufRXfOmMVJ60tY5j4qi2FDw5wtZ044t/GnH4W16NaoV8funfnyh2C/G/X5DAX53qDvixAW+XodCEkXR297cffZA4J5LrxY1Av0P4GTCZO0XIHaY+GeTAABAIgC4AAAAiCJwAQAAkABcAAAARBG4AAAASAAuAAAAoghcAAAAJPw/l/ohLdAmwbAAAAAASUVORK5CYII=" alt="" />

二、 我们通过junit方法,来加以对Base64算法的测试,明文:my name is huhx。

private static String src = "my name is huhx";

@Test
public void huhxBase64() {
try {
BASE64Encoder encoder = new BASE64Encoder();
String encode = encoder.encode(src.getBytes());
System.out.println("encode: " + encode); BASE64Decoder decoder = new BASE64Decoder();
String decode = new String(decoder.decodeBuffer(encode));
System.out.println("decode: " + decode);
} catch (IOException e) {
e.printStackTrace();
}
}

三、 运行结果如下:

encode: bXkgbmFtZSBpcyBodWh4
decode: my name is huhx

commons-codec的Base64算法

一、 引入commons-codec-1.10.jar包,提供对base64算法的支持

commons-codec-1.10.jar地址:https://www.bouncycastle.org/latest_releases.html

二、 我们通过junit方法,来加以对Base64算法的测试,明文:my name is huhx。

@Test
public void commonCodeBase64() {
byte[] encodeBytes = Base64.encodeBase64(src.getBytes());
System.out.println("encode: " + new String(encodeBytes)); byte[] decodeBytes = Base64.decodeBase64(encodeBytes);
System.out.println("decode: " + new String(decodeBytes));
}

三、 运行结果如下:

encode: bXkgbmFtZSBpcyBodWh4
decode: my name is huhx

bcprov的Base64算法

一、 引入bcprov-jdk15on-154.jar,提供对base64算法的支持

bcprov-jdk15on-154.jar地址: https://commons.apache.org/proper/commons-codec/download_codec.cgi

二、 我们通过junit方法,来加以对Base64算法的测试,明文:my name is huhx。

@Test
public void bouncyCodeBase64() {
byte[] encodeBytes = org.bouncycastle.util.encoders.Base64.encode(src.getBytes());
System.out.println("encode: " + new String(encodeBytes)); byte[] decodeBytes = org.bouncycastle.util.encoders.Base64.decode(encodeBytes);
System.out.println("decode: " + new String(decodeBytes));
}

三、 运行结果如下:

encode: bXkgbmFtZSBpcyBodWh4
decode: my name is huhx

自定义的base64算法

一、 HuhxBase64.java的自定义算法,内容如下:

package com.huhx.base64.jdk;

/**
* writer: huhx
*/
public class HuhxBase64 {
private static final String CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; // base64解密
private static byte[] base64Decode(String input) {
if (input.length() % 4 != 0) {
throw new IllegalArgumentException("Invalid base64 input");
}
byte decoded[] = new byte[((input.length() * 3) / 4) - (input.indexOf('=') > 0 ? (input.length() - input.indexOf('=')) : 0)];
char[] inChars = input.toCharArray();
int j = 0;
int b[] = new int[4];
for (int i = 0; i < inChars.length; i += 4) {
// This could be made faster (but more complicated) by precomputing
// these index locations.
b[0] = CODES.indexOf(inChars[i]);
b[1] = CODES.indexOf(inChars[i + 1]);
b[2] = CODES.indexOf(inChars[i + 2]);
b[3] = CODES.indexOf(inChars[i + 3]);
decoded[j++] = (byte) ((b[0] << 2) | (b[1] >> 4));
if (b[2] < 64) {
decoded[j++] = (byte) ((b[1] << 4) | (b[2] >> 2));
if (b[3] < 64) {
decoded[j++] = (byte) ((b[2] << 6) | b[3]);
}
}
}
return decoded;
} // base64加密
private static String base64Encode(byte[] in) {
StringBuilder out = new StringBuilder((in.length * 4) / 3);
int b;
for (int i = 0; i < in.length; i += 3) {
b = (in[i] & 0xFC) >> 2;
out.append(CODES.charAt(b));
b = (in[i] & 0x03) << 4;
if (i + 1 < in.length) {
b |= (in[i + 1] & 0xF0) >> 4;
out.append(CODES.charAt(b));
b = (in[i + 1] & 0x0F) << 2;
if (i + 2 < in.length) {
b |= (in[i + 2] & 0xC0) >> 6;
out.append(CODES.charAt(b));
b = in[i + 2] & 0x3F;
out.append(CODES.charAt(b));
} else {
out.append(CODES.charAt(b));
out.append('=');
}
} else {
out.append(CODES.charAt(b));
out.append("==");
}
}
return out.toString();
} public static void main(String[] args) {
String input = "I love you, huhx!";
String encode = base64Encode(input.getBytes());
System.out.println("encode: " + encode); String decode = new String(base64Decode(encode));
System.out.println("decode: " + decode);
}
}

二、 运行结果如下:

encode: SSBsb3ZlIHlvdSwgaHVoeCE=
decode: I love you, huhx!

友情链接

04-30 21:51