cert

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadCertificateFromBytes

func ReadCertificateFromBytes(certData []byte) (*x509.Certificate, error)

ReadCertificateFromBytes reads a certificate from a byte string.

func ReadCertificateFromFile

func ReadCertificateFromFile(certPath string) (*x509.Certificate, error)

ReadCertificateFromFile reads a certificate from a file.

func WriteDefaultCertificate

func WriteDefaultCertificate(certPath string, privateKeyPath string) error

WriteDefaultCertificate writes a X.509 Certificate and RSA private key using default configuration.

Types

type CertificateBuilder

type CertificateBuilder interface {
	// SetRsa1024 sets to build certificate and private key using RSA-1024.
	SetRsa1024() CertificateBuilder
	// Set to build certificate and private key using RSA-2048.
	SetRsa2048() CertificateBuilder
	// Set to build certificate and private key using RSA-4096.
	SetRsa4096() CertificateBuilder
	// Set to build certificate and private key using ECDSA P-224 elliptical curve.
	SetEcdsaP224() CertificateBuilder
	// Set to build certificate and private key using ECDSA P-256 elliptical curve.
	SetEcdsaP256() CertificateBuilder
	// Set to build certificate and private key using ECDSA P-384 elliptical curve.
	SetEcdsaP384() CertificateBuilder
	// Set to build certificate and private key using ECDSA P-521 elliptical curve.
	SetEcdsaP521() CertificateBuilder
	// Set the duration (in days) for the generated certificate.
	SetValidDurationInDays(numDays int) CertificateBuilder
	// Set the start time that the certificate is valid. (default is now)
	SetStartValidTime(startTime time.Time) CertificateBuilder
	// Set the host names that the certificate is for.
	SetHostName(hostName string) CertificateBuilder
	// Set the certificate to be used as the certificate authority.
	SetUseSelfAsCertificateAuthority(useSelf bool) CertificateBuilder
	// Set the certificate organization.
	SetOrganization(organization string, unit string) CertificateBuilder
	// Sets the country of the certificate origin.
	SetCountry(country string) CertificateBuilder
	// Sets the locality (city) of the certificate origin.
	SetLocality(locality string) CertificateBuilder
	// Sets the province (state or providence) of the certificate origin.
	SetProvince(province string) CertificateBuilder
	// Gets the X.509 certificate in PEM format as a byte string.
	GetCertificate() ([]byte, error)
	// Gets the private key in PEM format as a byte string.
	GetPrivateKey() ([]byte, error)
	// Gets the X.509 certificate in PEM format as a string.
	GetCertificateString() (string, error)
	// Gets the private key in PEM format as a string.
	GetPrivateKeyString() (string, error)
	// Writes the X.509 certificate in PEM format to a file.
	WriteCertificate(path string) error
	// Gets the private key in PEM format to a file.
	WritePrivateKey(path string) error
}

CertificateBuilder creates X.509 certificates and private key pairs.

func NewCertificateBuilder

func NewCertificateBuilder() CertificateBuilder

NewCertificateBuilder creates a new Certificate Builder.

Example
certBuilder := NewCertificateBuilder().
	SetCountry("US").
	SetProvince("WA").
	SetLocality("Seattle").
	SetOrganization("Golang Test Runner", "development")
certData, _ := certBuilder.GetCertificate()
cert, _ := ReadCertificateFromBytes(certData)

fmt.Printf("%s", cert.Subject.Organization[0])
Output:

Golang Test Runner

Jump to

Keyboard shortcuts

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