Dave
Dave

Reputation: 73

Can MySQL (Windows) do SHA-256 and HMAC hashing?

Long time reader, first time poster. And I start with quite a cryptic one!

What I'm seeking to do is encrypt a string with the SHA-256 algorithm, and hash it with a key.

I discovered someone had done some excellent work in creating an algorithm for "normal" SHA-2 encryption as a stored function at: http://blog.darkrainfall.org/sha-256-in-mysql/ which will probably be of help to others, but I need to be able to do it with a key.

Anyone know if this is possible? I'm a completely newbie to encryption I'm afraid.

I'm using mySQL 5.1 on Windows 2003 server.

Cheers.

Upvotes: 7

Views: 3086

Answers (1)

Mark Wilkins
Mark Wilkins

Reputation: 41232

It is a little unclear what your end goal is, but the SHA implementation you referenced should be able to do the hashing you desired. One meaning of "hashing something with a key" for message authentication might be that you take a secret key and prepend it to data and then hash the entire result. The ever-useful Wikipedia has some information on HMAC.

Note that hashing is not encryption. The question seems to imply that hashing something is the same as encrypting it. A hash, though, takes some data and runs it through a data blender and produces a (typically) fixed length chunk of data. With a cryptographically strong hash function, it is supposed to be impossible (from a practical standpoint) to find an input that results in a given hash value. Encryption, on the other hand, takes a key and a chunk of data and runs i through a data blender and produces a chunk of data that can then be "unblended" in conjunction with the original key to produce the original data.

Upvotes: 2

Related Questions