tls

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 21 Imported by: 0

README

tls

产生自签TLS证书

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertificateInfo

func CertificateInfo(certPath string) (*x509.Certificate, error)

func FormatIp

func FormatIp(ipStr string) (string, error)

func GenKeyAndCert added in v1.6.3

func GenKeyAndCert(hosts []string, keyFile, certFile string, types int) error

GenKeyAndCert 生成密钥和证书 types 0 为签名证书,1 为加密证书

func GenerateKey

func GenerateKey(root bool) (*rsa.PrivateKey, error)

func GenerateRoot

func GenerateRoot() (*x509.Certificate, *rsa.PrivateKey, error)

GenerateRoot return cert, privDER, nil

func GmCertificateInfo added in v1.6.7

func GmCertificateInfo(certPath string) (*x509.Certificate, error)

func IsIP

func IsIP(host string) bool

func IsIPv4

func IsIPv4(ip string) bool

func IsIPv6

func IsIPv6(ip string) bool

func IsSameIP

func IsSameIP(ipFirst, ipSecond string) bool

func Pkcs12Encode added in v1.3.2

func Pkcs12Encode(cert, key []byte, password string) (string, error)

func ReadGmPrivKey added in v1.6.7

func ReadGmPrivKey(key []byte) (*sm2.PrivateKey, error)

func ReadGmRootCert added in v1.6.7

func ReadGmRootCert(cert []byte) (*x509.Certificate, error)

func ReadPrivKey

func ReadPrivKey(key []byte) (*rsa.PrivateKey, error)

func ReadPrivKeyFile

func ReadPrivKeyFile(filename string) (*rsa.PrivateKey, error)

func ReadRootCert

func ReadRootCert(cert []byte) (*x509.Certificate, error)

func ReadRootCertFile

func ReadRootCertFile(filename string) (*x509.Certificate, error)

func SerialNumber added in v1.6.5

func SerialNumber() *big.Int

func UserAndHostname added in v1.6.5

func UserAndHostname() string

func WritePEM

func WritePEM(filepath string, pem []byte) error

Types

type CACert

type CACert struct {
	Cert *x509.Certificate
	Key  *rsa.PrivateKey
}

func (*CACert) GenerateServer

func (c *CACert) GenerateServer(hosts []string) ([]byte, []byte, error)

GenerateServer return certPEM, privPEM, nil

type GmCACert added in v1.6.6

type GmCACert struct {
	Cert  *x509.Certificate
	Key   *sm2.PrivateKey
	Hosts []string // 证书支持的主机名列表
}

GmCACert 国密CA证书结构体

func GenerateGmRoot added in v1.6.6

func GenerateGmRoot() (*GmCACert, error)

GenerateGmRoot 生成国密根证书

func (*GmCACert) GenerateGmCert added in v1.6.6

func (c *GmCACert) GenerateGmCert(keyFile, certFile string, types int) error

GenerateGmCert 使用国密根证书生成子证书 types 0 为签名证书,1 为加密证书

func (*GmCACert) SaveGmCertAndKey added in v1.6.6

func (c *GmCACert) SaveGmCertAndKey(certFile, keyFile string) error

SaveGmCertAndKey 保存国密证书和密钥到文件

Jump to

Keyboard shortcuts

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