Documentation ¶
Index ¶
- Constants
- func EncodeWithBlockType(b []byte, blockType string) []byte
- type EcdsaKey
- func (g *EcdsaKey) Gen() (crypto.Signer, error)
- func (g *EcdsaKey) Marshal(pkey crypto.Signer, opts *MarshalOptions) ([]byte, error)
- func (g *EcdsaKey) MarshalECPrivateKey(pkey *ecdsa.PrivateKey, password []byte) ([]byte, error)
- func (g *EcdsaKey) MarshalPKCS8PrivateKey(pkey interface{}) ([]byte, error)
- type Generator
- type MarshalOptions
- type RsaKey
Constants ¶
const ( RsaBlockType = "RSA PRIVATE KEY" EcdsaBlockType = "EC PRIVATE KEY" PKCCS8BlockType = "PRIVATE KEY" DefaultKeyLength = 2048 RecommendedKeyLength = 4096 )
Variables ¶
This section is empty.
Functions ¶
func EncodeWithBlockType ¶ added in v0.2.0
EncodeWithBlockType returns the PEM encoding of b with the given block type. If b has invalid headers and cannot be encoded, Encode returns nil.
Types ¶
type EcdsaKey ¶
type EcdsaKey struct {
// contains filtered or unexported fields
}
func NewEcdsaKey ¶
NewEcdsaKey return an Ecdsa key generator.
func (*EcdsaKey) Marshal ¶ added in v0.1.15
Marshal converts an EC private key to SEC 1 or PKCS#8, ASN.1 DER form. And returns the private key encoded in PEM blocks.
func (*EcdsaKey) MarshalECPrivateKey ¶ added in v0.2.0
MarshalECPrivateKey converts an EC private key to SEC 1, ASN.1 DER form. And returns the private key encoded in PEM blocks.
func (*EcdsaKey) MarshalPKCS8PrivateKey ¶ added in v0.2.0
MarshalPKCS8PrivateKey converts a private key to PKCS #8, ASN.1 DER form. And returns the private key encoded in PEM blocks.
type Generator ¶ added in v0.1.1
type Generator interface { // Gen generates a public and private key pair. // And returns a crypto.Singer. Gen() (crypto.Signer, error) // Marshal converts a private key to ASN.1 DER form. // And returns the private key encoded in PEM blocks. // The opts is optional. Marshal(pkey crypto.Signer, opts *MarshalOptions) ([]byte, error) }
type MarshalOptions ¶ added in v0.2.0
type MarshalOptions struct { // Password can be nil, otherwise use it to encrypt the private key. // If the IsPKCS8 is true, the Password will be ignored. // See https://github.com/golang/go/commit/57af9745bfad2c20ed6842878e373d6c5b79285a. Password []byte // IsPKCS8 whether to convert the private key to PKCS #8, ASN.1 DER form. IsPKCS8 bool }
type RsaKey ¶
type RsaKey struct {
// contains filtered or unexported fields
}
func NewRsaKey ¶
NewRsaKey return an RSA key generator. If the bit size less than 2048 bits, set to 2048 bits.
func (*RsaKey) Marshal ¶ added in v0.1.15
Marshal converts an RSA private key to PKCS #1 or PKCS #8, ASN.1 DER form. And returns the private key encoded in PEM blocks.
func (*RsaKey) MarshalPKCS1PrivateKey ¶ added in v0.2.0
MarshalPKCS1PrivateKey converts an RSA private key to PKCS #1, ASN.1 DER form. And returns the private key encoded in PEM blocks.