Created
December 13, 2013 23:47
-
-
Save titanous/7953648 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"crypto/rand" | |
"crypto/rsa" | |
"crypto/x509" | |
"crypto/x509/pkix" | |
"encoding/pem" | |
"fmt" | |
"math" | |
"math/big" | |
"os" | |
"time" | |
) | |
func main() { | |
key, _ := rsa.GenerateKey(rand.Reader, 2048) | |
cert := &x509.Certificate{ | |
Subject: pkix.Name{CommonName: "notary"}, | |
NotBefore: time.Now(), | |
NotAfter: time.Now().Add(time.Hour * 24 * 365 * 10), | |
IsCA: true, | |
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, | |
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, | |
BasicConstraintsValid: true, | |
} | |
cert.SerialNumber, _ = rand.Int(rand.Reader, big.NewInt(math.MaxInt64)) | |
certBytes, err := x509.CreateCertificate(rand.Reader, cert, cert, &key.PublicKey, key) | |
if err != nil { | |
fmt.Fprintln(os.Stderr, err) | |
os.Exit(1) | |
} | |
pem.Encode(os.Stdout, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)}) | |
pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment