MySQL Forums
Forum List  »  Newbie

Re: SHA-256 which data type is the best?
Posted by: Rick James
Date: October 02, 2011 11:03AM

Plan A: Hex representation:
BINARY(64)

Plan B: Binary representation:
BINARY(32)
This has the complication of storing binary values. Use some escaping mechanism (see your language specifics) for INSERTing.
Drawback: SELECT * (etc) would produce gibberish. Workaround: SELECT HEX(sha_col)...
Advantage: This is the most compact.

Plan C: Base64
BINARY(43)
Some languages make it easy to build a base-64 string. Note: there will be upper and lower case letters, so case folding is a no-no.
This one is a compromise between human-readable and compact.

Why "BINARY"? You don't need utf8 collation, etc, so BINARY instead of CHAR. The size does not vary, so not VAR. Add NULL or NOT NULL as needed.

Plan D: Use MD5 instead; it is unique enough. BINARY(16/22/32)

Options: ReplyQuote


Subject
Written By
Posted
Re: SHA-256 which data type is the best?
October 02, 2011 11:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.