2
0

md5.go 498 B

12345678910111213141516171819202122
  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/md5"
  7. "encoding/hex"
  8. )
  9. // MD5 encodes string to hexadecimal of MD5 checksum.
  10. func MD5(str string) string {
  11. return hex.EncodeToString(MD5Bytes(str))
  12. }
  13. // MD5Bytes encodes string to MD5 checksum.
  14. func MD5Bytes(str string) []byte {
  15. m := md5.New()
  16. _, _ = m.Write([]byte(str))
  17. return m.Sum(nil)
  18. }