github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/security/sha256/sha256.go (about)

     1  package sha256
     2  
     3  import (
     4  	"crypto/sha256"
     5  	"fmt"
     6  )
     7  
     8  // Encrypt sha256加密
     9  func Encrypt(content string) string {
    10  	h := sha256.New()
    11  	h.Write([]byte(content))
    12  	bs := h.Sum(nil)
    13  	return fmt.Sprintf("%x", bs)
    14  }
    15  
    16  //EncryptBytes bytes加密
    17  func EncryptBytes(content []byte) []byte {
    18  	h := sha256.New()
    19  	h.Write(content)
    20  	return h.Sum(nil)
    21  }