Thanks for this Jeremy,
actually for any code to be committed, I need a test that asserts the
behavior. Could you add what's needed to src/unittests/com/uwyn/rife/
tools/TestStringEncryptor.java and make sure the new assertions succeed.
Thanks,
Geert
On 16 Apr 2007, at 22:36, Jeremy Cowgar wrote:
Greetings!
I have a project that is accessing a user db that uses the common
MD5() function found in SQL servers like MySQL and PostgreSQL. It
appears as though RIFEs MD5 implementation gets the base64 of the
bytes returned by java's MessageDigest. I wrote up an encryption
method that is compatible with the hex strings returned by the MD5
() hex functions. Below is the diff that makes it all work. I
called the encryption method MD5HEX. I have tested it against MySQL
and Postgresql. It's working great in both of those instances.
Jeremy
Index: src/framework/com/uwyn/rife/tools/StringEncryptor.java
===================================================================
--- src/framework/com/uwyn/rife/tools/StringEncryptor.java
(revision 3717)
+++ src/framework/com/uwyn/rife/tools/StringEncryptor.java
(working copy)
@@ -17,18 +17,21 @@
{
public static final String IDENTIFIER_OBF = "OBF";
public static final String IDENTIFIER_MD5 = "MD5";
+ public static final String IDENTIFIER_MD5HEX = "MD5HEX";
public static final String IDENTIFIER_SHA = "SHA";
public static final String IDENTIFIER_WHIRLPOOL = "WRP";
private static final String PREFIX_SUFFIX = ":";
private static final String PREFIX_OBF = IDENTIFIER_OBF
+PREFIX_SUFFIX;
private static final String PREFIX_MD5 = IDENTIFIER_MD5
+PREFIX_SUFFIX;
+ private static final String PREFIX_MD5HEX =
IDENTIFIER_MD5HEX+PREFIX_SUFFIX;
private static final String PREFIX_SHA = IDENTIFIER_SHA
+PREFIX_SUFFIX;
private static final String PREFIX_WHIRLPOOL =
IDENTIFIER_WHIRLPOOL+PREFIX_SUFFIX;
public static final StringEncryptor OBF = new
StringEncryptor(PREFIX_OBF);
public static final StringEncryptor MD5 = new
StringEncryptor(PREFIX_MD5);
public static final StringEncryptor SHA = new
StringEncryptor(PREFIX_SHA);
+ public static final StringEncryptor MD5HEX = new
StringEncryptor(PREFIX_MD5HEX);
public static final StringEncryptor WHIRLPOOL = new
StringEncryptor(PREFIX_WHIRLPOOL);
private StringEncryptor(String identifier)
@@ -69,6 +72,18 @@
whirlpool.NESSIEfinalize(digest);
return PREFIX_WHIRLPOOL
+Base64.encodeToString(digest, false);
}
+ else if (value.startsWith(PREFIX_MD5HEX))
+ {
+ MessageDigest digest =
MessageDigest.getInstance("MD5");
+ digest.update(value.substring
(PREFIX_MD5HEX.length()).getBytes());
+ byte[] bytes = digest.digest();
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < bytes.length; ++i)
+ {
+ sb.append(Integer.toHexString((bytes[i] &
0xFF) | 0x100).substring(1, 3));
+ }
+ return PREFIX_MD5HEX+sb.toString();
+ }
else if (value.startsWith(PREFIX_MD5))
{
MessageDigest digest =
MessageDigest.getInstance("MD5");
@@ -108,6 +123,10 @@
{
clearValue = PREFIX_WHIRLPOOL+clearValue;
}
+ else if (encryptedValue.startsWith(PREFIX_MD5HEX))
+ {
+ clearValue = PREFIX_MD5HEX+clearValue;
+ }
else if (encryptedValue.startsWith(PREFIX_MD5))
{
clearValue = PREFIX_MD5+clearValue;
_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://lists.uwyn.com/mailman/listinfo/rife-users
--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Music and words - http://gbevin.com
_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://lists.uwyn.com/mailman/listinfo/rife-users