Create a CSR

I can create CSR in Go as below, is there something similar in Mojo
package main

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
)

func main() {
// Generate a new private key.
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Println(err)
return
}

// Create a simple template for the CSR.
csrTemplate := x509.CertificateRequest{
Subject: pkix.Name{
CommonName: "example.com",
Organization: []string{"Example, LLC"},
},
SignatureAlgorithm: x509.SHA256WithRSA,
}

// Create the CSR.
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &csrTemplate, priv)
if err != nil {
fmt.Println(err)
return
}

// PEM encode the CSR.
csrPEM := pem.EncodeToMemory(&pem.Block{
Type: "CERTIFICATE REQUEST",
Bytes: csrBytes,
})

fmt.Printf("%s\n", csrPEM)
}
package main

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
)

func main() {
// Generate a new private key.
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Println(err)
return
}

// Create a simple template for the CSR.
csrTemplate := x509.CertificateRequest{
Subject: pkix.Name{
CommonName: "example.com",
Organization: []string{"Example, LLC"},
},
SignatureAlgorithm: x509.SHA256WithRSA,
}

// Create the CSR.
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &csrTemplate, priv)
if err != nil {
fmt.Println(err)
return
}

// PEM encode the CSR.
csrPEM := pem.EncodeToMemory(&pem.Block{
Type: "CERTIFICATE REQUEST",
Bytes: csrBytes,
})

fmt.Printf("%s\n", csrPEM)
}
1 Reply
Alex Kirchhoff
Alex Kirchhoff13mo ago
Mojo does not include an X.509 library at this time. If you find a way to write it in Python, you can use Mojo's Python interop to generate a CSR that way.
Want results from more Discord servers?
Add your server