zoukankan      html  css  js  c++  java
  • md5密码生成工具

    import java.io.BufferedReader; import java.io.InputStreamReader; import java.security.MessageDigest; import java.util.Random;

    public class PasswordHash {  private static Random random = new Random();

     /**   * Default constructor.   */  public PasswordHash() {  }

     public static String encrypt(String inString) {   try {    MessageDigest md;    // MD5, SHA, SHA-1    md = MessageDigest.getInstance("MD5");    byte[] output = md.digest(inString.getBytes());    StringBuffer sb = new StringBuffer(2 * output.length);    for (int i = 0; i < output.length; ++i) {     int k = output[i] & 0xFF;     if (k < 0x10) {      sb.append('0');     }     sb.append(Integer.toHexString(k));    }    return sb.toString();   } catch (java.security.NoSuchAlgorithmException e) {   }   return null;  }

     public static void main(String args[]) {   PasswordHash hasher = new PasswordHash();   try {    String text;    if (args.length == 0) {     System.out.print("Password: ");     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));     text = in.readLine();     System.out.println("Hash: " + hasher.encrypt(text));    } else {     text = args[0];     System.out.println(hasher.encrypt(text));    }   } catch (Exception ex) {    System.out.println(ex);   }  }

     public static String getRandomString(int lo, int hi) {   int n = rand(lo, hi);   byte b[] = new byte[n];   for (int i = 0; i < n; i++) {    b[i] = (byte) rand('a', 'z');   }   return new String(b);  }

     public static int rand(int lo, int hi) {   int n = hi - lo + 1;   int i = random.nextInt() % n;   if (i < 0) {    i = -i;   }   return lo + i;  } }

  • 相关阅读:
    使用vue做项目时,刷新页面,原本应该隐藏的东西闪一下
    input type="file" 上传文件的一些使用
    vue强制重新渲染
    元素focus页面不滚动不定位的JS处理
    js使用案例
    js使用setInterval简单实现一个时钟
    js日期封装方法
    scss简单使用总结
    JavaScript的内置对象(Global对象)
    JavaScript—Date对象详情
  • 原文地址:https://www.cnblogs.com/guanghuiqq/p/2668877.html
Copyright © 2011-2022 走看看