mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 06:47:20 +08:00
40 lines
788 B
Go
40 lines
788 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("AcePanel")
|
|
|
|
// 加密数据
|
|
ciphertext, err := EncryptData(&privateKey.PublicKey, message)
|
|
suite.NoError(err)
|
|
suite.NotEmpty(ciphertext)
|
|
|
|
// 解密数据
|
|
decrypted, err := DecryptData(privateKey, ciphertext)
|
|
suite.NoError(err)
|
|
suite.NotEmpty(decrypted)
|
|
}
|