github.com/xxf098/lite-proxy@v0.15.1-0.20230422081941-12c69f323218/transport/ssr/tools/crypto.go (about)

     1  package tools
     2  
     3  import (
     4  	"crypto/hmac"
     5  	"crypto/md5"
     6  	"crypto/sha1"
     7  )
     8  
     9  const HmacSHA1Len = 10
    10  
    11  func HmacMD5(key, data []byte) []byte {
    12  	hmacMD5 := hmac.New(md5.New, key)
    13  	hmacMD5.Write(data)
    14  	return hmacMD5.Sum(nil)
    15  }
    16  
    17  func HmacSHA1(key, data []byte) []byte {
    18  	hmacSHA1 := hmac.New(sha1.New, key)
    19  	hmacSHA1.Write(data)
    20  	return hmacSHA1.Sum(nil)
    21  }
    22  
    23  func MD5Sum(b []byte) []byte {
    24  	h := md5.New()
    25  	h.Write(b)
    26  	return h.Sum(nil)
    27  }
    28  
    29  func SHA1Sum(b []byte) []byte {
    30  	h := sha1.New()
    31  	h.Write(b)
    32  	return h.Sum(nil)
    33  }