Skip to content

Instantly share code, notes, and snippets.

View chackett's full-sized avatar

Conor Hackett chackett

View GitHub Profile
@chackett
chackett / rsa-to-pem.go
Created March 19, 2019 10:40
Create RSA Public Private Keys in PEM format.
privateKey, err := rsa.GenerateKey(rand.Reader,2048)
privKey := pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
})
pubKey := pem.EncodeToMemory(&pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: x509.MarshalPKCS1PublicKey(&privateKey.PublicKey),
})