1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package myth
- import (
- "crypto/hmac"
- "crypto/md5"
- "crypto/sha1"
- "crypto/sha256"
- "crypto/sha512"
- "encoding/hex"
- )
- func SHA512(data []byte) ([]byte, error) {
- hash := sha512.New()
- _, err := hash.Write(data)
- if err != nil {
- return nil, err
- }
- return hash.Sum(nil), nil
- }
- func HmacSHA256(k, s []byte) ([]byte, error) {
- hash := hmac.New(sha256.New, k)
- _, err := hash.Write(s)
- if err != nil {
- return nil, err
- }
- return hash.Sum(nil), nil
- }
- func SHA256(data string) string {
- hash := sha256.New()
- hash.Write([]byte(data))
- return hex.EncodeToString(hash.Sum(nil))
- }
- func MD5(data string) string {
- hash := md5.New()
- hash.Write([]byte(data))
- return hex.EncodeToString(hash.Sum(nil))
- }
- func SHA1(data string) string {
- hash := sha1.New()
- hash.Write([]byte(data))
- return hex.EncodeToString(hash.Sum(nil))
- }
- func HmacSHA1(k, s []byte) ([]byte, error) {
- hash := hmac.New(sha1.New, k)
- _, err := hash.Write(s)
- if err != nil {
- return nil, err
- }
- return hash.Sum(nil), nil
- }
|