Base64编码解码

作者: wilsoncai 分类: 加密解密 发布时间: 2018-01-06 00:56
package com.wilson.EDecryption;

import java.io.UnsupportedEncodingException;

import junit.framework.Assert;

import org.apache.commons.codec.binary.Base64;
import org.junit.Test;

public class Base64CoderTest {
public final static String ENCODING = "UTF-8";

@Test
public void testBase64() throws UnsupportedEncodingException {
    String inputStr="Java加密";
    System.out.println("原文:\t" + inputStr);
    String code = new String(Base64.encodeBase64(inputStr.getBytes(ENCODING)), ENCODING);
    System.out.println("密文:\t" + code);
    String outputStr = new String(Base64.decodeBase64(code.getBytes(ENCODING)));
    System.out.println("解密:\t" + outputStr);
    Assert.assertEquals(inputStr, outputStr);
}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注