package com.youwin.yws.api.o2o.util;java
import java.io.UnsupportedEncodingException;api
import java.util.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
*
* 類 名: AuthorationUtil
* 描 述: 描述類完成的主要功能
* 做 者: sunqc@youwinedu.com
* 創 建:2016年5月6日
* 版 本:
*
* 歷 史: (版本) 做者 時間 註釋
*/
public class AuthorationUtil {
// 加密
public static String getBase64(String str) {
byte[] b = null;
String s = null;
try {
b = str.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (b != null) {
s = new BASE64Encoder().encode(b);
}
return s;
}
// 解密
public static String getFromBase64(String s) {
byte[] b = null;
String result = null;
if (s != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(s);
result = new String(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
public static void main(String[] args) {
System.out.println("==========1==========");//15226
String result = AuthorationUtil.getBase64("18500199757:cfca5efe-1a4c-46f6-b44f-6fb4bb6ddd65");
System.out.println(result);
System.out.println("==========2==========");//15019
String result2 = AuthorationUtil.getBase64("jiaosszj:cc7e2098-c7aa-40c7-ba71-03e6395a9f47");
System.out.println(result2);
System.out.println("==========3==========");//15017
String result3 = AuthorationUtil.getBase64("13912345678:4187ecad-cfbb-474a-ba65-cba2fc9abe62");
System.out.println(result3);
}
}
加密
==========1==========
MTg1MDAxOTk3NTc6Y2ZjYTVlZmUtMWE0Yy00NmY2LWI0NGYtNmZiNGJiNmRkZDY1
==========2==========
amlhb3Nzemo6Y2M3ZTIwOTgtYzdhYS00MGM3LWJhNzEtMDNlNjM5NWE5ZjQ3
==========3==========
MTM5MTIzNDU2Nzg6NDE4N2VjYWQtY2ZiYi00NzRhLWJhNjUtY2JhMmZjOWFiZTYy
code