码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-11-18 12:01:26      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/james-roger/p/4973717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!