File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed
Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -71,16 +71,19 @@ func (k *RsaKeyPair) GenKeyPair(size int) error {
7171
7272 if k .Format == PKCS8 {
7373 // PKCS8 format: Use generic headers
74- privateBytes , _ := x509 .MarshalPKCS8PrivateKey (key )
75- k .PrivateKey = pem .EncodeToMemory (& pem.Block {
76- Type : "PRIVATE KEY" ,
77- Bytes : privateBytes ,
78- })
79- publicBytes , _ := x509 .MarshalPKIXPublicKey (& key .PublicKey )
80- k .PublicKey = pem .EncodeToMemory (& pem.Block {
81- Type : "PUBLIC KEY" ,
82- Bytes : publicBytes ,
83- })
74+ if privateBytes , err := x509 .MarshalPKCS8PrivateKey (key ); err == nil {
75+ k .PrivateKey = pem .EncodeToMemory (& pem.Block {
76+ Type : "PRIVATE KEY" ,
77+ Bytes : privateBytes ,
78+ })
79+ }
80+
81+ if publicBytes , err := x509 .MarshalPKIXPublicKey (& key .PublicKey ); err == nil {
82+ k .PublicKey = pem .EncodeToMemory (& pem.Block {
83+ Type : "PUBLIC KEY" ,
84+ Bytes : publicBytes ,
85+ })
86+ }
8487 }
8588 return nil
8689}
You can’t perform that action at this time.
0 commit comments