You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
starcrypto/crypt_test.go

26 lines
422 B
Go

package starcrypto
import (
"fmt"
"testing"
)
func TestRsaCrypt(t *testing.T) {
privKey, pubKey, err := GenerateKey(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()
}
}