Documentation
¶
Index ¶
- Constants
- Variables
- func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
- func LoadCertificates(certificateBytes []byte) (*x509.Certificate, []*x509.Certificate, error)
- func LoadRSAPrivateKey(privateKeyBytes []byte) (*rsa.PrivateKey, error)
- func PEMEncode(buffer []byte, pemType string) ([]byte, error)
- func Sha256HashHex(content []byte) string
- func SignWithRSAPrivateKey(privateKey *rsa.PrivateKey, content []byte) (string, error)
Constants ¶
const ( PEMArmorCertificate = "CERTIFICATE" PEMArmorPKCS8PrivateKey = "PRIVATE KEY" PEMArmorPKCS1RSAPrivateKey = "RSA PRIVATE KEY" )
Variables ¶
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 Sha256HashHex ¶
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.