tls

package
v0.0.0-...-26d813d Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 20 Imported by: 17

Documentation

Index

Constants

View Source
const (
	RsaPKCS1PrivateKey = "RSA PRIVATE KEY"
	RsaPKCS8PrivateKey = "PRIVATE KEY"
	RsaPKCS1PublicKey  = "RSA PUBLIC KEY"
	RsaPKCS8PublicKey  = "PUBLIC KEY"
	CERTIFICATE        = "CERTIFICATE"
)

Variables

This section is empty.

Functions

func BuildClientSimpleTLSConfig

func BuildClientSimpleTLSConfig(caCert *x509.Certificate) (*tls.Config, error)

BuildClientSimpleTLSConfig builds client tls config.

func BuildClientTLSConfig

func BuildClientTLSConfig(caCert *x509.Certificate, cert *x509.Certificate, key *rsa.PrivateKey) (*tls.Config, error)

BuildClientTLSConfig builds client tls config.

func BuildClientTLSConfigViaPath

func BuildClientTLSConfigViaPath(caPath, certPath, keyPath string) (*tls.Config, error)

BuildClientTLSConfigViaPath builds client tls config.

func BuildServerTLSConfig

func BuildServerTLSConfig(caCert *x509.Certificate, cert *x509.Certificate, key *rsa.PrivateKey) (*tls.Config, error)

BuildServerTLSConfig builds server tls config.

func BuildServerTLSConfigFromPath

func BuildServerTLSConfigFromPath(caPath, certPath, keyPath string) (*tls.Config, error)

BuildServerTLSConfigFromPath builds server tls config.

func BuildTLSCertificate

func BuildTLSCertificate(cert *x509.Certificate, key *rsa.PrivateKey) []tls.Certificate

BuildTLSCertificate builds tls certificate.

func BuildTLSCertificateViaPath

func BuildTLSCertificateViaPath(certPath, keyPath string) ([]tls.Certificate, error)

BuildTLSCertificateViaPath builds tls certificate.

func CreateCA

func CreateCA(subjectName string) (*rsa.PrivateKey, []byte, error)

func CreateCAFile

func CreateCAFile(subjectName, certFile, keyFile string) error

func DecodeCert

func DecodeCert(certContent []byte) (*x509.Certificate, error)

DecodeCert loads cert from string content

func DecryptOAEP

func DecryptOAEP(priv *rsa.PrivateKey, ciphertext string) ([]byte, error)

func DecryptPKCS1v15

func DecryptPKCS1v15(priv *rsa.PrivateKey, ciphertext string, keysize int, prefix []byte) ([]byte, error)

func EncodeCert

func EncodeCert(cert *x509.Certificate) (string, error)

EncodeCert encode cert.

func EncodePKCS1PrivateKey

func EncodePKCS1PrivateKey(priKey *rsa.PrivateKey) []byte

func EncodePKCS1PublicKey

func EncodePKCS1PublicKey(priKey *rsa.PrivateKey) []byte

func EncodePKCS8PrivateKey

func EncodePKCS8PrivateKey(priKey *rsa.PrivateKey) ([]byte, error)

func EncodePKCS8PublicKey

func EncodePKCS8PublicKey(priKey *rsa.PrivateKey) ([]byte, error)

func EncodeRsaKeyToPKCS1

func EncodeRsaKeyToPKCS1(key *rsa.PrivateKey) (string, error)

EncodeRsaKeyToPKCS1 encode key to pkcs#1 form key.

func EncodeRsaKeyToPKCS8

func EncodeRsaKeyToPKCS8(key *rsa.PrivateKey) (string, error)

EncodeRsaKeyToPKCS8 encode key to pkcs#8 form key.

func EncryptOAEP

func EncryptOAEP(pub *rsa.PublicKey, key []byte) (string, error)

func EncryptPKCS1v15

func EncryptPKCS1v15(pub *rsa.PublicKey, key []byte, prefix []byte) (string, error)

func GenerateKeyCertPairData

func GenerateKeyCertPairData(rootCAKey *rsa.PrivateKey, rootCACert *x509.Certificate, commonName string) (string, string, error)

func GenerateKeyData

func GenerateKeyData() (string, error)

func GeneratePrivateKeyToFile

func GeneratePrivateKeyToFile(filename string) error

func GenerateX509KeyPair

func GenerateX509KeyPair(parent *x509.Certificate, caKey any, cert *x509.Certificate, certOut, keyOut io.Writer) error

GenerateX509KeyPair creates a public/private key pair and creates a new X.509 v3 certificate based on a template. caKey can be ecdsa.PrivateKey or rsa.PrivateKey

func GenerateX509KeyPairStruct

func GenerateX509KeyPairStruct(parent *x509.Certificate, caKey any, certTemplate *x509.Certificate) (*rsa.PrivateKey, *x509.Certificate, error)

GenerateX509KeyPairStruct creates a public/private key pair and creates a new X.509 v3 certificate based on a template. caKey can be ecdsa.PrivateKey or rsa.PrivateKey

func LoadCertFile

func LoadCertFile(name string) ([]byte, error)

LoadCertFile loads cert file.

func LoadKeyData

func LoadKeyData(keyFile string) (string, error)

func LoadX509EcKeyPair

func LoadX509EcKeyPair(certFile, keyFile string) (*x509.Certificate, *ecdsa.PrivateKey, error)

func LoadX509KeyPair

func LoadX509KeyPair(certFile, keyFile string) (*x509.Certificate, *rsa.PrivateKey, error)

LoadX509KeyPair reads and parses a public/private key pair from a pair of files. The files must contain PEM encoded data.

func ParseCert

func ParseCert(certData []byte, certFile string) (cert *x509.Certificate, err error)

func ParseCertData

func ParseCertData(data []byte) (*x509.Certificate, error)

func ParseCertFromFile

func ParseCertFromFile(caFilePath string) (*x509.Certificate, error)

func ParseCertWithGenerated

func ParseCertWithGenerated(privateKey *rsa.PrivateKey, subject string, certData []byte, certFile string) (cert *x509.Certificate, err error)

func ParseEncodedKey

func ParseEncodedKey(keyDataEncoded, keyFile string) (*rsa.PrivateKey, error)

func ParseKey

func ParseKey(keyData []byte, keyFile string) (key *rsa.PrivateKey, err error)

func ParseRSAPrivateKeyData

func ParseRSAPrivateKeyData(data []byte) (*rsa.PrivateKey, error)

func ParseRSAPrivateKeyFile

func ParseRSAPrivateKeyFile(serverKey string) (*rsa.PrivateKey, error)

func ParseRSAPublicKey

func ParseRSAPublicKey(der []byte) (*rsa.PublicKey, error)

func SignWithRSA

func SignWithRSA(key *rsa.PrivateKey, data string) (string, error)

func VerifyCert

func VerifyCert(cert []byte) bool

func VerifyEncodeCert

func VerifyEncodeCert(base64EncodeCert string) error

func VerifySSLKey

func VerifySSLKey(key []byte) bool

func WritePrivateKeyToFile

func WritePrivateKeyToFile(key *rsa.PrivateKey, filename string) error

func WriteX509CertToFile

func WriteX509CertToFile(cert *x509.Certificate, filename string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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