Golang crypto/x509.CreateCertificateRequest function example
package crypto/x509
CreateCertificateRequest creates a new certificate based on a template. The following members of template are used: Subject, Attributes, SignatureAlgorithm, Extension, DNSNames, EmailAddresses, and IPAddresses. The private key is the private key of the signer.
The returned slice is the certificate request in DER encoding.
The only supported key types are RSA (rsa.PrivateKey) and ECDSA (ecdsa.PrivateKey).
Golang crypto/x509.CreateCertificateRequest function usage example
// populate some dummy data.
// see CertificateRequest full structure at
// http://golang.org/pkg/crypto/x509/#CertificateRequest
template := &x509.CertificateRequest {
Signature : []byte("Hello World Signature"),
SignatureAlgorithm : 2, // http://golang.org/pkg/crypto/x509/#SignatureAlgorithm
Subject : pkix.Name{
Country : []string{"Earth"},
Organization: []string{"Mother Nature"},
},
DNSNames : []string{"example.abc123.com"},
EmailAddresses : []string{"admin@abc123.com"},
IPAddresses : []net.IP{net.IPv4(127, 0, 0, 1).To4(), net.ParseIP("2001:1234:0:2001::56")},
}
// generate private key
privatekey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
fmt.Println(err)
}
cert, err := x509.CreateCertificateRequest(rand.Reader, template, privatekey)
if err != nil {
fmt.Println(err)
}
Reference :
Advertisement
Something interesting
Tutorials
+29.5k Golang : How to create new XML file ?
+7.5k Golang : Handling Yes No Quit query input
+17.7k Golang : [json: cannot unmarshal object into Go value of type]
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+28.6k Get file path of temporary file in Go
+11.5k Golang : Generate DSA private, public key and PEM files example
+19.3k Golang : Get host name or domain name from IP address
+10k Golang : Get escape characters \u form from unicode characters
+5.4k Golang *File points to a file or directory ?
+17.3k Golang : How to tell if a file is compressed either gzip or zip ?
+44.9k Golang : Use wildcard patterns with filepath.Glob() example