Skip to content

Commit

Permalink
feat: rsa pem wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
leafney committed Dec 17, 2024
1 parent e823919 commit aab4f8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@ func RsaDecryptByte(pemData []byte, cipherText string) ([]byte, error) {
}
return plainText, nil
}

// RsaPEMWrapper 为 PEM 数据增加关键字 `-----BEGIN PUBLIC KEY----- 和 -----END PUBLIC KEY-----`
func RsaPEMWrapper(pemStr string) string {
return fmt.Sprintf("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", pemStr)
}

func RsaPEMWrapperB(pemStr string) []byte {
return []byte(RsaPEMWrapper(pemStr))
}
2 changes: 2 additions & 0 deletions rsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ func TestRsaEncrypt(t *testing.T) {
// RSA解密
decrypt, _ := RsaDecryptByte(pri, string(encrypt))
t.Logf("decrypt [%v]", string(decrypt))

t.Logf("result [%v]", RsaPEMWrapper("hello"))
}

0 comments on commit aab4f8f

Please sign in to comment.