yws token 机制

别说谁变了你拦得住时间么 提交于 2020-02-29 10:24:49



package com.youwin.yws.api.o2o.util;

import java.io.UnsupportedEncodingException;

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!