gitee.com/h79/goutils@v1.22.10/common/algorithm/md5.go (about)

     1  package algorithm
     2  
     3  import (
     4  	"crypto/md5"
     5  	"fmt"
     6  )
     7  
     8  // StringToMd5 string to md5
     9  // Deprecated: this function Md5String
    10  func StringToMd5(data string) string {
    11  	return fmt.Sprintf("%x", md5.Sum([]byte(data)))
    12  }
    13  
    14  // BytesToMd5 bytes to md5
    15  // Deprecated: this function Md5Bytes
    16  func BytesToMd5(data []byte) string {
    17  	return fmt.Sprintf("%x", md5.Sum(data))
    18  }
    19  
    20  func Md5String(data string) string {
    21  	return fmt.Sprintf("%x", md5.Sum([]byte(data)))
    22  }
    23  
    24  func Md5Bytes(data []byte) string {
    25  	return fmt.Sprintf("%x", md5.Sum(data))
    26  }