Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

binary password in SQL??

Thread view: 
timasmith@hotmail.com - 29 Apr 2006 05:14 GMT
Hi,

I used this function to convert the password to a hashe value

   public static byte[] getKeyedDigest(byte[] buffer, byte[] key)
throws NoSuchAlgorithmException {
       MessageDigest md5 = MessageDigest.getInstance("MD5");
       md5.update(buffer);
       return md5.digest(key);
   }

But the output was completely invalid to use for SQL to save in a field

?ª4úø...¦ÁœIÃÑäjÈ

Without doing a binary save - how can I easily convert the output to
regular ascii?

thanks

Tim
Roland de Ruiter - 29 Apr 2006 10:38 GMT
> Hi,
>
[quoted text clipped - 17 lines]
>
> Tim

Convert the byte array (IIRC 16 bytes for MD5) to a hexadecimal String
representation (2 characters for each byte: 32 in total for MD5)

byte[] md5sum = getKeyedDigest(yourBuffer, yourKey);
StringBuffer buf = new StringBuffer(2 * md5sum.length);
for (int i = 0; i < md5sum.length; i++ {
    // convert signed byte to its "unsigned" integer value
    int byte_i = md5sum[i] & 0x000000ff;
    // convert i'th byte to hexadecimal string repr
    String hex = Integer.toHexString(byte_i);
    // add leading 0 if i'th byte was less than 16.
    if (hex.length() == 1) {
        buf.append('0'); // add leading 0
    } /* else {
        // otherwise hex repr of the i'th byte consists of 2 chars
        assert hex.length() == 2
    } */
    buf.append(hex);
}
String md5sumRepr = buf.toString();
return md5sumRepr;
--
Regards,

Roland
timasmith@hotmail.com - 29 Apr 2006 14:37 GMT
awesome thanks
Aki Tuomi - 29 Apr 2006 11:08 GMT
timasmith@hotmail.com kirjoitti:
> Hi,
>
[quoted text clipped - 17 lines]
>
> Tim

There is no reason why you coulnd't save binary data in SQL database.
Unless of course you are using some DBM or database that does not
support binary data at all. There is a reason for VARBINARY and BLOB
data types. =)

Aki


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.