minzchickenflavor minzchickenflavor - 1 year ago 122
Python Question

sha1 different in go than in python and openssl

I am trying to build a base64 encoded sha1 hash in go but the result i am getting is very different to the results of other programming languages

package main

import (

func main() {
c := sha1.New()
input := []byte("hello")
myBytes := c.Sum(input)

This Go Code prints out

My Python Code Looks like this

import hashlib
import base64


And outputs

My bash command for comparison looks like this

echo -n hello| openssl dgst -sha1 -binary |base64

And outputs this

Which lets me assume that the python code is doing everything correct.
But why does go prints another result.
Where is my mistake?

Thnx in advance

Answer Source

There is an example of how to use it properly. You should do:

c := sha1.New()
io.WriteString(c, "hello")
myBytes := c.Sum(nil)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download