0

I was just asking myself if this is standard, because I was setting a column to Type "Char 40" to store a SHA1 value. Is this true? or do I have to pay more attention when I do this in case I work with other then my own mysql database.

Thanks

EDIT

the best possible answer is, that SHA1 just works that way. I thought it was returning 160 bits and some other config setting converted it into a 40 char string, but it always returns that 40 digit string. see doc

Richard
  • 4,516
  • 11
  • 60
  • 87
  • 1
    `CHAR` in MySQL is a string type. You can store any string characters in there. It doesn't matter if it's hex or not. `CHAR` isn't "hex-encoded". – gen_Eric Sep 18 '13 at 15:52
  • a better question would be, why is sha1 always 40 characters long? yes, it's always stored like that , because a char is represented by a 4 bit, but why? – Richard Sep 18 '13 at 15:53
  • Because that's how it works. http://en.wikipedia.org/wiki/SHA-1 – gen_Eric Sep 18 '13 at 15:53
  • Using `CHAR(40)` to store your SHA1 hashes is fine, if that's what you're asking. – gen_Eric Sep 18 '13 at 15:54
  • I just found this, it might help you more than I can: http://stackoverflow.com/a/614483 – gen_Eric Sep 18 '13 at 15:57
  • That post was actually the reason I started to think about it, I just need to know why a char is 4 bit, but thanks for the input – Richard Sep 18 '13 at 15:59

1 Answers1

1

SHA1 returns 40 characters, yes.

tkrajcar
  • 1,702
  • 1
  • 17
  • 34