gracex509

package
v0.0.0-...-1486261 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultCountry            = "CN"
	DefaultOrganization       = "guoyk93.github.io"
	DefaultExpires            = time.Hour * 24 * 365 * 30
	DefaultPublicKeyAlgorithm = x509.RSA
)
View Source
const (
	PEMTypeCertificate   = "CERTIFICATE"
	PEMTypeRSAPrivateKey = "RSA PRIVATE KEY"
	PEMTypePrivateKey    = "PRIVATE KEY"
)

Variables

This section is empty.

Functions

func CreateCertificatePEM

func CreateCertificatePEM(template, parent *x509.Certificate, pub any, priv any) (crt *x509.Certificate, crtPEM []byte, err error)

CreateCertificatePEM create certificate with PEM output

func GeneratePrivateKeyPEM

func GeneratePrivateKeyPEM(alg x509.PublicKeyAlgorithm) (key crypto.Signer, keyPEM []byte, err error)

GeneratePrivateKeyPEM generate a private key with PEM output in PKCS8 format

Types

type GenerateOptions

type GenerateOptions struct {
	// Parent certificate of parent, required when IsCA is false
	Parent PEMPair
	// IsCA whether to generate a IsCA certificate
	IsCA bool
	// PublicKeyAlgorithm x509 public key algorithm, default to RSA
	PublicKeyAlgorithm x509.PublicKeyAlgorithm
	// Names certificate names, tailing names will be used as DNSNames
	Names []string
	// Country certificate country
	Country string
	// Organization certificate organization
	Organization string
	// Expires certificate duration
	Expires time.Duration
}

GenerateOptions options for certificate generation

type PEMPair

type PEMPair struct {
	Crt []byte
	Key []byte
}

PEMPair PEM encoded x509 key pair

func Generate

func Generate(opts GenerateOptions) (res PEMPair, err error)

Generate easily generate a certificate with RSA private key if both ParentCrtPEM and CAKeyPem is missing, will generate a new IsCA

func (PEMPair) Certificate

func (b PEMPair) Certificate() (crt *x509.Certificate, err error)

func (PEMPair) Decode

func (b PEMPair) Decode() (crt *x509.Certificate, key any, err error)

func (PEMPair) IsZero

func (b PEMPair) IsZero() bool

func (PEMPair) PrivateKey

func (b PEMPair) PrivateKey() (key any, err error)

Jump to

Keyboard shortcuts

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