Base64编码的实现(三种方式)
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));
    }
    
}

posted on 2015-11-18 10:36  james-roger  阅读(930)  评论(0编辑  收藏  举报