| 118 | } |
| 119 | |
| 120 | func writePrivateKey(path string, privateKey *rsa.PrivateKey) error { |
| 121 | file, err := os.Create(path) |
| 122 | if err != nil { |
| 123 | return fmt.Errorf("writePrivateKey: %w", err) |
| 124 | } |
| 125 | |
| 126 | err = pem.Encode(file, &pem.Block{ |
| 127 | Type: "RSA PRIVATE KEY", |
| 128 | Bytes: x509.MarshalPKCS1PrivateKey(privateKey), |
| 129 | }) |
| 130 | if err != nil { |
| 131 | return fmt.Errorf("writePrivateKey: %w", err) |
| 132 | } |
| 133 | |
| 134 | err = file.Close() |
| 135 | if err != nil { |
| 136 | return fmt.Errorf("writePrivateKey: %w", err) |
| 137 | } |
| 138 | |
| 139 | return nil |
| 140 | } |
| 141 | |
| 142 | func writeEncryptedPrivateKey(path string, privateKey *rsa.PrivateKey, password string) error { |
| 143 | file, err := os.Create(path) |