2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 06:47:20 +08:00
Files
panel/pkg/rsacrypto/rsacrypto_test.go
2024-12-03 03:46:28 +08:00

40 lines
789 B
Go

package rsacrypto
import (
"testing"
"github.com/stretchr/testify/suite"
)
type RSATestSuite struct {
suite.Suite
}
func TestRSATestSuite(t *testing.T) {
suite.Run(t, &RSATestSuite{})
}
func (suite *RSATestSuite) TestRSA() {
// 生成RSA密钥对
privateKey, err := GenerateKey()
suite.NoError(err)
suite.NotEmpty(privateKey)
suite.NotEmpty(privateKey.PublicKey)
// 提取密钥对
suite.NotEmpty(PrivateKeyToString(privateKey))
suite.NotEmpty(PublicKeyToString(&privateKey.PublicKey))
message := []byte("Rat Panel")
// 加密数据
ciphertext, err := EncryptData(&privateKey.PublicKey, message)
suite.NoError(err)
suite.NotEmpty(ciphertext)
// 解密数据
decrypted, err := DecryptData(privateKey, ciphertext)
suite.NoError(err)
suite.NotEmpty(decrypted)
}