I'm trying to convert some values to ASN.1 format based on some examples, but I haven't success to understand some pieces of my example ASN.1 values...
First, I have the following ASN.1 value: 13024252
This value using in string format is: BR
BR in hex is the last part of the ASN.1 value: 4252
What's the 1302?
The second example is very similar:
ASN.1 value: 130d31333335333233363030313839
This value using in string format is: 1335323600189
1335323600189 in hex is the last part of the ASN.1 value: 31333335333233363030313839
What's the 130d?
I have to encode my string values because I have to create a subject_dn for a cert and some parts of the subject_dn is in ASN.1 format. Using node-forge I can have the attribute values in string format, but couldn't convert them to ASN.1 format.
What's the 1302?
13
(in hex) is ASN.1 type -- PrintableString
02
(in hex) is type content length in bytes. 2 bytes. Next two bytes are type value (a string in your case). Same with your second example.
ASN.1 types are encoded using TLV (tag-length-value) structures. You can read more about this here: DER Transfer Syntax.
Keep in mind that distinguished name is a more complex structure, it is a SEQUENCE OF RelativeDistinguishedName, which in turn is a SET OF AttributeTypeAndValue:
DistinguishedName ::= RDNSequence
RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
RelativeDistinguishedName ::= SET SIZE (1..MAX) OF
AttributeTypeAndValue
AttributeTypeAndValue ::= SEQUENCE {
type AttributeType,
value AttributeValue }
Full schema in X.501 InformationalFramework