mirror of
https://github.com/fumiama/aes-rsa-tcp-demo.git
synced 2026-06-28 07:50:26 +08:00
init
This commit is contained in:
27
utils/rsa_test.go
Normal file
27
utils/rsa_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRSA(t *testing.T) {
|
||||
testtext := []byte("test RSAPrivateKeyEncrypt")
|
||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
enc, err := RSAPrivateKeyEncrypt(priv, testtext)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dec, err := RSAPublicKeyDecrypt(&priv.PublicKey, enc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(testtext, dec) {
|
||||
t.Fatal("expected", string(testtext), "but got", string(dec))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user