BcryptCheck.java 544 B

12345678910111213141516
  1. package tools;
  2. import org.springframework.security.crypto.bcrypt.BCrypt;
  3. /**
  4. * 验证 Java BCrypt 能否校验 PHP password_hash() 生成的 $2y$ 口令。
  5. * 用法: java -cp "target/classes;<m2>/spring-security-crypto-*.jar" BcryptCheck.java <明文> <hash>
  6. */
  7. public class BcryptCheck {
  8. public static void main(String[] args) {
  9. String raw = args[0];
  10. String hash = args[1];
  11. System.out.println("hash prefix: " + hash.substring(0, 7));
  12. System.out.println("result: " + BCrypt.checkpw(raw, hash));
  13. }
  14. }