Reputation: 237
Is it possible to create a md5 hash of 8 characters long?
Upvotes: 5
Views: 6754
Reputation: 92404
MD5 creates 16-byte hashes. You can of course crop the string to eight characters, as with myString[0..7]
, but note that this not a valid MD5 hash any more.
Upvotes: 9
Reputation: 14046
require 'digest'
Digest::MD5.hexdigest("My secret")[0...8]
Upvotes: 8
Reputation: 5622
I think md5 has a generic length depending of what it's encrypting, so you can't pre define the length of the md5 hash.
Upvotes: 2