Search code examples
javaopensslcryptographymd5salt-cryptography

How to get the same salted password in Java as by using openssl passwd?


What I need is to get the same result as:

# openssl passwd -1 -salt SaltSalt thesecretpassword
$1$SaltSalt$d4KyTrYpU26ghRyvibVDY0

At least the last part(d4KyTrYpU26ghRyvibVDY0), as the first two parts are fixed to $1$SaltSalt$.

This is needed, so it can be set for a password of a Linux user.


Solution

  • I found it in commons-codec:

    Crypt.crypt(password, String.format("$1$SaltSalt", "thesecretpassword"))