sha.go 599 B

12345678910111213141516171819202122232425
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cryptoutil
  5. import (
  6. "crypto/sha1"
  7. "crypto/sha256"
  8. "encoding/hex"
  9. )
  10. // SHA1 encodes string to hexadecimal of SHA1 checksum.
  11. func SHA1(str string) string {
  12. h := sha1.New()
  13. _, _ = h.Write([]byte(str))
  14. return hex.EncodeToString(h.Sum(nil))
  15. }
  16. // SHA256 encodes string to hexadecimal of SHA256 checksum.
  17. func SHA256(str string) string {
  18. h := sha256.New()
  19. _, _ = h.Write([]byte(str))
  20. return hex.EncodeToString(h.Sum(nil))
  21. }