starcrypto/crypt_test.go

35 lines
646 B
Go
Raw Normal View History

package starcrypto
import (
"fmt"
"testing"
)
func TestRsaCrypt(t *testing.T) {
2024-03-10 13:04:26 +08:00
privKey, pubKey, err := GenerateRsaKey(2048)
if err != nil {
panic(err)
}
data, err := RSAEncryptByPrivkey(privKey, []byte("hello world"))
if err != nil {
t.Fatal(err)
}
code, err := RSADecryptByPubkey(pubKey, data)
if err != nil {
t.Fatal(err)
}
fmt.Println(string(code))
if string(code) != "hello world" {
t.Fail()
}
}
2024-03-10 13:04:26 +08:00
func TestHmacSHA224(t *testing.T) {
key := []byte("hello world")
data := []byte("hello world")
code := HmacSHA224Str(key, data)
if "1414427f4b2889c3e86e637162c1add2bb888d1fc6c405d05fa5b66b" != code {
t.Fail()
}
}