Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: OT: Is MD5 ALWAYS 32 character long?

by zakzebrowski (Curate)
on Dec 18, 2003 at 23:37 UTC ( [id://315692]=note: print w/replies, xml ) Need Help??


in reply to OT: Is MD5 ALWAYS 32 character long?

Write a sample program using Digest::MD5. Looking at the manual, you will realize you basically have three options
  • md5 - produces a (non human readable) binary string 16 bytes long
  • md5hex - 32 bytes of hex
  • md5_base64 - a base 64 string
From that, you have to ask yourself, "self, do I want a base 64 string? Self, do I want a human readable 32 byte string? Self, do I want to go for storage and use a binary string?" Personally, because I don't like dealing with binary information, and I don't need a base 64 string, I would use the 32 byte hex string. I would then write a simple test program (below) which shows me the length of a string. (I could enhance it by taking an md5 checksum of the checksum itself, but that's left as an exercise to the user...) Also, I know from database classes that char storage when you have a fix length, is better than varchar storage for fixed length, I would use a char(32) for the column type. (Of course, the database may silently convert char to a varchar2 (like oracle) since the char size is large, but that's an implementation detail of the database system you use.)
Default@z ~ $ more test.pl use Digest::MD5 qw (md5_hex); my $digest = Digest::MD5->new; $digest->add("Hi"); print length($digest->hexdigest);


----
Zak

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315692]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-19 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found