Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadCertificateFromBytes ¶
func ReadCertificateFromBytes(certData []byte) (*x509.Certificate, error)
Reads a certificate from a byte string.
func ReadCertificateFromFile ¶
func ReadCertificateFromFile(certPath string) (*x509.Certificate, error)
Reads a certificate from a file.
func WriteDefaultCertificate ¶
Writes a X.509 Certificate and RSA private key using default configuration.
Types ¶
type CertificateBuilder ¶
type CertificateBuilder interface { // Set 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 }
Creates X.509 certificates and private key pairs.
func NewCertificateBuilder ¶
func NewCertificateBuilder() CertificateBuilder
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
Click to show internal directories.
Click to hide internal directories.