Base64 Java org.apache.commons.codec.binary.Base64
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包
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
