Skip to content

Commit aab4f8f

Browse files
committed
feat: rsa pem wrapper
1 parent e823919 commit aab4f8f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

rsa.go

+9
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,12 @@ func RsaDecryptByte(pemData []byte, cipherText string) ([]byte, error) {
179179
}
180180
return plainText, nil
181181
}
182+
183+
// RsaPEMWrapper 为 PEM 数据增加关键字 `-----BEGIN PUBLIC KEY----- 和 -----END PUBLIC KEY-----`
184+
func RsaPEMWrapper(pemStr string) string {
185+
return fmt.Sprintf("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", pemStr)
186+
}
187+
188+
func RsaPEMWrapperB(pemStr string) []byte {
189+
return []byte(RsaPEMWrapper(pemStr))
190+
}

rsa_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ func TestRsaEncrypt(t *testing.T) {
2727
// RSA解密
2828
decrypt, _ := RsaDecryptByte(pri, string(encrypt))
2929
t.Logf("decrypt [%v]", string(decrypt))
30+
31+
t.Logf("result [%v]", RsaPEMWrapper("hello"))
3032
}

0 commit comments

Comments
 (0)