|
3 | 3 | // License: BSD 3-Clause License |
4 | 4 |
|
5 | 5 | // Package csr provides functionality for generating Certificate Signing Requests (CSRs) and private keys. |
| 6 | +// |
| 7 | +// The package exports a single function, [GenerateCSRAndPrivateKey], which generates an ECDSA private key |
| 8 | +// using the P-256 curve and creates a CSR template with the provided common name and Subject Alternative |
| 9 | +// Names (SANs). The CSR is signed using the private key and encoded in PEM format. The private key is also |
| 10 | +// encoded in PEM format. |
| 11 | +// |
| 12 | +// # Usage |
| 13 | +// |
| 14 | +// The [GenerateCSRAndPrivateKey] function takes the following parameters: |
| 15 | +// - commonName: The common name (domain name) for the certificate. |
| 16 | +// - dnsNames: A slice of Subject Alternative Names (SANs) for the certificate. |
| 17 | +// |
| 18 | +// The function returns the following: |
| 19 | +// - csrPEM: The generated CSR in PEM format. |
| 20 | +// - privateKeyPEM: The generated private key in PEM format. |
| 21 | +// - err: An error, if any occurred during the generation process. |
| 22 | +// |
| 23 | +// Example: |
| 24 | +// |
| 25 | +// commonName := "example.com" |
| 26 | +// dnsNames := []string{"www.example.com", "api.example.com"} |
| 27 | +// |
| 28 | +// csrPEM, privateKeyPEM, err := csr.GenerateCSRAndPrivateKey(commonName, dnsNames) |
| 29 | +// if err != nil { |
| 30 | +// log.Fatalf("Failed to generate CSR and private key: %v", err) |
| 31 | +// } |
| 32 | +// |
| 33 | +// // Save the CSR and private key to files |
| 34 | +// err = os.WriteFile("example.com.csr.pem", csrPEM, 0644) |
| 35 | +// if err != nil { |
| 36 | +// log.Fatalf("Failed to write CSR to file: %v", err) |
| 37 | +// } |
| 38 | +// |
| 39 | +// err = os.WriteFile("example.com.key.pem", privateKeyPEM, 0600) |
| 40 | +// if err != nil { |
| 41 | +// log.Fatalf("Failed to write private key to file: %v", err) |
| 42 | +// } |
6 | 43 | package csr |
0 commit comments