光辉飞翔

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

 

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

posted on   光辉飞翔  阅读(474)  评论(0编辑  收藏  举报
编辑推荐:
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
 
点击右上角即可分享
微信分享提示