1
0
mirror of https://github.com/fumiama/aes-rsa-tcp-demo.git synced 2026-06-28 07:50:26 +08:00
This commit is contained in:
源文雨
2023-12-29 16:29:41 +09:00
commit f79b275f42
13 changed files with 827 additions and 0 deletions

27
utils/rsa_test.go Normal file
View 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))
}
}