init
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
4299eb6949
@ -0,0 +1,11 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: clone
|
||||
|
||||
steps:
|
||||
- name: test-golang
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- go test -v ./...
|
@ -0,0 +1,7 @@
|
||||
.env
|
||||
.git
|
||||
.svn
|
||||
.idea
|
||||
.vscode
|
||||
*.log
|
||||
gitmod.sh
|
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 茂名聚合科技有限公司
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,25 @@
|
||||
<h1>
|
||||
<a href="https://www.dtapp.net/">Golang Md5</a>
|
||||
</h1>
|
||||
|
||||
📦 Golang 字符串组件
|
||||
|
||||
[comment]: <> (go)
|
||||
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gomd5?status.svg)](https://pkg.go.dev/go.dtapp.net/gomd5)
|
||||
[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gomd5/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gomd5)
|
||||
[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gomd5)](https://goreportcard.com/report/go.dtapp.net/gomd5)
|
||||
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net/gomd5)
|
||||
|
||||
#### 安装使用
|
||||
|
||||
```go
|
||||
go get -v -u go.dtapp.net/gomd5
|
||||
```
|
||||
|
||||
#### 导入
|
||||
|
||||
```go
|
||||
import (
|
||||
"go.dtapp.net/gomd5"
|
||||
)
|
||||
```
|
@ -0,0 +1,54 @@
|
||||
package gomd5
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Php(str string) string {
|
||||
h := md5.New()
|
||||
io.WriteString(h, str)
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
func Md5(str string) string {
|
||||
s := md5.New()
|
||||
s.Write([]byte(str))
|
||||
return hex.EncodeToString(s.Sum(nil))
|
||||
}
|
||||
|
||||
// ToUpper md5加密后转大写
|
||||
func ToUpper(str string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(str))
|
||||
cipherStr := h.Sum(nil)
|
||||
return strings.ToUpper(hex.EncodeToString(cipherStr))
|
||||
}
|
||||
|
||||
// ToLower md5加密后转小写
|
||||
func ToLower(str string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(str))
|
||||
cipherStr := h.Sum(nil)
|
||||
return strings.ToLower(hex.EncodeToString(cipherStr))
|
||||
}
|
||||
|
||||
// GetMD5Encode 返回一个32位md5加密后的字符串
|
||||
func GetMD5Encode(data string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// Get16MD5Encode 返回一个16位md5加密后的字符串
|
||||
func Get16MD5Encode(data string) string {
|
||||
return GetMD5Encode(data)[8:24]
|
||||
}
|
||||
|
||||
// Get16MD5EncodeToUpper 返回一个16位md5加密后的大写字符串
|
||||
func Get16MD5EncodeToUpper(data string) string {
|
||||
return strings.ToUpper(Get16MD5Encode(data))
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package gomd5
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMd5(t *testing.T) {
|
||||
t.Logf(GetMD5Encode("测试"))
|
||||
t.Logf(ToUpper(GetMD5Encode("测试")))
|
||||
t.Logf(ToUpper("测试"))
|
||||
}
|
||||
|
||||
func TestGet16MD5EncodeToUpper(t *testing.T) {
|
||||
t.Logf("A" + Get16MD5EncodeToUpper("10000,admin"))
|
||||
t.Logf("A" + Get16MD5EncodeToUpper("10001,agent"))
|
||||
t.Logf("A" + Get16MD5EncodeToUpper("10007,agent"))
|
||||
t.Logf("A" + Get16MD5EncodeToUpper("10008,agent"))
|
||||
t.Logf("A" + Get16MD5EncodeToUpper("10010,agent"))
|
||||
t.Logf("M" + Get16MD5EncodeToUpper("10011,merchant"))
|
||||
t.Logf("M" + Get16MD5EncodeToUpper("10015,merchant"))
|
||||
t.Logf("U" + Get16MD5EncodeToUpper("AE4E9C88A45813D4D,oojLm5Xv9iJ36WZGgJHooHcNyFGs,mini_user"))
|
||||
}
|
Loading…
Reference in new issue