Golang crypto/x509/pkix.AttributeTypeAndValue type example

package crypto/x509/pkix

AlgorithmIdentifier represents the ASN.1 structure of the same name. See RFC 5280, section 4.1.1.2.

Golang crypto/x509/pkix.AttributeTypeAndValue type usage example

 import "encoding/asn1"

 ...

 var publicKeyBytes []byte
 var (
 oidRsa = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}
 oidEcdsa = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}
 )
 ....

 cert, err = asn1.Marshal(certificate{
  Validity: validity{
 NotBefore: time.Now(),
 NotAfter:  time.Date(2049, 12, 31, 23, 59, 59, 0, time.UTC), 
  },
  Subject: []pkix.AttributeTypeAndValue{{
 Type:  asn1.ObjectIdentifier{1, 2, 3, 4},
 Value: "example",
  }},
  SubjectPublicKeyInfo: subjectPublicKeyInfo{

 // see http://golang.org/pkg/crypto/x509/pkix/#AlgorithmIdentifier
 AlgorithmIdentifier: pkix.AlgorithmIdentifier{
 Algorithm: oidRsa,
 Parameters: asn1.RawValue{
 Tag: 5,
 },
 },
 Bytes: asn1.BitString{
 Bytes: publicKeyBytes,
 BitLength: 8 * len(publicKeyBytes),
 },
  },
 })

Reference :

https://www.socketloop.com/references/golang-crypto-x509-pkix-algorithmidentifier-type-example

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

Advertisement