Generate password hash in java as openssl passwd -1

Is there an easy way in Java to generate password hashes in the same way as the generated "openssl passwd -1".

Example:

# openssl passwd -1 test $1$Gt24/BL6$E4ZsrluohHFxtcdqCH7jo. 

I am looking for a pure Java solution that does not call openssl or any other external program.

Thanks Raffael

+4
source share
3 answers

The openssl docs describe option -1 as: "Use the BSD password algorithm based on MD5 1".

Jasypt is a java cryptogrqphy library like jBCrypt . Jasypt is a bit more complicated, but more customizable.

I don’t know much about cryptography, but I assume that the password generated by openssl breaks up like:
$1$ - indicates that this was generated using the MD5 scheme
Gt24/BL6 - 8 byte salt
$ - delimiter
E4ZsrluohHFxtcdqCH7jo. - hash

so it looks like Jasypt BasicPasswordEncryptor might be what you want -

+3
source

Perhaps something like this?

 MessageDigest md = null; md = MessageDigest.getInstance("SHA"); md.update(pPassword.getBytes("UTF-8")); byte raw[] = md.digest(); String hash = BASE64Encoder.encodeBuffer(raw); 

The Java source BASE64Encoder can be found on the net.

0
source

You can find the source code for the C version here . It should be simple to convert it to pure Java.

0
source

All Articles