Morin
Morin

Reputation: 237

ruby - Can I create a md5 hash of length 8?

Is it possible to create a md5 hash of 8 characters long?

Upvotes: 5

Views: 6754

Answers (4)

dcai
dcai

Reputation: 2555

length 8 string is not valid md5 hash.

Upvotes: 0

DarkDust
DarkDust

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

RyanScottLewis
RyanScottLewis

Reputation: 14046

require 'digest'

Digest::MD5.hexdigest("My secret")[0...8]

Upvotes: 8

Tjekkles
Tjekkles

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

Related Questions