Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeCSR(in []byte) (*x509.CertificateRequest, error)
- func DecodeCertificate(in []byte) (*x509.Certificate, error)
- func DecodePrivateKey(in []byte) (interface{}, error)
- func DecodePublicKey(in []byte) (interface{}, error)
- func EncodeCSR(c *x509.CertificateRequest) ([]byte, error)
- func EncodeCertificate(c *x509.Certificate) ([]byte, error)
- func EncodePrivateKey(key interface{}) ([]byte, error)
- func EncodePublicKey(key interface{}) ([]byte, error)
- func ParsePrivateKey(block *pem.Block) (interface{}, error)
- func ParsePublicKey(block *pem.Block) (interface{}, error)
- type Block
- type Reader
- type Writer
- func (w *Writer) Close() error
- func (w *Writer) Encode(block *pem.Block) error
- func (w *Writer) EncodeCSR(c *x509.CertificateRequest) error
- func (w *Writer) EncodeCertificate(c *x509.Certificate) error
- func (w *Writer) EncodePrivateKey(key interface{}) error
- func (w *Writer) EncodePublicKey(key interface{}) error
- func (w *Writer) Write(p []byte) (int, error)
Constants ¶
const ( BlockPublicKey = "PUBLIC KEY" BlockPrivateKey = "PRIVATE KEY" BlockRSAPublicKey = "RSA PUBLIC KEY" BlockRSAPrivateKey = "RSA PRIVATE KEY" BlockECPrivateKey = "EC PRIVATE KEY" BlockCertificate = "CERTIFICATE" BlockCertificateRequest = "CERTIFICATE REQUEST" )
PEM Block types
Variables ¶
Functions ¶
func DecodeCSR ¶
func DecodeCSR(in []byte) (*x509.CertificateRequest, error)
DecodeCSR from PEM encoded block with type "CERTIFICATE REQUEST"
func DecodeCertificate ¶
func DecodeCertificate(in []byte) (*x509.Certificate, error)
DecodeCertificate from PEM encoded block with type "CERTIFICATE"
func DecodePrivateKey ¶
DecodePrivateKey from a PEM encoded block. If the block type is "EC PRIVATE KEY", then the block is parsed as an EC private key in SEC 1, ASN.1 DER form. If the block is "RSA PRIVATE KEY" then it is decoded as a PKCS 1, ASN.1 DER form. If the block type is "PRIVATE KEY", the block is decoded as a PKCS 8 ASN.1 DER key, if that fails, then the PKCS 1 and EC parsers are tried in that order, before returning an error.
func DecodePublicKey ¶
DecodePublicKey from a PEM encoded block. If the block type is "RSA PUBLIC KEY", then it is deocded as a PKCS 1, ASN.1 DER form. If the block is "PUBLIC KEY", then it is decoded from PKIX ASN1.1 DER form.
func EncodeCSR ¶
func EncodeCSR(c *x509.CertificateRequest) ([]byte, error)
EncodeCSR and write a PEM block with type "CERTIFICATE REQUEST"
func EncodeCertificate ¶
func EncodeCertificate(c *x509.Certificate) ([]byte, error)
EncodeCertificate and write a PEM block with type "CERTIFICATE"
func EncodePrivateKey ¶
EncodePrivateKey as a PKCS8 ASN.1 DER key and write a PEM block with type "PRIVATE KEY"
func EncodePublicKey ¶
EncodePublicKey as a PKIX ASN1.1 DER key and write a PEM block with type "PUBLIC KEY"
func ParsePrivateKey ¶
ParsePrivateKey from PEM block. May return an *ecdsa.PrivateKey, *rsa.PrivateKey, or ed25519.PrivateKey depending on the block type and the x509 parsing method.
func ParsePublicKey ¶
Types ¶
type Block ¶
Block wraps a pem.Block and adds type-specific decoding functions.
func (*Block) DecodeCSR ¶
func (b *Block) DecodeCSR() (*x509.CertificateRequest, error)
DecodeCSR from PEM encoded block with type "CERTIFICATE REQUEST"
func (*Block) DecodeCertificate ¶
func (b *Block) DecodeCertificate() (*x509.Certificate, error)
DecodeCertificate from PEM encoded block with type "CERTIFICATE"
func (*Block) DecodePrivateKey ¶
DecodePrivateKey from a PEM encoded block. If the block type is "EC PRIVATE KEY", then the block is parsed as an EC private key in SEC 1, ASN.1 DER form. If the block is "RSA PRIVATE KEY" then it is decoded as a PKCS 1, ASN.1 DER form. If the block type is "PRIVATE KEY", the block is decoded as a PKCS 8 ASN.1 DER key, if that fails, then the PKCS 1 and EC parsers are tried in that order, before returning an error.
func (*Block) DecodePublicKey ¶
DecodePublicKey from a PEM encoded block. If the block type is "RSA PUBLIC KEY", then it is deocded as a PKCS 1, ASN.1 DER form. If the block is "PUBLIC KEY", then it is decoded from PKIX ASN1.1 DER form.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps an io.ReadCloser in order to decode bytes from the underlying data. As data is decoded from the underlying reader it is freed from memory and cannot be read again. A typical use case is to create a reader to loop over all blocks in the underlying data as though it were an iterator.
func (*Reader) Decode ¶
Decode the next block and move the cursor. If block is nil then no block was able to be decoded and the rest of the data can be read using the Read function.
func (*Reader) Next ¶
Next is used to determine if there is a next block of data that can be read and is typically used for iteration over all of the blocks in a PEM encoded file.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer wraps an io.WriteCloser and allows users to write multiple PEM encoded blocks to the underlying writer. Unlike pem.Encode the writer has type specific encoders to make it easier to write data from different types. This writer is not thread-safe.
func (*Writer) EncodeCSR ¶
func (w *Writer) EncodeCSR(c *x509.CertificateRequest) error
EncodeCSR and write a PEM block with type "CERTIFICATE REQUEST"
func (*Writer) EncodeCertificate ¶
func (w *Writer) EncodeCertificate(c *x509.Certificate) error
EncodeCertificate and write a PEM block with type "CERTIFICATE"
func (*Writer) EncodePrivateKey ¶
EncodePrivateKey as a PKCS8 ASN.1 DER key and write a PEM block with type "PRIVATE KEY"
func (*Writer) EncodePublicKey ¶
EncodePublicKey as a PKIX ASN1.1 DER key and write a PEM block with type "PUBLIC KEY"