gf/crypto/gcrc32/gcrc32_test.go

34 lines
824 B
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2019-04-05 17:11:03 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// go test *.go -bench=".*"
package gcrc32_test
import (
"testing"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/crypto/gcrc32"
"github.com/gogf/gf/crypto/gmd5"
"github.com/gogf/gf/test/gtest"
2019-04-05 17:11:03 +08:00
)
2019-06-10 15:05:11 +08:00
func TestEncrypt(t *testing.T) {
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-10 15:05:11 +08:00
s := "pibigstar"
result := 693191136
encrypt1 := gcrc32.Encrypt(s)
encrypt2 := gcrc32.Encrypt([]byte(s))
2020-03-19 22:56:12 +08:00
t.AssertEQ(int(encrypt1), result)
t.AssertEQ(int(encrypt2), result)
2019-06-10 15:55:43 +08:00
2019-06-21 22:23:07 +08:00
strmd5, _ := gmd5.Encrypt(s)
2019-06-10 15:55:43 +08:00
test1 := gcrc32.Encrypt(strmd5)
test2 := gcrc32.Encrypt([]byte(strmd5))
2020-03-19 22:56:12 +08:00
t.AssertEQ(test2, test1)
2019-06-10 15:05:11 +08:00
})
}