Documentation ¶
Index ¶
- Constants
- Variables
- func AddKey(name string, key KeyFunc)
- func AllKey() map[string]KeyFunc
- func Decode(pfxData []byte, password string) (privateKey any, certificate *x509.Certificate, err error)
- func DecodeChain(pfxData []byte, password string) (privateKey any, certificate *x509.Certificate, caCerts []*x509.Certificate, ...)
- func DecodeTrustStore(pfxData []byte, password string) (certs []*x509.Certificate, err error)
- func Encode(rand io.Reader, privateKey any, certificate *x509.Certificate, password string, ...) (pfxData []byte, err error)
- func EncodeChain(rand io.Reader, privateKey any, certificate *x509.Certificate, ...) (pfxData []byte, err error)
- func EncodeSecret(rand io.Reader, secretKey []byte, password string, opts ...Opts) (pfxData []byte, err error)
- func EncodeTrustStore(rand io.Reader, certs []*x509.Certificate, password string, opts ...Opts) (pfxData []byte, err error)
- func EncodeTrustStoreEntries(rand io.Reader, entries []TrustStoreEntry, password string, opts ...Opts) (pfxData []byte, err error)
- func GetStructName(s any) (name string)
- func MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
- func MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
- func ParsePKCS8PrivateKey(pkData []byte) (privateKey crypto.PrivateKey, err error)
- func ToPEM(pfxData []byte, password string) ([]*pem.Block, error)deprecated
- type CertKDFOpts
- type Cipher
- type ContentInfo
- type DigestInfo
- type EncryptedContentInfo
- type EncryptedData
- type Hash
- type ISafeBagData
- type Key
- type KeyDSA
- type KeyEcdsa
- type KeyEdDSA
- type KeyFunc
- type KeyKDFOpts
- type KeyRsa
- type KeySM2
- type Keys
- type MacData
- type MacKDFOpts
- type MacKDFParameters
- type MacOpts
- type NotImplementedError
- type Opts
- type PBKDF2Opts
- type PKCS12
- func (this *PKCS12) AddCaCert(ca *x509.Certificate)
- func (this *PKCS12) AddCaCertBytes(ca []byte)
- func (this *PKCS12) AddCaCerts(caCerts []*x509.Certificate)
- func (this *PKCS12) AddCaCertsBytes(caCerts [][]byte)
- func (this *PKCS12) AddCert(cert *x509.Certificate)
- func (this *PKCS12) AddCertBytes(cert []byte)
- func (this *PKCS12) AddPrivateKey(privateKey crypto.PrivateKey) error
- func (this *PKCS12) AddPrivateKeyBytes(privateKey []byte)
- func (this *PKCS12) AddSecretKey(secretKey []byte)
- func (this *PKCS12) AddTrustStore(cert *x509.Certificate)
- func (this *PKCS12) AddTrustStoreEntries(entries []TrustStoreData)
- func (this *PKCS12) AddTrustStoreEntry(cert *x509.Certificate, friendlyName string)
- func (this *PKCS12) AddTrustStoreEntryBytes(cert []byte, friendlyName string)
- func (this *PKCS12) AddTrustStores(certs []*x509.Certificate)
- func (this *PKCS12) GetCaCerts() (caCerts []*x509.Certificate, err error)
- func (this *PKCS12) GetCaCertsBytes() (caCerts [][]byte, err error)
- func (this *PKCS12) GetCert() (cert *x509.Certificate, attrs PKCS12Attributes, err error)
- func (this *PKCS12) GetCertBytes() (cert []byte, attrs PKCS12Attributes, err error)
- func (this *PKCS12) GetPrivateKey() (prikey crypto.PrivateKey, attrs PKCS12Attributes, err error)
- func (this *PKCS12) GetPrivateKeyBytes() (prikey []byte, attrs PKCS12Attributes, err error)
- func (this *PKCS12) GetSecretKey() (secretKey []byte, attrs PKCS12Attributes)
- func (this *PKCS12) GetTrustStoreEntries() (caCerts []trustStoreKeyData, err error)
- func (this *PKCS12) GetTrustStoreEntriesBytes() (caCerts []trustStoreKeyDataBytes, err error)
- func (this *PKCS12) GetTrustStores() (caCerts []*x509.Certificate, err error)
- func (this *PKCS12) GetTrustStoresBytes() (caCerts [][]byte, err error)
- func (this *PKCS12) HasCaCert() bool
- func (this *PKCS12) HasCert() bool
- func (this *PKCS12) HasPrivateKey() bool
- func (this *PKCS12) HasSecretKey() bool
- func (this *PKCS12) HasTrustStore() bool
- func (this *PKCS12) Marshal(rand io.Reader, password string, opts ...Opts) (pfxData []byte, err error)
- func (this *PKCS12) Parse(pfxData []byte, password string) (*PKCS12, error)
- func (this *PKCS12) SetLocalKeyId(id []byte)
- func (this *PKCS12) String() string
- func (this *PKCS12) ToOriginalPEM() ([]*pem.Block, error)
- func (this *PKCS12) ToPEM() ([]*pem.Block, error)
- type PKCS12Attribute
- type PKCS12Attributes
- type PfxPdu
- type SafeBag
- type SafeBagData
- type ScryptOpts
- type SecretKey
- type TrustStoreData
- type TrustStoreEntry
- type TrustStoreKey
Examples ¶
Constants ¶
const ( CertificateType = "CERTIFICATE" PrivateKeyType = "PRIVATE KEY" )
PEM block types
const DefaultPassword = "cryptobin"
DefaultPassword is the string "cryptobin", a commonly-used password for PKCS#12 files. Due to the weak encryption used by PKCS#12, it is RECOMMENDED that you use DefaultPassword when encoding PKCS#12 files, and protect the PKCS#12 files using other means.
const (
// PKCS12 系列
PKCS12Version = 3
)
Variables ¶
var ( AddCipher = pbes1.AddCipher GetCipher = pbes1.GetCipher )
别名
var ( CipherSHA1And3DES = pbes1.SHA1And3DES CipherSHA1And2DES = pbes1.SHA1And2DES CipherSHA1AndRC2_128 = pbes1.SHA1AndRC2_128 CipherSHA1AndRC2_40 = pbes1.SHA1AndRC2_40 CipherSHA1AndRC4_128 = pbes1.SHA1AndRC4_128 CipherSHA1AndRC4_40 = pbes1.SHA1AndRC4_40 )
加密方式
var ( // ErrDecryption represents a failure to decrypt the input. ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding") // ErrIncorrectPassword is returned when an incorrect password is detected. // Usually, P12/PFX data is signed to be able to verify the password. ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect") )
var ( // 获取 Cipher 类型 GetPbes1CipherFromName = pkcs8_pbes1.GetCipherFromName // 检测 Cipher 类型 CheckPbes1CipherFromName = pkcs8_pbes1.CheckCipherFromName // 获取 Cipher 类型 GetPbes2CipherFromName = pkcs8_pbes2.GetCipherFromName // 获取 hash 类型 GetPbes2HashFromName = pkcs8_pbes2.GetHashFromName )
var ( // 默认 hash DefaultHash = SHA1 )
var DefaultOpts = LegacyRC2Opts
默认配置
var LegacyDESOpts = Opts{ KeyCipher: pkcs8_pbes1.SHA1And3DES, CertCipher: CipherSHA1And3DES, MacKDFOpts: MacOpts{ SaltSize: 8, IterationCount: 1, HMACHash: SHA1, }, }
LegacyDES
var LegacyOpts = LegacyDESOpts
LegacyOpts
var LegacyRC2Opts = Opts{ KeyCipher: pkcs8_pbes1.SHA1And3DES, CertCipher: CipherSHA1AndRC2_40, MacKDFOpts: MacOpts{ SaltSize: 8, IterationCount: 1, HMACHash: SHA1, }, }
LegacyRC2
var LoadPKCS12 = LoadPKCS12FromBytes
别名
var Modern2023Opts = Opts{ KeyCipher: pkcs8_pbes2.AES256CBC, KeyKDFOpts: PBKDF2Opts{ SaltSize: 16, IterationCount: 2048, }, CertCipher: pkcs8_pbes2.AES256CBC, CertKDFOpts: PBKDF2Opts{ SaltSize: 16, IterationCount: 2048, }, MacKDFOpts: MacOpts{ SaltSize: 16, IterationCount: 2048, HMACHash: SHA256, }, }
Modern2023
var ModernOpts = Modern2023Opts
ModernOpts
var NewPKCS12Encode = NewPKCS12
var PasswordlessOpts = Opts{ KeyCipher: nil, CertCipher: nil, MacKDFOpts: nil, }
Passwordless
Functions ¶
func Decode ¶
func Decode(pfxData []byte, password string) ( privateKey any, certificate *x509.Certificate, err error, )
Decode extracts a certificate and private key from pfxData, which must be a DER-encoded PKCS#12 file. This function assumes that there is only one certificate and only one private key in the pfxData. Since PKCS#12 files often contain more than one certificate, you probably want to use DecodeChain instead.
func DecodeChain ¶
func DecodeChain(pfxData []byte, password string) ( privateKey any, certificate *x509.Certificate, caCerts []*x509.Certificate, err error, )
DecodeChain extracts a certificate, a CA certificate chain, and private key from pfxData, which must be a DER-encoded PKCS#12 file. This function assumes that there is at least one certificate and only one private key in the pfxData. The first certificate is assumed to be the leaf certificate, and subsequent certificates, if any, are assumed to comprise the CA certificate chain.
func DecodeTrustStore ¶
func DecodeTrustStore(pfxData []byte, password string) (certs []*x509.Certificate, err error)
DecodeTrustStore extracts the certificates from pfxData, which must be a DER-encoded PKCS#12 file containing exclusively certificates with attribute 2.16.840.1.113894.746875.1.1, which is used by Java to designate a trust anchor.
func Encode ¶
func Encode( rand io.Reader, privateKey any, certificate *x509.Certificate, password string, opts ...Opts, ) (pfxData []byte, err error)
for go
func EncodeChain ¶
func EncodeChain( rand io.Reader, privateKey any, certificate *x509.Certificate, caCerts []*x509.Certificate, password string, opts ...Opts, ) (pfxData []byte, err error)
EncodeChain produces pfxData containing one private key (privateKey), an end-entity certificate (certificate), and any number of CA certificates (caCerts).
The private key is encrypted with the provided password, but due to the weak encryption primitives used by PKCS#12, it is RECOMMENDED that you specify a hard-coded password (such as pkcs12.DefaultPassword) and protect the resulting pfxData using other means.
The rand argument is used to provide entropy for the encryption, and can be set to rand.Reader from the crypto/rand package.
EncodeChain emulates the behavior of OpenSSL's PKCS12_create: it creates two SafeContents: one that's encrypted with RC2 and contains the certificates, and another that is unencrypted and contains the private key shrouded with 3DES The private key bag and the end-entity certificate bag have the LocalKeyId attribute set to the SHA-1 fingerprint of the end-entity certificate.
func EncodeSecret ¶
func EncodeSecret(rand io.Reader, secretKey []byte, password string, opts ...Opts) (pfxData []byte, err error)
Encode Secret with der
func EncodeTrustStore ¶
func EncodeTrustStore( rand io.Reader, certs []*x509.Certificate, password string, opts ...Opts, ) (pfxData []byte, err error)
EncodeTrustStore produces pfxData containing any number of CA certificates (certs) to be trusted. The certificates will be marked with a special OID that allow it to be used as a Java TrustStore in Java 1.8 and newer.
Due to the weak encryption primitives used by PKCS#12, it is RECOMMENDED that you specify a hard-coded password (such as pkcs12.DefaultPassword) and protect the resulting pfxData using other means.
The rand argument is used to provide entropy for the encryption, and can be set to rand.Reader from the crypto/rand package.
EncodeTrustStore creates a single SafeContents that's encrypted with RC2 and contains the certificates.
The Subject of the certificates are used as the Friendly Names (Aliases) within the resulting pfxData. If certificates share a Subject, then the resulting Friendly Names (Aliases) will be identical, which Java may treat as the same entry when used as a Java TrustStore, e.g. with `keytool`. To customize the Friendly Names, use EncodeTrustStoreEntries.
func EncodeTrustStoreEntries ¶
func EncodeTrustStoreEntries( rand io.Reader, entries []TrustStoreEntry, password string, opts ...Opts, ) (pfxData []byte, err error)
EncodeTrustStoreEntries produces pfxData containing any number of CA certificates (entries) to be trusted. The certificates will be marked with a special OID that allow it to be used as a Java TrustStore in Java 1.8 and newer.
This is identical to EncodeTrustStore, but also allows for setting specific Friendly Names (Aliases) to be used per certificate, by specifying a slice of TrustStoreEntry.
If the same Friendly Name is used for more than one certificate, then the resulting Friendly Names (Aliases) in the pfxData will be identical, which Java may treat as the same entry when used as a Java TrustStore, e.g. with `keytool`.
Due to the weak encryption primitives used by PKCS#12, it is RECOMMENDED that you specify a hard-coded password (such as pkcs12.DefaultPassword) and protect the resulting pfxData using other means.
The rand argument is used to provide entropy for the encryption, and can be set to rand.Reader from the crypto/rand package.
EncodeTrustStoreEntries creates a single SafeContents that's encrypted with RC2 and contains the certificates.
func MarshalPKCS8PrivateKey ¶
func MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
从注册的 key 列表编码证书
func MarshalPrivateKey ¶
func MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
从注册的 key 列表编码证书
func ParsePKCS8PrivateKey ¶
func ParsePKCS8PrivateKey(pkData []byte) (privateKey crypto.PrivateKey, err error)
从注册的 key 列表解析证书
func ToPEM
deprecated
ToPEM converts all "safe bags" contained in pfxData to PEM blocks.
Deprecated: ToPEM creates invalid PEM blocks (private keys are encoded as raw RSA or EC private keys rather than PKCS#8 despite being labeled "PRIVATE KEY"). To decode a PKCS#12 file, use DecodeChain instead, and use the encoding/pem package to convert to PEM if necessary.
Example ¶
p12, _ := base64.StdEncoding.DecodeString(`MIIJzgIBAzCCCZQGCS ... CA+gwggPk==`) blocks, err := ToPEM(p12, "password") if err != nil { panic(err) } var pemData []byte for _, b := range blocks { pemData = append(pemData, pem.EncodeToMemory(b)...) } // then use PEM data for tls to construct tls certificate: cert, err := tls.X509KeyPair(pemData, pemData) if err != nil { panic(err) } config := &tls.Config{ Certificates: []tls.Certificate{cert}, } _ = config
Output:
Types ¶
type CertKDFOpts ¶ added in v1.0.2031
type CertKDFOpts = pkcs8_pbes2.KDFOpts
type Cipher ¶
type Cipher interface { // oid OID() asn1.ObjectIdentifier // 值大小 KeySize() int // 加密, 返回: [加密后数据, 参数, error] Encrypt(rand io.Reader, key, plaintext []byte) ([]byte, []byte, error) // 解密 Decrypt(key, params, ciphertext []byte) ([]byte, error) }
加密接口
type ContentInfo ¶ added in v1.0.2032
type ContentInfo struct { ContentType asn1.ObjectIdentifier Content asn1.RawValue `asn1:"tag:0,explicit,optional"` }
type DigestInfo ¶ added in v1.0.2032
type DigestInfo struct { Algorithm pkix.AlgorithmIdentifier Digest []byte }
from PKCS#7:
type EncryptedContentInfo ¶ added in v1.0.2032
type EncryptedContentInfo struct { ContentType asn1.ObjectIdentifier ContentEncryptionAlgorithm pkix.AlgorithmIdentifier EncryptedContent []byte `asn1:"tag:0,optional"` }
func (EncryptedContentInfo) Algorithm ¶ added in v1.0.2032
func (this EncryptedContentInfo) Algorithm() pkix.AlgorithmIdentifier
func (EncryptedContentInfo) Data ¶ added in v1.0.2032
func (this EncryptedContentInfo) Data() []byte
type EncryptedData ¶ added in v1.0.2032
type EncryptedData struct { Version int EncryptedContentInfo EncryptedContentInfo }
type ISafeBagData ¶ added in v1.0.2033
type ISafeBagData interface { // Attributes return the PKCS12AttrSet of the safe bag Attributes() map[string]string // Data Data() []byte // Attrs Attrs() PKCS12Attributes // FriendlyName return the value of `friendlyName` // attribute if exists, otherwise it will return empty string FriendlyName() string }
SafeBagData
type Key ¶
type Key interface { // 包装默认证书 MarshalPrivateKey(privateKey crypto.PrivateKey) (pkData []byte, err error) // 包装 PKCS8 证书 MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) (pkData []byte, err error) // 解析 PKCS8 证书 ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error) }
Key 接口
type KeyDSA ¶
type KeyDSA struct{}
DSA
func (KeyDSA) MarshalPKCS8PrivateKey ¶
func (this KeyDSA) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyDSA) MarshalPrivateKey ¶
func (this KeyDSA) MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyDSA) ParsePKCS8PrivateKey ¶
func (this KeyDSA) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)
解析
type KeyEcdsa ¶
type KeyEcdsa struct{}
Ecdsa
func (KeyEcdsa) MarshalPKCS8PrivateKey ¶
func (this KeyEcdsa) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyEcdsa) MarshalPrivateKey ¶
func (this KeyEcdsa) MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyEcdsa) ParsePKCS8PrivateKey ¶
func (this KeyEcdsa) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)
解析
type KeyEdDSA ¶
type KeyEdDSA struct{}
EdDSA
func (KeyEdDSA) MarshalPKCS8PrivateKey ¶
func (this KeyEdDSA) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyEdDSA) MarshalPrivateKey ¶
func (this KeyEdDSA) MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyEdDSA) ParsePKCS8PrivateKey ¶
func (this KeyEdDSA) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)
解析
type KeyRsa ¶
type KeyRsa struct{}
rsa
func (KeyRsa) MarshalPKCS8PrivateKey ¶
func (this KeyRsa) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyRsa) MarshalPrivateKey ¶
func (this KeyRsa) MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeyRsa) ParsePKCS8PrivateKey ¶
func (this KeyRsa) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)
解析
type KeySM2 ¶
type KeySM2 struct{}
SM2
func (KeySM2) MarshalPKCS8PrivateKey ¶
func (this KeySM2) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeySM2) MarshalPrivateKey ¶
func (this KeySM2) MarshalPrivateKey(privateKey crypto.PrivateKey) ([]byte, error)
包装
func (KeySM2) ParsePKCS8PrivateKey ¶
func (this KeySM2) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)
解析
type Keys ¶ added in v1.0.2032
type Keys struct {
// contains filtered or unexported fields
}
Key 数据
type MacData ¶ added in v1.0.2032
type MacData struct { Mac DigestInfo MacSalt []byte Iterations int `asn1:"optional,default:1"` }
type MacKDFOpts ¶ added in v1.0.2031
type MacKDFOpts interface { // 构造 Compute(message []byte, password []byte) (data MacKDFParameters, err error) }
KDF 设置接口
type MacKDFParameters ¶ added in v1.0.2031
数据接口
type NotImplementedError ¶
type NotImplementedError string
NotImplementedError indicates that the input is not currently supported.
func (NotImplementedError) Error ¶
func (e NotImplementedError) Error() string
type Opts ¶
type Opts struct { KeyCipher Cipher KeyKDFOpts KeyKDFOpts CertCipher Cipher CertKDFOpts CertKDFOpts MacKDFOpts MacKDFOpts }
配置
func (Opts) WithCertCipher ¶ added in v1.0.2031
func (Opts) WithCertKDFOpts ¶ added in v1.0.2031
func (this Opts) WithCertKDFOpts(opts CertKDFOpts) Opts
func (Opts) WithKeyCipher ¶ added in v1.0.2031
func (Opts) WithKeyKDFOpts ¶ added in v1.0.2031
func (this Opts) WithKeyKDFOpts(opts KeyKDFOpts) Opts
func (Opts) WithMacKDFOpts ¶ added in v1.0.2031
func (this Opts) WithMacKDFOpts(opts MacKDFOpts) Opts
type PKCS12 ¶ added in v1.0.2033
type PKCS12 struct {
// contains filtered or unexported fields
}
PKCS12 结构
func LoadPKCS12FromBytes ¶ added in v1.0.2033
LoadPKCS12FromBytes loads the key store from the bytes data.
func LoadPKCS12FromReader ¶ added in v1.0.2033
LoadPKCS12FromReader loads the key store from the specified file.
func (*PKCS12) AddCaCert ¶ added in v1.0.2033
func (this *PKCS12) AddCaCert(ca *x509.Certificate)
func (*PKCS12) AddCaCertBytes ¶ added in v1.0.2033
func (*PKCS12) AddCaCerts ¶ added in v1.0.2033
func (this *PKCS12) AddCaCerts(caCerts []*x509.Certificate)
func (*PKCS12) AddCaCertsBytes ¶ added in v1.0.2033
func (*PKCS12) AddCert ¶ added in v1.0.2033
func (this *PKCS12) AddCert(cert *x509.Certificate)
func (*PKCS12) AddCertBytes ¶ added in v1.0.2033
func (*PKCS12) AddPrivateKey ¶ added in v1.0.2033
func (this *PKCS12) AddPrivateKey(privateKey crypto.PrivateKey) error
func (*PKCS12) AddPrivateKeyBytes ¶ added in v1.0.2033
func (*PKCS12) AddSecretKey ¶ added in v1.0.2033
func (*PKCS12) AddTrustStore ¶ added in v1.0.2033
func (this *PKCS12) AddTrustStore(cert *x509.Certificate)
func (*PKCS12) AddTrustStoreEntries ¶ added in v1.0.2033
func (this *PKCS12) AddTrustStoreEntries(entries []TrustStoreData)
func (*PKCS12) AddTrustStoreEntry ¶ added in v1.0.2033
func (this *PKCS12) AddTrustStoreEntry(cert *x509.Certificate, friendlyName string)
func (*PKCS12) AddTrustStoreEntryBytes ¶ added in v1.0.2033
func (*PKCS12) AddTrustStores ¶ added in v1.0.2033
func (this *PKCS12) AddTrustStores(certs []*x509.Certificate)
func (*PKCS12) GetCaCerts ¶ added in v1.0.2033
func (this *PKCS12) GetCaCerts() (caCerts []*x509.Certificate, err error)
func (*PKCS12) GetCaCertsBytes ¶ added in v1.0.2033
func (*PKCS12) GetCert ¶ added in v1.0.2033
func (this *PKCS12) GetCert() (cert *x509.Certificate, attrs PKCS12Attributes, err error)
func (*PKCS12) GetCertBytes ¶ added in v1.0.2033
func (this *PKCS12) GetCertBytes() (cert []byte, attrs PKCS12Attributes, err error)
func (*PKCS12) GetPrivateKey ¶ added in v1.0.2033
func (this *PKCS12) GetPrivateKey() (prikey crypto.PrivateKey, attrs PKCS12Attributes, err error)
func (*PKCS12) GetPrivateKeyBytes ¶ added in v1.0.2033
func (this *PKCS12) GetPrivateKeyBytes() (prikey []byte, attrs PKCS12Attributes, err error)
func (*PKCS12) GetSecretKey ¶ added in v1.0.2033
func (this *PKCS12) GetSecretKey() (secretKey []byte, attrs PKCS12Attributes)
func (*PKCS12) GetTrustStoreEntries ¶ added in v1.0.2033
func (*PKCS12) GetTrustStoreEntriesBytes ¶ added in v1.0.2033
func (*PKCS12) GetTrustStores ¶ added in v1.0.2033
func (this *PKCS12) GetTrustStores() (caCerts []*x509.Certificate, err error)
func (*PKCS12) GetTrustStoresBytes ¶ added in v1.0.2033
func (*PKCS12) HasPrivateKey ¶ added in v1.0.2033
func (*PKCS12) HasSecretKey ¶ added in v1.0.2033
func (*PKCS12) HasTrustStore ¶ added in v1.0.2033
func (*PKCS12) SetLocalKeyId ¶ added in v1.0.2033
func (*PKCS12) ToOriginalPEM ¶ added in v1.0.2033
生成原始数据的PEM证书
type PKCS12Attribute ¶ added in v1.0.2032
type PKCS12Attribute struct { Id asn1.ObjectIdentifier Value asn1.RawValue `asn1:"set"` }
type PKCS12Attributes ¶ added in v1.0.2033
type PKCS12Attributes struct {
// contains filtered or unexported fields
}
额外数据
func NewPKCS12Attributes ¶ added in v1.0.2033
func NewPKCS12Attributes(attrs []PKCS12Attribute) PKCS12Attributes
func NewPKCS12AttributesEmpty ¶ added in v1.0.2033
func NewPKCS12AttributesEmpty() PKCS12Attributes
func (PKCS12Attributes) Attributes ¶ added in v1.0.2033
func (this PKCS12Attributes) Attributes() []PKCS12Attribute
数据
func (PKCS12Attributes) String ¶ added in v1.0.2033
func (this PKCS12Attributes) String() string
返回字符
func (PKCS12Attributes) ToArray ¶ added in v1.0.2033
func (this PKCS12Attributes) ToArray() map[string]string
返回数据
func (PKCS12Attributes) Verify ¶ added in v1.0.2033
func (this PKCS12Attributes) Verify(data []byte) bool
验证签名数据
type PfxPdu ¶ added in v1.0.2032
type PfxPdu struct { Version int AuthSafe ContentInfo MacData MacData `asn1:"optional"` }
type SafeBag ¶ added in v1.0.2032
type SafeBag struct { Id asn1.ObjectIdentifier Value asn1.RawValue `asn1:"tag:0,explicit"` Attributes []PKCS12Attribute `asn1:"set,optional"` }
type SafeBagData ¶ added in v1.0.2033
type SafeBagData struct {
// contains filtered or unexported fields
}
func NewSafeBagData ¶ added in v1.0.2033
func NewSafeBagData(data []byte, attrs PKCS12Attributes) SafeBagData
func NewSafeBagDataWithAttrs ¶ added in v1.0.2033
func NewSafeBagDataWithAttrs(data []byte, attrs []PKCS12Attribute) SafeBagData
func (SafeBagData) Attributes ¶ added in v1.0.2033
func (this SafeBagData) Attributes() map[string]string
func (SafeBagData) Attrs ¶ added in v1.0.2033
func (this SafeBagData) Attrs() PKCS12Attributes
func (SafeBagData) Data ¶ added in v1.0.2033
func (this SafeBagData) Data() []byte
func (SafeBagData) FriendlyName ¶ added in v1.0.2033
func (this SafeBagData) FriendlyName() string
type SecretKey ¶
type SecretKey interface { // Attributes return the PKCS12AttrSet of the safe bag // https://tools.ietf.org/html/rfc7292#section-4.2 Attributes() map[string]string // key Key() []byte // FriendlyName return the value of `friendlyName` // attribute if exists, otherwise it will return empty string FriendlyName() string }
type TrustStoreData ¶ added in v1.0.2033
TrustStoreData represents an entry in a Java TrustStore.
func NewTrustStoreData ¶ added in v1.0.2033
func NewTrustStoreData(cert *x509.Certificate, friendlyName string) TrustStoreData
type TrustStoreEntry ¶
type TrustStoreEntry struct { Cert *x509.Certificate FriendlyName string }
TrustStoreEntry represents an entry in a Java TrustStore.
type TrustStoreKey ¶ added in v1.0.2031
type TrustStoreKey interface { // Attributes return the PKCS12AttrSet of the safe bag // https://tools.ietf.org/html/rfc7292#section-4.2 Attributes() map[string]string // Cert Cert() *x509.Certificate // FriendlyName return the value of `friendlyName` // attribute if exists, otherwise it will return empty string FriendlyName() string }
func DecodeTrustStoreEntries ¶ added in v1.0.2031
func DecodeTrustStoreEntries(pfxData []byte, password string) (trustStoreKeys []TrustStoreKey, err error)
DecodeTrustStoreEntries extracts the certificates from pfxData, which must be a DER-encoded
Source Files ¶
- bmp_string.go
- cipher.go
- errors.go
- kdf_mac.go
- key.go
- key_dsa.go
- key_ecdsa.go
- key_eddsa.go
- key_rsa.go
- key_setting.go
- key_sm2.go
- p12.go
- p12_decode.go
- p12_encode.go
- p12_utils.go
- pkcs12.go
- pkcs12_interface.go
- pkcs12_option.go
- pkcs12_utils.go
- safebags.go
- secret.go
- secret_key.go
- secret_value.go
- trust_store_key.go