zoukankan      html  css  js  c++  java
  • sha1加密算法【收藏】

    public static String getSha1(String str){
            if (null == str || 0 == str.length()){
                return null;
            }
            char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                    'a', 'b', 'c', 'd', 'e', 'f'};
            try {
                MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
                mdTemp.update(str.getBytes("UTF-8"));
                 
                byte[] md = mdTemp.digest();
                int j = md.length;
                char[] buf = new char[j * 2];
                int k = 0;
                for (int i = 0; i < j; i++) {
                    byte byte0 = md[i];
                    buf[k++] = hexDigits[byte0 >>> 4 & 0xf];
                    buf[k++] = hexDigits[byte0 & 0xf];
                }
                return new String(buf);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return null;
        }

  • 相关阅读:
    Individual Project
    最后的作业
    Reading Task 2 —— by12061154Joy
    Code Review —— by12061154Joy
    Pair Project —— Elevator Scheduler
    《移山之道》Reading Task——by12061154Joy
    Individual Project
    qa_model
    个人阅读作业2
    Personal Reading Assignment 2 -读推荐文章有感以及项目开发目前总结
  • 原文地址:https://www.cnblogs.com/JasonTech0713/p/6227715.html
Copyright © 2011-2022 走看看