Java加解密工具 jBCrypt

jopen 12年前發布 | 55K 次閱讀 加解 安全相關

java版Bcrypt ,加解密工具 (用于賬號密碼加密,被時間檢證過了) 對用戶的口令進行Hash,并使用salt,以防止Rainbow 攻擊(Hash算法可用MD5或SHA1等,對口令使用salt的意思是,user 在設定密碼時,system 產生另外一個random string(salt)。在datbase 存的是與salt + passwd 產的md5sum 及salt。 當要驗證密碼時就把user 輸入的string 加上使用者的salt,產生md5sum 來比對。 理論上用salt 可以大幅度讓密碼更難破解,相同的密碼除非剛好salt 相同,最后存在database 上的內容是不一樣的。使用慢一點的Hash算法來保存口令,如 bcrypt (被時間檢證過了) 或是 scrypt (更強,但是也更新一些)

 

The API is very simple: 

// Hash a password for the first time 

String hashed = BCrypt.hashpw(password, BCrypt.gensalt()); 

// gensalt's log_rounds parameter determines the complexity 

// the work factor is 2**log_rounds, and the default is 10 

String hashed = BCrypt.hashpw(password, BCrypt.gensalt(12)); 

// Check that an unencrypted password matches one that has 

// previously been hashed 

if (BCrypt.checkpw(candidate, hashed)) 

 System.out.println("It matches"); 

else 

 System.out.println("It does not match");

項目主頁:http://www.baiduhome.net/lib/view/home/1348582343119

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!