crypto

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PEMArmorCertificate        = "CERTIFICATE"
	PEMArmorPKCS8PrivateKey    = "PRIVATE KEY"
	PEMArmorPKCS1RSAPrivateKey = "RSA PRIVATE KEY"
)

Variables

View Source
var (
	ErrNoClientCertificatesFound     = errors.New("no client certificates found")
	ErrMultipleClientCertificates    = errors.New("multiple client certificates found")
	ErrInvalidTypeInCertificateChain = errors.New(
		"a certificate in the chain is of the wrong type",
	)
	ErrFailedToParsePrivateKey  = errors.New("failed to parse private key")
	ErrFailedToParseCertificate = errors.New("failed to parse certificate")
	ErrPrivateKeyWrongType      = errors.New("private key is of the wrong type")
	ErrFailedToSignWithRSAKey   = errors.New("failed to sign using RSA private key")

	ErrPemEncode          = errors.New("PEM encode error")
	ErrGeneratePrivateKey = errors.New("generate private key error")
)

Functions

func GeneratePrivateKey

func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)

func LoadCertificates

func LoadCertificates(certificateBytes []byte) (*x509.Certificate, []*x509.Certificate, error)

LoadCertificates loads the client certificate and certificate authorities from a PEM certificate chain. There must be one and only one client certificate in the chain. There can be zero, one, or more certificate authorities in the chain. Returns the singular client certificate and array of certificate authorities.

func LoadRSAPrivateKey

func LoadRSAPrivateKey(privateKeyBytes []byte) (*rsa.PrivateKey, error)

LoadRSAPrivateKey loads the RSA private key from the given bytes either from PKCS1 or PKCS8 format.

func PEMEncode

func PEMEncode(buffer []byte, pemType string) ([]byte, error)

func Sha256HashHex

func Sha256HashHex(content []byte) string

Sha256HashHex returns the SHA256 hash of the content as a hex string

func SignWithRSAPrivateKey

func SignWithRSAPrivateKey(privateKey *rsa.PrivateKey, content []byte) (string, error)

SignWithRSAPrivateKey signs the content with the RSA private key and returns the signature as a hex string. The content is hashed with SHA256 before signing and uses PKCS#1 v1.5 padding.

Types

This section is empty.

Jump to

Keyboard shortcuts

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