• 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;  } }

  • 相关阅读:
    C#几个经常犯错误汇总
    vs2010密钥
    SQL数据库基础知识用sql语句创建数据库
    空值显示表格线条(border)
    vs2008常用快捷方式
    汉字与十六进制之间的相互转换
    asp.net中常用信息验证总结
    GridView中全选和反选
    Nonreentrant C# timer
    GC.Collect
  • 原文地址:https://www.cnblogs.com/guanghuiqq/p/2668877.html
Copyright © 2020-2023  润新知