How to create a hash like apache htpasswd using java

I use "force MD5 password encryption" in htpasswd to generate a hash, for example, "123", I get:

use htpasswd: 123 => $ apr1 $ kaTbKaLO $ ewJXRZAKpjaxK4thy2jOp /

use the MD5 digest: 123 => 202cb962ac59075b964b07152d234b70

please tell me how can I generate a hash, for example apache htpasswd using java Thank you.

+5
source share
4 answers

Passwords in Apache.htpasswd files are encoded using salt . If you want to generate these passwords using Java, you will need to do the same. This site contains an explanation of the salt / hash algorithm used for Apache.htpasswd files; I am looking for an actual algorithm that you could use, and edit my answer after I find it.

EDIT : it looks like this was asked earlier, right here on SO:

Htpasswd programming

Here's the documentation from Apache, as well as their source code:

http://httpd.apache.org/docs/2.2/misc/password_encryptions.html

http://svn.apache.org/viewvc/apr/apr-util/branches/1.3.x/crypto/apr_md5.c?view=co

+6
source

, - java . , ? , , 2007 , , 2010 .

" Java : , jonabbey@arlut.utexas.edu"

"MD5Crypt.java - FreeBSD Poul-Henning Kamp MD5-- Apache HTTP- ."

" '$ apr1 $<salt> $< hashed mess > '"

ftp://ftp.arlut.utexas.edu/pub/java_hashes/

+3

Md5Crypt is what you are looking for. It implements Apache htpasswd algorithms.

Apache-specific algorithm using a redesigned ( 1000 times ) MD5 digest of various combinations of random 32-bit salt and password .

import org.apache.commons.codec.digest.Md5Crypt;
...
String enPasswd = Md5Crypt.md5Crypt("your plain password".getBytes());
String htpasswdContent = "your username:" + enPasswd;
0
source

All Articles