Documentation
¶
Overview ¶
Package pemutil provides a simple, high-level API to load, parse, and decode standard crypto primitives (ie, rsa.PrivateKey, ecdsa.PrivateKey, etc) from PEM-encoded data.
Example:
store, err := pemutil.LoadFile("/path/to/file") if err != nil { /* ... */ } if rsaPrivKey, ok := store.RSAPrivateKey(); !ok { // PEM does not contain an RSA private key }
Index ¶
- func Decode(s Store, buf []byte) error
- func EncodePrimitive(p interface{}) ([]byte, error)
- func ParsePKCSPrivateKey(buf []byte) (interface{}, error)
- type BlockType
- type Store
- func (s Store) AddPublicKeys()
- func (s Store) Bytes() ([]byte, error)
- func (s Store) Certificate() (*x509.Certificate, bool)
- func (s Store) Decode(buf []byte) error
- func (s Store) DecodeBlock(block *pem.Block) error
- func (s Store) ECPrivateKey() (*ecdsa.PrivateKey, bool)
- func (s Store) ECPublicKey() (*ecdsa.PublicKey, bool)
- func (s Store) LoadFile(filename string) error
- func (s Store) PrivateKey() (crypto.PrivateKey, bool)
- func (s Store) PublicKey() (crypto.PublicKey, bool)
- func (s Store) RSAPrivateKey() (*rsa.PrivateKey, bool)
- func (s Store) RSAPublicKey() (*rsa.PublicKey, bool)
- func (s Store) WriteFile(filename string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode parses and decodes PEM-encoded data from buf, storing any resulting crypto primitives encountered into the Store. The decoded PEM BlockType will be used as the map key for each primitive.
func EncodePrimitive ¶
EncodePrimitive encodes the crypto primitive p into PEM-encoded data.
func ParsePKCSPrivateKey ¶
ParsePKCSPrivateKey attempts to decode a RSA private key first using PKCS1 encoding, and then PKCS8 encoding.
Types ¶
type BlockType ¶
type BlockType string
BlockType is a PEM block type.
const ( // PrivateKey is the "PRIVATE KEY" block type. PrivateKey BlockType = "PRIVATE KEY" // RSAPrivateKey is the "RSA PRIVATE KEY" block type. RSAPrivateKey BlockType = "RSA PRIVATE KEY" // ECPrivateKey is the "EC PRIVATE KEY" block type. ECPrivateKey BlockType = "EC PRIVATE KEY" // PublicKey is the "PUBLIC KEY" block type. PublicKey BlockType = "PUBLIC KEY" // Certificate is the "CERTIFICATE" block type. Certificate BlockType = "CERTIFICATE" )
type Store ¶
type Store map[BlockType]interface{}
Store is a store containing crypto primitives.
A store can contain any of the following crypto primitives:
[]byte -- raw key *rsa.PrivateKey, *ecdsa.PrivateKey -- rsa / ecdsa private key *rsa.PublicKey, *ecdsa.PublicKey -- rsa / ecdsa public key *x509.Certificate -- x509 certificate
func DecodeBytes ¶
DecodeBytes decodes the supplied buf into a store.
func GenerateECKeySet ¶
GenerateECKeySet generates a EC private and public key crypto primitives, returning them as a Store.
func GenerateRSAKeySet ¶
GenerateRSAKeySet generates a RSA private and public key crypto primitives, returning them as a Store.
func GenerateSymmetricKeySet ¶
GenerateSymmetricKeySet generates a private key crypto primitive, returning it as a Store.
func LoadFile ¶
LoadFile creates a store and loads any crypto primitives in the PEM encoded data stored in filename.
Note: calls Store.AddPublicKeys after successfully loading a file. If that behavior is not desired, please manually create the Store and call Decode, or [DecodeBlock].
func (Store) AddPublicKeys ¶
func (s Store) AddPublicKeys()
AddPublicKeys adds the public keys for a RSAPrivateKey or ECPrivateKey block type generating and storing the corresponding *PublicKey block if not already present.
Useful when a Store is missing the public key for a private key.
func (Store) Bytes ¶
Bytes returns all crypto primitives in the Store as a single byte slice containing the PEM-encoded versions of the crypto primitives.
func (Store) Certificate ¶
func (s Store) Certificate() (*x509.Certificate, bool)
Certificate returns the X509 certificate contained within the Store.
func (Store) Decode ¶
Decode parses and decodes PEM-encoded data from buf, storing any resulting crypto primitives encountered into the Store. The decoded PEM BlockType will be used as the map key for each primitive.
func (Store) DecodeBlock ¶
DecodeBlock decodes PEM block data, adding any crypto primitive encountered in the Store.
func (Store) ECPrivateKey ¶
func (s Store) ECPrivateKey() (*ecdsa.PrivateKey, bool)
ECPrivateKey returns the ECDSA private key contained within the Store.
func (Store) ECPublicKey ¶
ECPublicKey returns the ECDSA public key contained within the Store.
func (Store) PrivateKey ¶
func (s Store) PrivateKey() (crypto.PrivateKey, bool)
PrivateKey returns the private key contained within the Store.
func (Store) RSAPrivateKey ¶
func (s Store) RSAPrivateKey() (*rsa.PrivateKey, bool)
RSAPrivateKey returns the RSA private key contained within the Store.
func (Store) RSAPublicKey ¶
RSAPublicKey returns the RSA public key contained within the Store.
Directories
¶
Path | Synopsis |
---|---|
_example/main.go
|
_example/main.go |
cmd
|
|
pemutil
Command pemutil is a simple command line util making to generate suitable keyset data for use with the pemutil package.
|
Command pemutil is a simple command line util making to generate suitable keyset data for use with the pemutil package. |