首页 > 代码库 > BASE64实现加密
BASE64实现加密
有两种实现的方法:
自己添加额外jar包:javabase64-1.3.1
使用jdk自带的类,但通常都会报找不到类,解决方法就是:http://blog.csdn.net/a0501bqzhxy/article/details/6441526
< buildpath --> access rule --> add --> accessible --> ** >
方式<一>:
package com.lzj.www.base64.test;import it.sauronsoftware.base64.Base64;import org.junit.Test;public class BASE64Test { public String ecodeObject(String object){ return Base64.encode(object); } public String decodeObject(String object){ return Base64.decode(object); } @Test public void test(){ System.out.println(ecodeObject("hello")); } @Test public void test_decode(){ System.out.println(decodeObject(ecodeObject("hello"))); } }
方式<二>:
package com.lzj.www.base64.test;import org.junit.Test;import sun.misc.BASE64Decoder;import sun.misc.BASE64Encoder;public class BASE64Test { public String ecodeObject_2(String object){ byte[] b = null; if(object != null){ b = object.getBytes(); } return new BASE64Encoder().encode(b); } public String decodeObject_2(String object){ byte[] b = null; String result = null; if(object != null){ try { b = new BASE64Decoder().decodeBuffer(object); result = new String(b, "utf-8"); } catch (Exception e) { e.printStackTrace(); } } return result; } @Test public void test(){ System.out.println(ecodeObject_2("hello")); } @Test public void test_decode(){ System.out.println(decodeObject_2(ecodeObject_2("hello"))); } }
BASE64实现加密
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。