--- /dev/null
+#!/usr/bin/perl -w\r
+\r
+# Apache $apr1$ to OpenLDAP {APR1} hash converter\r
+# (C) 2011 Devin J. Pohly\r
+# You may use this code freely. It would be nice to be credited.\r
+\r
+use MIME::Base64;\r
+\r
+while (<>) {\r
+ ($user, $hash) = split(/:/, $_);\r
+ unless ($hash =~ /^\$apr1\$/) {\r
+ print STDERR "Not an Apache MD5 hash\n";\r
+ exit 1;\r
+ }\r
+\r
+ chomp $hash;\r
+ ($_,$_,$salt,$hash) = split(/\$/, $hash);\r
+\r
+ $hash =~ tr|./0-9A-Za-z|A-Za-z0-9+/|;\r
+ $hash .= "AA";\r
+ $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;\r
+ $hash = decode_base64($hash);\r
+ $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)..(.)/$1$4$7$10$13$15$2$5$8$11$14$16$3$6$9$12/s;\r
+ $hash .= $salt;\r
+ $hash = encode_base64($hash);\r
+ chop $hash;\r
+\r
+ print "$user:{APR1}$hash\n";\r
+}
\ No newline at end of file
--- /dev/null
+#!/usr/bin/perl -w\r
+\r
+# OpenLDAP {APR1} to Apache $apr1$ hash converter\r
+# (C) 2011 Devin J. Pohly\r
+# You may use this code freely. It would be nice to be credited.\r
+\r
+use MIME::Base64;\r
+\r
+while (<>) {\r
+ ($user, $hash) = split(/:/, $_);\r
+ unless ($hash =~ /^{APR1}/) {\r
+ print STDERR "Not an Apache MD5 hash\n";\r
+ next;\r
+ }\r
+\r
+ chomp $hash;\r
+ $hash = decode_base64(substr($hash, 6));\r
+ ($hash, $salt) = (substr($hash, 0, 16), substr($hash, 16));\r
+ $hash = $hash;\r
+ $hash =~ s/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/$1$7$13$2$8$14$3$9$15$4$10$16$5$11$6\0\0$12/s;\r
+ $hash = encode_base64($hash);\r
+ chomp $hash;\r
+ $hash =~ s/(.)(.)(.)(.)/$4$3$2$1/gs;\r
+ unless ($hash =~ /AA$/) {\r
+ #print "Problem with hash\n";\r
+ next;\r
+ }\r
+ $hash =~ s/AA$//;\r
+ $hash =~ tr|A-Za-z0-9+/|./0-9A-Za-z|;\r
+ print "$user:\$apr1\$$salt\$$hash\n"\r
+}
\ No newline at end of file