-
-
Save sierrezinal/3a11c158449be370305d18a9df73340d to your computer and use it in GitHub Desktop.
Revisions
-
miguelmota revised this gist
Jun 5, 2019 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ package main import ( "crypto/sha256" "fmt" ) func main() { data := []byte("hello") hash := sha256.Sum256(data) fmt.Printf("%x", hash[:]) // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 } -
miguelmota revised this gist
Dec 17, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,8 @@ func TestNewSHA256(t *testing.T) { out string }{ {[]byte(""), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, {[]byte("abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"}, {[]byte("hello"), "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"}, } { t.Run(fmt.Sprintf("%v", i), func(t *testing.T) { result := NewSHA256(tt.in) -
miguelmota created this gist
Dec 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ package crypto import ( "crypto/sha256" ) // NewSHA256 ... func NewSHA256(data []byte) []byte { hash := sha256.Sum256(data) return hash[:] } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ package crypto import ( "encoding/hex" "fmt" "testing" ) func TestNewSHA256(t *testing.T) { for i, tt := range []struct { in []byte out string }{ {[]byte(""), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}, {[]byte("hello"), "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"}, {[]byte("abc"), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"}, } { t.Run(fmt.Sprintf("%v", i), func(t *testing.T) { result := NewSHA256(tt.in) if hex.EncodeToString(result) != tt.out { t.Errorf("want %v; got %v", tt.out, hex.EncodeToString(result)) } }) } }