MCPcopy
hub / github.com/jackc/pgx / writeEncryptedPrivateKey

Function writeEncryptedPrivateKey

testsetup/generate_certs.go:142–164  ·  view source on GitHub ↗
(path string, privateKey *rsa.PrivateKey, password string)

Source from the content-addressed store, hash-verified

140}
141
142func 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
166func writeCertificate(path string, certBytes []byte) error {
167 file, err := os.Create(path)

Callers 1

mainFunction · 0.85

Calls 3

CreateMethod · 0.80
EncodeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected