yws token 机制

本文详细介绍了AuthorationUtil类中加密与解密的方法实现,包括如何使用Base64进行字符串的编码与解码,提供了实例代码演示,有助于深入理解加密与解密的基本原理与实践应用。

153857_f21x_2357525.png



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

转载于:https://my.oschina.net/u/2357525/blog/657393

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值