Last active
March 21, 2016 21:59
-
-
Save mundry/a3211c9b2037f55d5ab2 to your computer and use it in GitHub Desktop.
Go example of generating subresource integrity hashes (https://www.srihash.org).
This file contains 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 characters
package main | |
import ( | |
"crypto/sha256" | |
"crypto/sha512" | |
"encoding/base64" | |
"fmt" | |
"io/ioutil" | |
"log" | |
) | |
func main() { | |
b, err := ioutil.ReadFile("/path/to/file") | |
if err != nil { | |
log.Fatal(err) | |
} | |
dgst256 := sha256.Sum256(b) | |
fmt.Printf("sha256-%s\n", base64.StdEncoding.EncodeToString(dgst256[:])) | |
dgst384 := sha512.Sum384(b) | |
fmt.Printf("sha384-%s\n", base64.StdEncoding.EncodeToString(dgst384[:])) | |
dgst512 := sha512.Sum512(b) | |
fmt.Printf("sha512-%s\n", base64.StdEncoding.EncodeToString(dgst512[:])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment