Documentation
¶
Index ¶
- type CA
- type CAGenOpts
- type CAGenerator
- type CSP
- type CertKeyPair
- type Decrypter
- type DecrypterOpts
- type Encrypter
- type EncrypterOpts
- type HashOpts
- type Hasher
- type Key
- type KeyDerivOpts
- type KeyDeriver
- type KeyGenOpts
- type KeyGenerator
- type KeyImportOpts
- type KeyImporter
- type KeyStore
- type Signer
- type SignerOpts
- type Verifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CA ¶
type CA interface {
// CertBytes 返回 CA 的证书的 PEM 格式编码的字节切片。
CertBytes() []byte
// KeyBytes 返回 CA 的密钥的 PEM 格式编码的字节切片。
KeyBytes() []byte
// NewIntermediateCA 创建一个中级 CA。
NewIntermediateCA() (CA, error)
// NewClientCertKeyPair CA 调用此方法为 client 生成一个证书和对应的密钥,证书由 CA 签署,
// 然后证书被用来验证 client。
NewClientCertKeyPair() (CertKeyPair, error)
// NewServerCertKeyPair CA 为 server 生成一个证书和对应的密钥。
NewServerCertKeyPair(hosts ...string) (CertKeyPair, error)
// Signer 返回此证书用来给其他证书进行签名的 signer。
Signer() crypto.Signer
}
type CAGenerator ¶
type CSP ¶
type CSP interface {
// KeyGen 根据提供的密钥生成选项,生成一个密钥。
KeyGen(opts KeyGenOpts) (key Key, err error)
// KeyDeriv 给定一个密钥,在此密钥的基础上派生出一个新的密钥。
KeyDeriv(key Key, opts KeyDerivOpts) (dk Key, err error)
// KeyImport 给定一个密钥的原始数据,根据此原始数据导入一个密钥。
KeyImport(raw interface{}, opts KeyImportOpts) (key Key, err error)
// Hash 给定消息,计算此消息的哈希值。
Hash(msg []byte, opts HashOpts) ([]byte, error)
// GetHash 根据给定的哈希选项,返回特定的哈希函数。
GetHash(opts HashOpts) (hash.Hash, error)
// Sign 给定密钥(私钥)、消息摘要,计算签名。
Sign(key Key, digest []byte, opts SignerOpts) (signature []byte, err error)
// Verify 给定密钥(公钥)、签名,验证签名的正确性。
Verify(key Key, signature []byte, digest []byte, opts SignerOpts) (valid bool, err error)
// Encrypt 给定加密密钥、明文,计算密文。
Encrypt(key Key, plaintext []byte, opts EncrypterOpts) (ciphertext []byte, err error)
// Decrypt 给定解密密钥、密文,计算明文。
Decrypt(key Key, ciphertext []byte, opts DecrypterOpts) (plaintext []byte, err error)
// GetKey 给定密钥的主体标识符,返回此密钥本身。
GetKey(ski []byte) (key Key, err error)
CAGen(opts CAGenOpts) (CA, error)
}
type CertKeyPair ¶
type CertKeyPair interface {
// Cert 返回证书的 PEM 格式编码的字节切片。
Cert() []byte
// Key Cert方法返回的证书内包含证书的公钥,此方法返回的私钥与证书内的公钥相对应,
// 返回的字节切片是私钥的 PEM 格式编码。
Key() []byte
// Signer 返回签名私钥,Key 方法返回的字节切片就是此签名密钥。
Signer() crypto.Signer
// TLSCert 将 Cert 方法返回的字节切片解析后即可得到 x509 证书,然后此方法可返回该证书。
TLSCert() tls.Certificate
X509Cert() *x509.Certificate
}
type Decrypter ¶
type Decrypter interface {
Decrypt(key Key, ciphertext []byte, opts DecrypterOpts) ([]byte, error)
}
type Encrypter ¶
type Encrypter interface {
Encrypt(key Key, plaintext []byte, opts EncrypterOpts) ([]byte, error)
}
type Key ¶
type Key interface {
Bytes() ([]byte, error)
// SKI 返回密钥的主体密钥标识符。
SKI() []byte
// Symmetric 如果此密钥是对称密钥,则此方法返回 true,否则返回 false。
Symmetric() bool
// Private 如果此密钥是私钥,则此方法返回 true,否则返回 false。
Private() bool
// PublicKey 只有非对称密钥才能调用此方法返回公钥。
PublicKey() (Key, error)
}
Key softimpl 包内的所有密钥都必须实现此接口。
type KeyDerivOpts ¶
type KeyDeriver ¶
type KeyDeriver interface {
KeyDeriv(key Key, opts KeyDerivOpts) (Key, error)
}
type KeyGenOpts ¶
type KeyGenerator ¶
type KeyGenerator interface {
KeyGen(opts KeyGenOpts) (Key, error)
}
type KeyImportOpts ¶
type KeyImporter ¶
type KeyImporter interface {
KeyImport(raw interface{}, opts KeyImportOpts) (Key, error)
}
type Signer ¶
type Signer interface {
Sign(key Key, digest []byte, opts SignerOpts) ([]byte, error)
}
type SignerOpts ¶
Click to show internal directories.
Click to hide internal directories.