封装的方法类
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package sha1x
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
func Sha1(s string) string {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(s))
|
||||
|
||||
bs := h.Sum(nil)
|
||||
return hex.EncodeToString(bs)
|
||||
|
||||
// return fmt.Sprintf("%x", bs)
|
||||
|
||||
// return res
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package sha1x_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
sha1x "yunink/app/pkg/encryptx/sha1x"
|
||||
)
|
||||
|
||||
func TestSha1(t *testing.T) {
|
||||
s := "sha1 this string"
|
||||
r := sha1x.Sha1(s)
|
||||
fmt.Println(r)
|
||||
}
|
||||
Reference in New Issue
Block a user