Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate a hash like apache's htpasswd using java

Tags:

java

.htpasswd

i use "Force MD5 encryption of the password" in htpasswd to generate a hash for instance '123' i get:

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

use MD5 digest: 123 => 202cb962ac59075b964b07152d234b70

please tell me how can i generate a hash like the apache htpasswd using java Thanks.

like image 779
robinmag Avatar asked Mar 18 '10 10:03

robinmag


People also ask

What is htpasswd hash?

This htpasswd generator creates passwords that are hashed using the MD5 algorithm, which means that you can use it for sites hosted on any platform, including Windows and Linux. You can also create htpasswd passwords with PHP on your own server – this technique only works on Linux though.

What encryption does htpasswd use?

htpasswd encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1, or the system's crypt() routine.


2 Answers

Passwords in Apache .htpasswd files are encoded using a salt. If you want to generate these passwords using Java you'll need to do the same. This site has an explanation of the salt/hashing algorithm used for Apache's .htpasswd files; I am looking for an actual algorithm you could use and will edit my answer after I find one.

EDIT: Looks like it's been asked before, right here on SO:

Programmaticly building htpasswd

Here's the documentation from Apache, along with 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

like image 117
Josh Avatar answered Oct 08 '22 19:10

Josh


I found where someone's tackled this in java & released it with a beer-ware license. Better late than never right? It's been there probably since 2007 so I'd be surprised if you hadn't eventually found it some time after asking in 2010.

"Java Port By: Jonathan Abbey, [email protected]"

"MD5Crypt.java is a port of Poul-Henning Kamp's original FreeBSD MD5-based hash algorithm, with additional methods to support the Apache HTTPd server variant of this algorithm."

"The resulting string will be in the form '$apr1$<salt>$<hashed mess>'"

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

like image 25
jejese Avatar answered Oct 08 '22 17:10

jejese