Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Jul 1, 2021
1 parent 5941d86 commit 597c644
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@ type RSA struct {
privateKey *RSAPrivateKey
}

func (r *RSA) SetPublicKey(publicKey []byte) (err error) {
func (r *RSA) SetPublicKeyBytes(publicKey []byte) (err error) {
r.publicKey, err = NewRSAPublicKey(publicKey)
return err
}

func (r *RSA) SetPublicKey(publicKey *RSAPublicKey) *RSA {
r.publicKey = publicKey
return r
}

func (r *RSA) PublicKey() *RSAPublicKey {
return r.publicKey
}

func (r *RSA) SetPrivateKey(privateKey []byte) (err error) {
func (r *RSA) SetPrivateKeyBytes(privateKey []byte) (err error) {
r.privateKey, err = NewRSAPrivateKey(privateKey)
return err
}

func (r *RSA) SetPrivateKey(privateKey *RSAPrivateKey) *RSA {
r.privateKey = privateKey
return r
}

func (r *RSA) PrivateKey() *RSAPrivateKey {
return r.privateKey
}
8 changes: 4 additions & 4 deletions rsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func Test_SetPrivateKey(t *testing.T) {
// 公钥加密私钥解密
func Test_PubENCTYPTPriDECRYPT(t *testing.T) {
a := NewRSA()
if err := a.SetPublicKey(testPubkey); err != nil {
if err := a.SetPublicKeyBytes(testPubkey); err != nil {
t.Error(err)
}
if err := a.SetPrivateKey(testPrivatekey); err != nil {
if err := a.SetPrivateKeyBytes(testPrivatekey); err != nil {
t.Error(err)
}
pubenctypt, err := a.PublicKey().Encrypt([]byte(`hello world`))
Expand All @@ -84,10 +84,10 @@ func Test_PubENCTYPTPriDECRYPT(t *testing.T) {
// 公钥解密私钥加密
func Test_PriENCTYPTPubDECRYPT(t *testing.T) {
a := NewRSA()
if err := a.SetPublicKey(testPubkey); err != nil {
if err := a.SetPublicKeyBytes(testPubkey); err != nil {
t.Error(err)
}
if err := a.SetPrivateKey(testPrivatekey); err != nil {
if err := a.SetPrivateKeyBytes(testPrivatekey); err != nil {
t.Error(err)
}
prienctypt, err := a.PrivateKey().Encrypt([]byte(`hello world`))
Expand Down

0 comments on commit 597c644

Please sign in to comment.