PHP crypt(pass, salt) alternative in Java - Blowfish algorithm

*爱你&永不变心* 提交于 2019-12-06 08:59:19

问题


I'm using on php server function crypt like this:

$hash = crypt($password, '$2y$10$' . $salt);

It makes hash of password by Blowfish method.

I'm looking for java equivalent for crypt password.

I found this code, but I don't know where add $salt. More above:

String key = "abcd";
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(cipher.ENCRYPT_MODE, keySpec);
return DatatypeConverter.printBase64Binary(cipher.doFinal(key.getBytes()));

Thank's for every idea or answer.


回答1:


Not an answer to your question but maybe it helps:

There is the Apache Commons Codec library that contains a Linux crypt(3) compatible function for at least des,md5,sha256 and sha512 based crypt() algorithms in case you don't really need blowfish but just something stronger than the traditional DES based hashes (use sha512 then): http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/digest/Md5Crypt.java?view=markup

And there's other source code that implements the Blowfish algorithm but it's in C: http://doxygen.postgresql.org/crypt-blowfish_8c_source.html

As you can see crypt() uses algorithms that are only based on those encryption ciphers but pipes the input several thousant times through them to get a nice hash value.




回答2:


Now I did found some java implementations of crypt(3) with blowfish:

http://www.mindrot.org/projects/jBCrypt/ (last update 2010)

and

http://docs.spring.io/spring-security/site/docs/3.2.3.RELEASE/apidocs/org/springframework/security/crypto/bcrypt/BCrypt.html



来源:https://stackoverflow.com/questions/23570655/php-cryptpass-salt-alternative-in-java-blowfish-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!