Created
July 18, 2016 16:59
-
-
Save bifurcation/d4c9e9f72f3322ae329922256d47e33b to your computer and use it in GitHub Desktop.
A quick script to generate CSRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a simple script to generate test CSRs. | |
package main | |
import ( | |
"crypto/rand" | |
"crypto/rsa" | |
"crypto/x509" | |
"crypto/x509/pkix" | |
"encoding/asn1" | |
"encoding/pem" | |
"fmt" | |
"io/ioutil" | |
) | |
func main() { | |
priv, err := rsa.GenerateKey(rand.Reader, 2048) | |
if err != nil { | |
fmt.Println("could not generate key") | |
return | |
} | |
template := &x509.CertificateRequest{ | |
SignatureAlgorithm: x509.SHA1WithRSA, | |
Subject: pkix.Name{ | |
CommonName: "not-example.com", | |
}, | |
DNSNames: []string{ | |
"not-example.com", | |
"www.not-example.com", | |
}, | |
} | |
csrDER, err := x509.CreateCertificateRequest(rand.Reader, template, priv) | |
if err != nil { | |
fmt.Println("could not generate CSR") | |
return | |
} | |
csrPEM := pem.EncodeToMemory(&pem.Block{ | |
Type: "CERTIFICATE REQUEST", | |
Bytes: csrDER, | |
}) | |
ioutil.WriteFile("test.pem", csrPEM, 0666) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment