A Go package that provides a light wrapper to load PEM-encoded data, meant to ease the loading, parsing and decoding of PEM data into standard crypto primitives.
Install the package via the following:
$ go get -u github.com/kenshaw/pemutil
Please see the GoDoc API page for a full API listing.
The pemutil package can be used similarly to the following:
// _example/main.go
package main
//go:generate openssl genrsa -out rsa-private.pem 2048
//go:generate openssl rsa -in rsa-private.pem -outform PEM -pubout -out rsa-public.pem
import (
"log"
"os"
"github.com/kenshaw/pemutil"
)
func main() {
// create store and load our private key
keyset, err := pemutil.LoadFile("rsa-private.pem")
if err != nil {
log.Fatal(err)
}
// do something with keyset.RSAPrivateKey()
// get pem data and write to disk
buf, err := keyset.Bytes()
if err != nil {
log.Fatal(err)
}
os.Stdout.Write(buf)
}