加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hmac_sha256_test.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2022-11-29 22:30 . 优化错误处理
package dongle
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
var hmacSha256Test = []struct {
input string
key string
toHex string
toBase64 string
}{
{"", "", "", ""},
{"hello world", "dongle", "77f5c8ce4147600543e70b12701e7b78b5b95172332ebbb06de65fcea7112179", "d/XIzkFHYAVD5wsScB57eLW5UXIzLruwbeZfzqcRIXk="},
}
func TestEncrypt_ByHmacSha225_ToString(t *testing.T) {
for index, test := range hmacSha256Test {
e := Encrypt.FromString(test.input).ByHmacSha256(test.key)
assert.Nil(t, e.Error)
assert.Equal(t, test.toHex, e.ToHexString(), "Hex test index is "+strconv.Itoa(index))
assert.Equal(t, test.toBase64, e.ToBase64String(), "Base64 test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_ByHmacSha225_ToBytes(t *testing.T) {
for index, test := range hmacSha256Test {
e := Encrypt.FromBytes([]byte(test.input)).ByHmacSha256([]byte(test.key))
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.toHex), e.ToHexBytes(), "Hex test test index is "+strconv.Itoa(index))
assert.Equal(t, []byte(test.toBase64), e.ToBase64Bytes(), "Base64 test index is "+strconv.Itoa(index))
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化