Golang crypto/x509/pkix.Name type example

package crypto/x509/pkix

Name represents an X.509 distinguished name. This only includes the common elements of a DN. Additional elements in the name are ignored.

Golang crypto/x509/pkix.Name type usage example

 template := x509.Certificate {

 Subject : pkix.Name{
 Country : []string{"Earth"},
 Organization: []string{"Mother Nature"},
 OrganizationalUnit: []string{"Solar System"},
 Locality: []string{""},
 Province: []string{""},
 StreetAddress: []string{"Solar System"},
 PostalCode: []string{"Planet # 3"},
 SerialNumber: "123",
 CommonName: "Gaia",
 },

 IsCA : true,
 BasicConstraintsValid : true,
 SubjectKeyId : []byte{1,2,3},
 SerialNumber : big.NewInt(1234),
 NotBefore : time.Now(),
 NotAfter : time.Now().AddDate(5,5,5),
 // see http://golang.org/pkg/crypto/x509/#KeyUsage
 ExtKeyUsage : []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
 KeyUsage : x509.KeyUsageDigitalSignature|x509.KeyUsageCertSign,
 }

Reference :

https://www.socketloop.com/references/golang-crypto-x509-certpool-addcert-function-example

http://golang.org/pkg/crypto/x509/pkix/#Name

Advertisement