service/library/mycrypto/md5Crypto.go

26 lines
518 B
Go
Raw Normal View History

2024-09-25 13:13:35 +08:00
package mycrypto
import (
"crypto/md5"
"fmt"
)
type Md5Crypto struct{}
func NewMd5Crypto() (md5Crypto *Md5Crypto) {
return &Md5Crypto{}
}
func (rsaCrypto *Md5Crypto) Encrypt(msg []byte) (encryptedBytes []byte, err error) {
hash := md5.Sum(msg)
encryptedString := fmt.Sprintf("%x", hash)
encryptedBytes = []byte(encryptedString)
return
}
func (rsaCrypto *Md5Crypto) EncryptToString(msg []byte) (encryptedString string, err error) {
hash := md5.Sum(msg)
encryptedString = fmt.Sprintf("%x", hash)
return
}