Base64编码的实现(三种方式)

时间:2024-08-14 10:04:38
package com.smart.base;

import org.apache.commons.codec.binary.Base64;
public class Base64Test { private static String src = "imooc security base64";
public static void main(String[] args) {
// commonsBase64();
bouncyBase64();
} public static void commonsBase64(){
byte[] encodeBytes = Base64.encodeBase64(src.getBytes());
System.out.println("encode:"+new String(encodeBytes));
byte[] decodeBytes = Base64.decodeBase64(encodeBytes);
System.out.println(new String(decodeBytes));
} public static void bouncyBase64(){
byte[] encodeBytes = org.bouncycastle.util.encoders.Base64.encode(src.getBytes());
System.out.println(new String(encodeBytes));
byte[] decodeBytes = org.bouncycastle.util.encoders.Base64.decode(encodeBytes);
System.out.println(new String(decodeBytes));
} }

Base64编码的实现(三种方式)