Computing SHA for use in CreateFile endpoint

I have a file whose contents are “from test” - 9 bytes. The documentation says that the SHA of created files is computed using SHA1:

> The file’s SHA-1 hash is computed and stored in the blob object.

(from https://developer.github.com/v3/git/blobs/)

However, when I compute the hex-encoded SHA1 output of “from test”, I get 5669556d9a5c27fdd649dcaaa0873757c2aa402f.

The Github API says that the sha is 62b551731eada762035d4665978027cd44291290 - this is the ETag returned and the value for “sha” in the API response for retrieving a file. In addition, when I call the CreateFile endpoint with “from test” as the value and 566955… as the sha, I’m told that the SHA is incorrect.

I’ve also tried appending newlines, computing the SHA of the base64 encoded value of the content, computing the SHA of base64+ a trailing newline, and none of them give me 62b551731eada762035d4665978027cd44291290. How is Github computing that value?

Thanks,

Kevin

GitHub uses git to calculate the SHA of the object. You can find the documentation of how this works on the git-scm.com website. Or you can use the git hash-object command:

$ echo -n "from test" | git hash-object --stdin
62b551731eada762035d4665978027cd44291290

I hope that helps!