I am trying to create base64 encoded sha1 encoding in go, but the result I get is very different from the results of other programming languages.
package main
import (
"crypto/sha1"
"encoding/base64"
"fmt"
)
func main() {
c := sha1.New()
input := []byte("hello")
myBytes := c.Sum(input)
fmt.Println(base64.StdEncoding.EncodeToString(base64.StdPadding))
}
This Go code outputs aGVsbG/aOaPuXmtLDTJVv++VYBiQr9gHCQ==
My Python code is as follows
import hashlib
import base64
print(base64.b64encode(hashlib.sha1('hello').digest()))
And exits qvTGHdzF6KLavt4PO0gs2a6pQ00=
My bash command for comparison looks like this:
echo -n hello| openssl dgst -sha1 -binary |base64
And displays this qvTGHdzF6KLavt4PO0gs2a6pQ00=
Which allows me to assume that python code is doing everything right. But why is a different result imprinted. Where is my mistake?
Thnx in advance
source
share