List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:December 30 2002 5:27am
Subject:Re: Storing a SHA1 checksum
View as plain text  
At 0:14 -0500 12/30/02, Philip Mak wrote:
>On Sun, Dec 29, 2002 at 11:09:47PM -0600, Paul DuBois wrote:
>>  At 5:28 -0500 12/29/02, Philip Mak wrote:
>>  >sql, table
>>  >
>>  >I'm storing a SHA1 checksum as "varchar(20) binary" in my application.
>>
>>  Other people have addressed other aspects of your message, but I'm
>>  curious why you're using a VARCHAR(20), when SHA1() returns a 40-byte
>>  string.
>>  >
>>  >After running a test, it seems MySQL will strip trailing spaces from a
>>  >varchar column, even if it is binary! That means if the last character
>>  >of my SHA1 checksum happens to be a space, MySQL will corrupt it.
>>
>>  SHA1() returns a string of 40 hexadecimal digits.  There won't be trailing
>>  spaces.
>>
>>  Are you converting the hex string to some other representation before
>>  storing it?
>
>Yes, I'm converting it to a binary representation first, so that it
>only takes 20 bytes instead of 40 bytes.

Okay.  I see then why you might end up with trailing 'spaces'.

>
>I ended up using a TINYBLOB to store my checksum, since performance
>shouldn't be overly critical in my application.

Sounds like a good choice.
Thread
Storing a SHA1 checksumPhilip Mak29 Dec
  • Re: Storing a SHA1 checksumBenjamin Pflugmann29 Dec
    • RE: Storing a SHA1 checksumAdolfo Bello29 Dec
  • Re: Storing a SHA1 checksumiConnect \(Berlin\) Stefan Hinz29 Dec
  • Fatal errorPikasz Gyorgy29 Dec
    • Re: Fatal errorDoug Thompson29 Dec
      • Re: Fatal erroriConnect \(Berlin\) Stefan Hinz29 Dec
  • Re: Fatal errorLeVar Bery29 Dec
  • Re: Storing a SHA1 checksumPaul DuBois30 Dec
    • Re: Storing a SHA1 checksumPhilip Mak30 Dec
      • Re: Storing a SHA1 checksumPaul DuBois30 Dec