Overview

Package pem implements the PEM data encoding, which originated in Privacy
Enhanced Mail. The most common use of PEM encoding today is in TLS keys and
certificates. See RFC 1421.

pem.go

func

Encode writes the PEM encoding of b to out.

  1. Type: "MESSAGE",
  2. Headers: map[string]string{
  3. "Animal": "Gopher",
  4. },
  5. }
  6. if err := pem.Encode(os.Stdout, block); err != nil {
  7. log.Fatal(err)
  8. }
  9. // -----BEGIN MESSAGE-----
  10. // Animal: Gopher
  11. //
  12. // dGVzdA==
  13. // -----END MESSAGE-----

EncodeToMemory returns the PEM encoding of b.

If b has invalid headers and cannot be encoded, EncodeToMemory returns nil. If
it is important to report details about this error case, use Encode instead.

type

  1. type Block struct {
  2. Type // The type, taken from the preamble (i.e. "RSA PRIVATE KEY").
  3. Headers map[string] // Optional headers.
  4. Bytes []byte // The decoded bytes of the contents. Typically a DER encoded ASN.1 structure.
  5. }

The encoded form is:

where Headers is a possibly empty sequence of Key: Value lines.

    Decode will find the next PEM formatted block (certificate, private key etc) in
    the input. It returns that block and the remainder of the input. If no PEM data
    is found, p is nil and the whole of the input is returned in rest.


    Example: