简体   繁体   中英

How to reproduce php Crypt() in java for custom sha256 rounds

I have a php script that store crypt() results with a custom rounds off 10000 and some already existing salt.

The code look like that :

echo crypt('rasmuslerdorf', '$5$rounds=10000$usesomesillystringforsalt$');

And the output is

$5$rounds=10000$usesomesillystri$CaVZTpnmHfz9Fi6zjGJmSAAwwABsSqSJbtzdlfvVC10

Witch is not a hash in hexa nor in binary, it seem to be a Crypt3 output.

Question is "How to get this same string for the same input in Java ?"

For now all MessageDigest & SO answers tested don't work, as it print directly the hash in hexa (aka lot of pain to compare).

Ok, finally able to find a way to get the same output.

Using the Apache Commons Crypt I get the same output with the salt round and everything.

import org.apache.commons.codec.digest.Crypt;
return Crypt.crypt("rasmuslerdorf", "$5$rounds=10000$usesomesillystringforsalt$");

Will get me my :

$5$rounds=10000$usesomesillystri$CaVZTpnmHfz9Fi6zjGJmSAAwwABsSqSJbtzdlfvVC10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM