I have passwords hashed into 512 bits, how to store them in MySQL?
I have passwords hashed into 512 bits, how to store them in MySQL?
Initially I wanted BINARY(512)
However binary has fixed length 255.
I know I can use VARBINARY(512)
But since my data is "fixed" and not variable-length, i do not think this is the best solution and am looking for a b开发者_运维问答etter alternative.
From the page http://dev.mysql.com/doc/refman/5.0/en/blob.html:
In some cases, it may be desirable to store binary data such as media files in
BLOB
orTEXT
columns. You may find MySQL's string handling functions useful for working with such data.
So does that mean that there is another way to store binary data other than BLOB
?
Since 512-bit is 64-byte, you can use BINARY(64)
for that purpose. Please note that length for BINARY()
type is measured by bytes and not bits.
From MySQL Reference Manual:
The BINARY and VARBINARY types are similar to CHAR and VARCHAR, except that they contain binary strings rather than nonbinary strings. That is, they contain byte strings rather than character strings.
512 bits is 64 bytes so BINARY(64)
should do
512 bits is just 64 bytes. CHAR
(BINARY
) can hold up to 255.
I'd convert to HEX string and then store in VARCHAR.
精彩评论