You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
342 B

6 years ago
  1. package blockchainlib
  2. import (
  3. "crypto/sha256"
  4. "encoding/base64"
  5. "encoding/json"
  6. "log"
  7. )
  8. func HashBlock(b Block) string {
  9. blockJson, err := json.Marshal(b)
  10. if err != nil {
  11. log.Println(err)
  12. }
  13. blockString := string(blockJson)
  14. h := sha256.New()
  15. h.Write([]byte(blockString))
  16. return base64.URLEncoding.EncodeToString(h.Sum(nil))
  17. }