您的位置:首页 > 运维架构 > Apache

Base64 Java org.apache.commons.codec.binary.Base64

2016-03-17 15:32 531 查看
Base64组成由 26个区分大小写字母  + 10个数字 + 一个加号 和 一个/

package com.base64;

import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;

public class Base64_ {
public static String base64encode(String message) {
try {
byte[] encodeBase64 = Base64.encodeBase64(message.getBytes("UTF-8"));
System.out.println("Result:" + new String(encodeBase64));
return new String(encodeBase64);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException();
}

}

public static String base64decode(String message) {
byte[] encodeBase64 = Base64.decodeBase64(message);
System.out.println("Result:" + new String(encodeBase64));
return new String(encodeBase64);

}

}
<pre name="code" class="java">package com.base64;

public class Base64Test {

public static void main(String[] args) {

String str = "Hello World";
String str2 = Base64_.base64encode(str);
System.out.println(str2);
String str1 = Base64_.base64decode(str2);
System.out.println(str1);
}

}



需要引包   import org.apache.commons.codec.binary.Base64;

apacheBase64包
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: