MySQL Forums
Forum List  »  Security

Re: Can't store md5 string in varchar
Posted by: Arjen Lentz
Date: February 24, 2005 08:29PM

Joel Schuster wrote:
> Howdy! I'm placing an md5 encrypted string created via the java.security.MessageDigest and "MD5"
> algorithm in a varchar(16) field.

> When I retrieve it out and compare it against the same string newly created they are not the same.
> When I look at the string retrieved from the database some of the odd characters are now
> converted to something else.
>
> Suggestions?

Well, MD5 is a 128-bit signature.
That amounts to 16 bytes, or for a human and ASCII readable hex string it's 32 bytes.

From the above, I gander that you want to insert the binary 16 bytes rather than a string.
That's fine, but then you need to take proper care when inserting. Use mysql_escape_string().

I'd also make the field CHAR(16) BINARY as it will never be less than 16 bytes, and BINARY just to remind you, but this should have no bearing on the prob. The above info will solve that bit.

Regards, Arjen.
--
Arjen Lentz, Exec.Director @ Open Query (http://openquery.com)
Remote expertise & maintenance for MySQL/MariaDB server environments.

Follow us at http://openquery.com/blog/ & http://twitter.com/openquery

Options: ReplyQuote


Subject
Views
Written By
Posted
8030
February 24, 2005 09:58AM
Re: Can't store md5 string in varchar
6433
February 24, 2005 08:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.