Skip to content
pikachule edited this page Aug 29, 2017 · 1 revision
package main

import (
	"crypto/sha1"
	"encoding/hex"
	"fmt"
)

func main() {
	s := "hello world1"
	h := sha1.New()
	h.Write([]byte(s))
	sha1_hash := hex.EncodeToString(h.Sum(nil))
	fmt.Println(s, sha1_hash)
}

package main

import (
	"crypto/sha1"
	"encoding/hex"
	"fmt"
	"io"
	"os"
)

func main() {
	file, err := os.Open("test.txt")
	if err != nil {
		return
	}
	defer file.Close()
	h := sha1.New()
	_, erro := io.Copy(h, file)
	if erro != nil {
		return
	}
	sha1_hash := hex.EncodeToString(h.Sum(nil))
	fmt.Println(sha1_hash)
}

Clone this wiki locally