pki

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: Apache-2.0 Imports: 16 Imported by: 8

Documentation

Index

Constants

View Source
const (
	TypeIssuingCA = "IssuingCA"
	// TypeIssuingSubCert is an issuing sub cert which is signed by issuing ca
	TypeIssuingSubCert = "IssuingSubCertificate"

	// 证书有效期,以天为单位 [1, 50*365]
	DefaultCADuration      = 50 * 365
	DefaultSubCertDuration = 20 * 365
)
View Source
const (
	RsaPrivateKeyBlockType      = "RSA PRIVATE KEY"
	EcPrivateKeyBlockType       = "EC PRIVATE KEY"
	CertificateBlockType        = "CERTIFICATE"
	CertificateRequestBlockType = "CERTIFICATE REQUEST"

	DefaultDSA     = "P256"
	DefaultRSABits = 2048
)

Variables

This section is empty.

Functions

func EncodeByteToPem

func EncodeByteToPem(data []byte, tp string) string

func EncodeCertPrivateKey

func EncodeCertPrivateKey(priv *PrivateKey) ([]byte, error)

EncodeCertPrivateKey returns PEM-encoded private key data

func EncodeCertificates

func EncodeCertificates(certs ...*x509.Certificate) ([]byte, error)

EncodeCertificates returns the PEM-encoded byte array that represents by the specified certs

func EncodeCertificatesRequest

func EncodeCertificatesRequest(csrs ...*x509.CertificateRequest) ([]byte, error)

EncodeCertificatesRequest returns the PEM-encoded byte array that represents by the specified certs

func ParseCertificates

func ParseCertificates(pemCerts []byte) ([]*x509.Certificate, error)

ParseCertificates takes a PEM encoded x509 certificates byte array and returns A x509 certificate and the block byte array

func SigAlgorithmType

func SigAlgorithmType(priv *PrivateKey) x509.SignatureAlgorithm

Types

type PKI

type PKI interface {
	CreateRootCert(info *x509.CertificateRequest, parentId string) (string, error)
	GetCert(certId string) ([]byte, error)
	CreateSubCert(csr []byte, rootId string) (string, error)
	DeleteRootCert(rootId string) error
	DeleteSubCert(certId string) error
	io.Closer
}

func NewPKIClient

func NewPKIClient(keyFile, crtFile string, sto Storage) (PKI, error)

type PrivateKey

type PrivateKey struct {
	Type string
	Key  interface{}
}

PrivateKey wraps a ECC or RSA private key

func GenCertPrivateKey

func GenCertPrivateKey(dsa string, bits int) (*PrivateKey, error)

func ParseCertPrivateKey

func ParseCertPrivateKey(key []byte) (*PrivateKey, error)

ParseCertPrivateKey takes a key PEM byte array and returns a PrivateKey that represents Either an RSA or EC private key.

type Storage

type Storage interface {
	CreateCert(cert models.Cert) error
	DeleteCert(certId string) error
	UpdateCert(cert models.Cert) error
	GetCert(certId string) (*models.Cert, error)
	CountCertByParentId(parentId string) (int, error)
	io.Closer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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