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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
lathspell42
  • 603
  • 3
  • 7
  • 11
  • Did you check that: http://stackoverflow.com/questions/3174943/java-implementation-of-crypt3 – home Jan 30 '12 at 11:02

3 Answers3

5

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

lathspell42
  • 603
  • 3
  • 7
  • 11
  • 1
    Meanwhile the Apache Commons Codec project has complete support for all Linux crypt() algorithms! – lathspell42 Oct 08 '12 at 17:47
  • I would appreciate a little info about where that link comes from. Downloading random jars can be a bad idea. – DonyorM Mar 07 '16 at 11:26
  • 2
    FYI the link is dead, and no `archive.org` version available. Do you have another source? – Luc Mar 06 '18 at 11:30
  • https://github.com/apache/commons-codec/blob/master/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java – Air2 Apr 18 '23 at 15:13
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.

Sergey Ponomarev
  • 2,947
  • 1
  • 33
  • 43
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

  • After some searching I found at least one implementation of the $6$ mechanism based on SHA-512: http://tools.arlut.utexas.edu/gash2/doc/javadoc/arlut/csd/crypto/Sha512Crypt.html – lathspell42 Feb 03 '12 at 18:40
  • `man 3 crypt` → "NOTES" → "Features in glibc" → `$5$` = SHA-256 (not SHA-1) – 3ED Sep 05 '18 at 15:33