I am trying to encrypt SHA-1 the following string:
commit 218\0tree 64a7513fad0b86d34b6feedbf9c2e99135819861 parent 233634213baf3f40236233f28c6646f20786a80a author CTF user <me@example.com> 1390678027 +0000 committer CTF user <me@example.com> 1390678027 +0000 Give me a Gitcoin 200
It is a git hash-object
input, with the header along with the commit message. The results I am getting are very different from one method to the other.
Using git hash-object, I get bed6b1001619ad84548d05db65a75ac80bf79f31
.
Using Ruby's digest/sha1
, I get e729e36abf0fa4da392b8f2acc1561ec5d298af9
.
Using http://www.sha1-online.com, I get d543ddbfb7607464f5f964b9a3536eccedd1e1a4
.
This is extremely confusing. Which one is it and why am I unable to mimic git-hash-object
's functionality? I read http://git-scm.com/book/en/Git-Internals-Git-Objects and followed the instructions there but I cannot seem to get the right hash digest.
Here is my ruby snippet:
Digest::SHA1.hexdigest "commit #{body.length}\0#{body}"
Is there a way in git to see the hash-object header, or the string it uses to hash out the SHA-1? What is wrong with my method above?