Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: OT: Is MD5 ALWAYS 32 character long?

by zakzebrowski (Curate)
on Dec 18, 2003 at 23:37 UTC ( #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 use Digest::MD5 qw (md5_hex); my $digest = Digest::MD5->new; $digest->add("Hi"); print length($digest->hexdigest);


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2020-07-06 13:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found