password.java.htm
来自「JAVA的加密源程序」· HTM 代码 · 共 40 行
HTM
40 行
<html>/*Christoforos Pirillos @ Villanova University - May 1999based on code from the book "Java Network Programming" by Hughes*/package encryption;/**Generates keys from passwords*/public class Password {/**Converts the supplied String into an array of bytes and returns adigest of this*/public static long keyFromPassword (String password) { byte[] passwordBytes = new byte[password.length()*2]; for (int i =0; i<password.length();++i) { char c=password.charAt(i); passwordBytes[i*2]=(byte) (c>>8); passwordBytes[i*2+1]=(byte) c; } SHS hash = new SHS(); byte[] keyBytes = hash.digest (passwordBytes); return Crypt.bytesToLong(keyBytes,0);}/**Returns the next key from the digest*/public static long nextKeyFromPassword (String password) { byte[] passwordBytes = new byte[password.length()*2]; for (int i =0;i<password.length(); ++i) { char c=password.charAt(i); passwordBytes[i*2]=(byte)(c>>8); passwordBytes[i*2+1]=(byte) c; } SHS hash = new SHS(); byte[] keyBytes=hash.digest(passwordBytes); return Crypt.bytesToLong(keyBytes,8);}}/*end of class*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?