csr

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package csr provides functionality for generating Certificate Signing Requests (CSRs) and private keys.

The package exports a single function, GenerateCSRAndPrivateKey, which generates an ECDSA private key using the P-256 curve and creates a CSR template with the provided common name and Subject Alternative Names (SANs). The CSR is signed using the private key and encoded in PEM format. The private key is also encoded in PEM format.

Usage

The GenerateCSRAndPrivateKey function takes the following parameters:

  • commonName: The common name (domain name) for the certificate.
  • dnsNames: A slice of Subject Alternative Names (SANs) for the certificate.

The function returns the following:

  • csrPEM: The generated CSR in PEM format.
  • privateKeyPEM: The generated private key in PEM format.
  • err: An error, if any occurred during the generation process.

Example:

commonName := "example.com"
dnsNames := []string{"www.example.com", "api.example.com"}

csrPEM, privateKeyPEM, err := csr.GenerateCSRAndPrivateKey(commonName, dnsNames)
if err != nil {
    log.Fatalf("Failed to generate CSR and private key: %v", err)
}

// Save the CSR and private key to files
err = os.WriteFile("example.com.csr.pem", csrPEM, 0644)
if err != nil {
    log.Fatalf("Failed to write CSR to file: %v", err)
}

err = os.WriteFile("example.com.key.pem", privateKeyPEM, 0600)
if err != nil {
    log.Fatalf("Failed to write private key to file: %v", err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCSRAndPrivateKey

func GenerateCSRAndPrivateKey(commonName string, dnsNames []string) (csrPEM, privateKeyPEM []byte, err error)

GenerateCSRAndPrivateKey generates a Certificate Signing Request (CSR) and a private key.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL