madcrazydrumma
madcrazydrumma

Reputation: 1897

Computing a (Non-MD5) 128 bit hash with salt

So for a piece of code I am writing, I want to create a 128 bit hash - like the one in the MurmurHash3 library (https://pypi.python.org/pypi/mmh3/2.5.1)

Note: I also want to add a salt to the hash which I already have as a string

I was looking around and it was suggested to truncate a SHA256 hash to 128 bits, but is there a way to get SHA256 using Crystal?

I know it supports MD5 and SHA1 in its libraries, but could I even use the OpenSSL library in the code? Would this require the OS to be running OpenSSL?

EDIT:

There is an OpenSSL::Digest module in Crystal (https://crystal-lang.org/api/0.24.1/OpenSSL/Digest.html) but how can I generate a hash to eventually be truncated to 128 bits

Upvotes: 0

Views: 161

Answers (1)

Jason Waldrip
Jason Waldrip

Reputation: 5148

You CAN use the OpenSSL module to generate a SHA256 digest, or any other algorithm supported by OpenSSL. Unfortunately, I would not suggest truncating as that is not an accurate representation of a true hash and has a higher chance of collision. Have you thought about porting murmur to Crystal, I am sure many people would love to see the library. My other suggestion is to just use 256 bits as its more secure anyway.

Upvotes: 1

Related Questions