zoukankan      html  css  js  c++  java
  • SHA加密

    package SSM.utils;
    
    import java.security.MessageDigest;
    import java.util.Calendar;
    import java.util.TimeZone;
    
    /**
     * SHA加密工具类
     * @author zhouhe
     * @date 2020/6/29 11:39
     */
    public class SecuritySHA1Utils {
        public static String shaEncode(String inStr) throws Exception {
            MessageDigest sha = null;
            try {
                sha = MessageDigest.getInstance("SHA");
            } catch (Exception e) {
                System.out.println(e.toString());
                e.printStackTrace();
                return "";
            }
    
            byte[] byteArray = inStr.getBytes("UTF-8");
            byte[] md5Bytes = sha.digest(byteArray);
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16) {
                    hexValue.append("0");
                }
                hexValue.append(Integer.toHexString(val));
            }
            return hexValue.toString();
        }
    
        public static void main(String args[]) throws Exception {
            Calendar cal = Calendar.getInstance();
            TimeZone tz = TimeZone.getTimeZone("GMT");
            cal.setTimeZone(tz);
            String timeStr = String.valueOf(cal.getTimeInMillis()/1000);    //返回的UTC时间戳(秒级) 这里要注意我们得到的UTC时间戳是毫秒,所以要除以1000
            System.out.println("t:"+timeStr);
    
            String str = new String("123456789");
            System.out.println("原始:" + str);
            System.out.println("SHA后:" + shaEncode(str));
        }
    
    }
  • 相关阅读:
    Django —— DateTimeField格式
    Django——权限组件(中间件判断用户权限--URL初级)
    linux命令
    性能测试--测试分类
    web安全之csrf攻击
    web安全之xss攻击
    测试用例规范
    禅道操作手册
    fiddler弱网测试
    Web测试系列之测试工具
  • 原文地址:https://www.cnblogs.com/zhouheblog/p/13208755.html
Copyright © 2011-2022 走看看