zoukankan      html  css  js  c++  java
  • 常用公共工具类——生成token

    public class TokenGenerator {
    
        public static String generateValue() {
            return generateValue(UUID.randomUUID().toString());
        }
    
        private static final char[] hexCode = "0123456789abcdef".toCharArray();
    
        public static String toHexString(byte[] data) {
            if(data == null) {
                return null;
            }
            StringBuilder r = new StringBuilder(data.length*2);
            for ( byte b : data) {
                r.append(hexCode[(b >> 4) & 0xF]);
                r.append(hexCode[(b & 0xF)]);
            }
            return r.toString();
        }
    
        //生成Token值
        public static String generateValue(String param) {
            try {
                MessageDigest algorithm = MessageDigest.getInstance("MD5");
                algorithm.reset();
                algorithm.update(param.getBytes());
                byte[] messageDigest = algorithm.digest();
                return toHexString(messageDigest);
            } catch (Exception e) {
                throw new RRException("生成Token失败", e);
            }
        }
    }
    一个小小后端的爬行痕迹
  • 相关阅读:
    正向代理和反向代理
    Unicode
    utf-8
    ISO 8895-1
    ProtocalBuffers学习记录
    C#基础知识
    MSBuild学习记录
    Linux学习笔记
    Jenkins学习记录
    CruiseControl.Net学习记录
  • 原文地址:https://www.cnblogs.com/heikedeblack/p/14981991.html
Copyright © 2011-2022 走看看