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
+15.3k nginx: [emerg] unknown directive "ssl"
+18.5k Golang : Send email with attachment
+18.1k Golang : Convert IPv4 address to decimal number(base 10) or integer
+8.5k Linux/Unix : fatal: the Postfix mail system is already running
+10.3k Golang : Embed secret text string into binary(executable) file
+10.1k Golang : Identifying Golang HTTP client request
+20.4k nginx: [emerg] unknown directive "passenger_enabled"
+6.3k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+9.7k Golang : List available AWS regions
+18.2k Golang : Get path name to current directory or folder
+6.8k Get Facebook friends working in same company
+23.7k Find and replace a character in a string in Go