26 lines
422 B
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()
|
|
}
|
|
}
|