crypt(3) $6$ password hash algorithm (based on SHA-512) in Java?
Asked Answered
M

3

7

I'm looking for a Java function to generate/verify password hashes that were encoded in the way crypt(3) does when storing them in the Linux "/etc/shadow" file if sha512 is activated in "/etc/pam.d/common-password".

The plaintext string "geheim" will translate to:

"$6$WoC532HB$LagBJ00vAGNGu8p9oeYDOSNZo9vTNTzOgPA.K0bJoiXfbcpj3jBuTkNwdzCrSNadRi8LanH1tH6tGGPPp/Lp3."

From http://www.akkadia.org/drepper/SHA-crypt.txt I understand that, like with MD5, it's not just a SHA hash like DigestUtils or the Java MessageDigest classes produce but an algorithm that does a bit more magic.

Myrtismyrtle answered 30/1, 2012 at 10:54 Comment(1)
Did you check that: #3175443Builtin
M
5

I found Java implementations for all the new crypt() algorithms here: ftp://ftp.arlut.utexas.edu/java_hashes/

Myrtismyrtle answered 8/2, 2012 at 13:45 Comment(4)
Meanwhile the Apache Commons Codec project has complete support for all Linux crypt() algorithms!Myrtismyrtle
I would appreciate a little info about where that link comes from. Downloading random jars can be a bad idea.Carroty
FYI the link is dead, and no archive.org version available. Do you have another source?Hygrometer
github.com/apache/commons-codec/blob/master/src/main/java/org/…Mutual
C
3

Take a look on Apache Commons Codec Digest

Also jBCrypt you may find useful.

In this article Modular Crypt Format or, a side note about a standard that isn’t a lot of details of Crypt3 format.

Catling answered 7/3, 2016 at 11:16 Comment(0)
D
0

The othe question you refer to only provides links to the traditional crypt(3) method based on DES and the "$1$" method based on MD5. I need to check passwords that use the "$5$" method that is based on SHA-1 or even the "$6$" method that is based on SHA-512.

Based here means that crypt(3) uses e.g. SHA-512 but adds a salt value and does several iterations as described on http://www.akkadia.org/drepper/SHA-crypt.txt

Deference answered 3/2, 2012 at 17:47 Comment(2)
After some searching I found at least one implementation of the $6$ mechanism based on SHA-512: tools.arlut.utexas.edu/gash2/doc/javadoc/arlut/csd/crypto/…Myrtismyrtle
man 3 crypt → "NOTES" → "Features in glibc" → $5$ = SHA-256 (not SHA-1)Barrier

© 2022 - 2024 — McMap. All rights reserved.