| 140 | } |
| 141 | |
| 142 | func writeEncryptedPrivateKey(path string, privateKey *rsa.PrivateKey, password string) error { |
| 143 | file, err := os.Create(path) |
| 144 | if err != nil { |
| 145 | return fmt.Errorf("writeEncryptedPrivateKey: %w", err) |
| 146 | } |
| 147 | |
| 148 | block, err := x509.EncryptPEMBlock(rand.Reader, "CERTIFICATE", x509.MarshalPKCS1PrivateKey(privateKey), []byte(password), x509.PEMCipher3DES) |
| 149 | if err != nil { |
| 150 | return fmt.Errorf("writeEncryptedPrivateKey: %w", err) |
| 151 | } |
| 152 | |
| 153 | err = pem.Encode(file, block) |
| 154 | if err != nil { |
| 155 | return fmt.Errorf("writeEncryptedPrivateKey: %w", err) |
| 156 | } |
| 157 | |
| 158 | err = file.Close() |
| 159 | if err != nil { |
| 160 | return fmt.Errorf("writeEncryptedPrivateKey: %w", err) |
| 161 | } |
| 162 | |
| 163 | return nil |
| 164 | } |
| 165 | |
| 166 | func writeCertificate(path string, certBytes []byte) error { |
| 167 | file, err := os.Create(path) |