Class ASN1HEX
ASN.1 DER encoded hexadecimal string utility class
Defined in: asn1hex-1.1.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
ASN1HEX()
ASN.1 DER encoded hexadecimal string utility class
This class provides a parser for hexadecimal string of
DER encoded ASN.1 binary data.
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
ASN1HEX.dump(hexOrObj, flags, idx, indent)
get string of simple ASN.1 dump from hexadecimal ASN.1 data
This method will get an ASN.1 dump from hexadecmal string of ASN.1 DER encoded data. |
| <static> |
ASN1HEX.getByteLengthOfL_AtObj(s, pos)
get byte length for ASN.1 L(length) bytes
|
| <static> |
ASN1HEX.getDecendantHexTLVByNthList(h, currentIndex, nthList)
get hexadecimal string of ASN.1 TLV refered by current index and nth index list.
|
| <static> |
ASN1HEX.getDecendantHexVByNthList(h, currentIndex, nthList)
get hexadecimal string of ASN.1 V refered by current index and nth index list.
|
| <static> |
ASN1HEX.getDecendantIndexByNthList(h, currentIndex, nthList)
get string index of nth child object of ASN.1 object refered by h, idx
|
| <static> |
ASN1HEX.getHexOfL_AtObj(s, pos)
get hexadecimal string for ASN.1 L(length) bytes
|
| <static> |
ASN1HEX.getHexOfTLV_AtObj(s, pos)
get hexadecimal string of ASN.1 TLV at
|
| <static> |
ASN1HEX.getHexOfV_AtObj(s, pos)
get hexadecimal string of ASN.1 V(value)
|
| <static> |
ASN1HEX.getIntOfL_AtObj(s, pos)
get integer value of ASN.1 length for ASN.1 data
|
| <static> |
ASN1HEX.getNthChildIndex_AtObj(h, idx, nth)
get string index of nth child object of ASN.1 object refered by h, idx
|
| <static> |
ASN1HEX.getPosArrayOfChildren_AtObj(h, pos)
get array of string indexes of child ASN.1 objects
This method returns array of integers for a concatination of ASN.1 objects in a ASN.1 value. |
| <static> |
ASN1HEX.getPosOfNextSibling_AtObj(s, pos)
get next sibling starting index for ASN.1 object string
|
| <static> |
ASN1HEX.getStartPosOfV_AtObj(s, pos)
get ASN.1 value starting string position for ASN.1 object refered by index 'idx'.
|
| <static> |
ASN1HEX.getVbyList(h, currentIndex, nthList, checkingTag)
get ASN.1 value by nthList
This static method is to get a ASN.1 value which specified "nthList" position with checking expected tag "checkingTag". |
| <static> |
ASN1HEX.hextooidstr(hex)
get OID string from hexadecimal encoded value
|
| <static> |
ASN1HEX.isASN1HEX(hex)
check wheather the string is ASN.1 hexadecimal string or not
This method checks wheather the argument 'hex' is a hexadecimal string of
ASN.1 data or not.
|
| <static> |
ASN1HEX.pemToHex(s, sHead)
get hexacedimal string from PEM format data
This static method gets a hexacedimal string of contents from PEM format data. |
Class Detail
ASN1HEX()
ASN.1 DER encoded hexadecimal string utility class
This class provides a parser for hexadecimal string of
DER encoded ASN.1 binary data.
Here are major methods of this class.
- ACCESS BY POSITION
- ASN1HEX.getHexOfTLV_AtObj - get ASN.1 TLV at specified position
- ASN1HEX.getHexOfV_AtObj - get ASN.1 V at specified position
- ASN1HEX.getHexOfL_AtObj - get hexadecimal ASN.1 L at specified position
- ASN1HEX.getIntOfL_AtObj - get integer ASN.1 L at specified position
- ASN1HEX.getStartPosOfV_AtObj - get ASN.1 V position from its ASN.1 TLV position
- ACCESS FOR CHILD ITEM
- ASN1HEX.getNthChildIndex_AtObj - get nth child index at specified position
- ASN1HEX.getPosArrayOfChildren_AtObj - get indexes of children
- ASN1HEX.getPosOfNextSibling_AtObj - get position of next sibling
- ACCESS NESTED ASN.1 STRUCTURE
- ASN1HEX.getVbyList - get ASN.1 V at specified nth list index with checking expected tag
- ASN1HEX.getDecendantHexTLVByNthList - get ASN.1 TLV at specified list index
- ASN1HEX.getDecendantHexVByNthList - get ASN.1 V at specified list index
- ASN1HEX.getDecendantIndexByNthList - get index at specified list index
- UTILITIES
- ASN1HEX.dump - dump ASN.1 structure
- ASN1HEX.isASN1HEX - check whether ASN.1 hexadecimal string or not
- ASN1HEX.hextooidstr - convert hexadecimal string of OID to dotted integer list
- Since:
- jsrsasign 1.1
Method Detail
<static>
{String}
ASN1HEX.dump(hexOrObj, flags, idx, indent)
get string of simple ASN.1 dump from hexadecimal ASN.1 data
This method will get an ASN.1 dump from hexadecmal string of ASN.1 DER encoded data. Here are features:
This method will get an ASN.1 dump from hexadecmal string of ASN.1 DER encoded data. Here are features:
- ommit long hexadecimal string
- dump encapsulated OCTET STRING (good for X.509v3 extensions)
- structured/primitive context specific tag support (i.e. [0], [3] ...)
- automatic decode for implicit primitive context specific tag
(good for X.509v3 extension value)
- if hex starts '68747470'(i.e. http) it is decoded as utf8 encoded string.
- if it is in 'subjectAltName' extension value and is '[2]'(dNSName) tag value will be encoded as utf8 string
- otherwise it shows as hexadecimal string
// 1) ASN.1 INTEGER
ASN1HEX.dump('0203012345')
↓
INTEGER 012345
// 2) ASN.1 Object Identifier
ASN1HEX.dump('06052b0e03021a')
↓
ObjectIdentifier sha1 (1 3 14 3 2 26)
// 3) ASN.1 SEQUENCE
ASN1HEX.dump('3006020101020102')
↓
SEQUENCE
INTEGER 01
INTEGER 02
// 4) ASN.1 SEQUENCE since jsrsasign 6.2.4
o = KJUR.asn1.ASN1Util.newObject({seq: [{int: 1}, {int: 2}]});
ASN1HEX.dump(o)
↓
SEQUENCE
INTEGER 01
INTEGER 02
// 5) ASN.1 DUMP FOR X.509 CERTIFICATE
ASN1HEX.dump(ASN1HEX.pemToHex(certPEM))
↓
SEQUENCE
SEQUENCE
[0]
INTEGER 02
INTEGER 0c009310d206dbe337553580118ddc87
SEQUENCE
ObjectIdentifier SHA256withRSA (1 2 840 113549 1 1 11)
NULL
SEQUENCE
SET
SEQUENCE
ObjectIdentifier countryName (2 5 4 6)
PrintableString 'US'
:
- Parameters:
- {Object} hexOrObj
- hexadecmal string of ASN.1 data or ASN1Object object
- {Array} flags
- associative array of flags for dump (OPTION)
- {Number} idx
- string index for starting dump (OPTION)
- {String} indent
- indent string (OPTION)
- Since:
- jsrsasign 4.8.3 asn1hex 1.1.6
- Returns:
- {String} string of simple ASN.1 dump
<static>
ASN1HEX.getByteLengthOfL_AtObj(s, pos)
get byte length for ASN.1 L(length) bytes
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
- Returns:
- byte length for ASN.1 L(length) bytes
<static>
{Number}
ASN1HEX.getDecendantHexTLVByNthList(h, currentIndex, nthList)
get hexadecimal string of ASN.1 TLV refered by current index and nth index list.
- Parameters:
- {String} h
- hexadecimal string of ASN.1 DER encoded data
- {Number} currentIndex
- start string index of ASN.1 object
- {Array of Number} nthList
- array list of nth
- Since:
- 1.1
- Returns:
- {Number} hexadecimal string of ASN.1 TLV refered by nthList
<static>
{Number}
ASN1HEX.getDecendantHexVByNthList(h, currentIndex, nthList)
get hexadecimal string of ASN.1 V refered by current index and nth index list.
- Parameters:
- {String} h
- hexadecimal string of ASN.1 DER encoded data
- {Number} currentIndex
- start string index of ASN.1 object
- {Array of Number} nthList
- array list of nth
- Since:
- 1.1
- Returns:
- {Number} hexadecimal string of ASN.1 V refered by nthList
<static>
{Number}
ASN1HEX.getDecendantIndexByNthList(h, currentIndex, nthList)
get string index of nth child object of ASN.1 object refered by h, idx
The "nthList" is a index list of structured ASN.1 object
reference. Here is a sample structure and "nthList"s which
refers each objects.
SQUENCE -
SEQUENCE - [0]
IA5STRING 000 - [0, 0]
UTF8STRING 001 - [0, 1]
SET - [1]
IA5STRING 010 - [1, 0]
UTF8STRING 011 - [1, 1]
- Parameters:
- {String} h
- hexadecimal string of ASN.1 DER encoded data
- {Number} currentIndex
- start string index of ASN.1 object
- {Array of Number} nthList
- array list of nth
- Since:
- 1.1
- Returns:
- {Number} string index refered by nthList
<static>
{String}
ASN1HEX.getHexOfL_AtObj(s, pos)
get hexadecimal string for ASN.1 L(length) bytes
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
- Returns:
- {String} hexadecimal string for ASN.1 L(length) bytes
<static>
{String}
ASN1HEX.getHexOfTLV_AtObj(s, pos)
get hexadecimal string of ASN.1 TLV at
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
- Since:
- asn1hex 1.1
- Returns:
- {String} hexadecimal string of ASN.1 TLV.
<static>
{String}
ASN1HEX.getHexOfV_AtObj(s, pos)
get hexadecimal string of ASN.1 V(value)
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
- Returns:
- {String} hexadecimal string of ASN.1 value.
<static>
ASN1HEX.getIntOfL_AtObj(s, pos)
get integer value of ASN.1 length for ASN.1 data
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
- Returns:
- ASN.1 L(length) integer value
<static>
{Number}
ASN1HEX.getNthChildIndex_AtObj(h, idx, nth)
get string index of nth child object of ASN.1 object refered by h, idx
- Parameters:
- {String} h
- hexadecimal string of ASN.1 DER encoded data
- {Number} idx
- start string index of ASN.1 object
- {Number} nth
- for child
- Since:
- 1.1
- Returns:
- {Number} string index of nth child.
<static>
{Array of Number}
ASN1HEX.getPosArrayOfChildren_AtObj(h, pos)
get array of string indexes of child ASN.1 objects
This method returns array of integers for a concatination of ASN.1 objects in a ASN.1 value. As for BITSTRING, one byte of unusedbits is skipped. As for other ASN.1 simple types such as INTEGER, OCTET STRING or PRINTABLE STRING, it returns a array of a string index of its ASN.1 value.
NOTE: Since asn1hex 1.1.7 of jsrsasign 6.1.2, Encapsulated BitString is supported.
This method returns array of integers for a concatination of ASN.1 objects in a ASN.1 value. As for BITSTRING, one byte of unusedbits is skipped. As for other ASN.1 simple types such as INTEGER, OCTET STRING or PRINTABLE STRING, it returns a array of a string index of its ASN.1 value.
NOTE: Since asn1hex 1.1.7 of jsrsasign 6.1.2, Encapsulated BitString is supported.
ASN1HEX.getPosArrayOfChildren_AtObj("0203012345", 0) ⇒ [4] // INTEGER 012345
ASN1HEX.getPosArrayOfChildren_AtObj("1303616161", 0) ⇒ [4] // PrintableString aaa
ASN1HEX.getPosArrayOfChildren_AtObj("030300ffff", 0) ⇒ [6] // BITSTRING ffff (unusedbits=00a)
ASN1HEX.getPosArrayOfChildren_AtObj("3006020104020105", 0) ⇒ [4, 10] // SEQUENCE(INT4,INT5)
- Parameters:
- {String} h
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- start string index of ASN.1 object
- Returns:
- {Array of Number} array of indexes for childen of ASN.1 objects
<static>
ASN1HEX.getPosOfNextSibling_AtObj(s, pos)
get next sibling starting index for ASN.1 object string
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
- Returns:
- next sibling starting index for ASN.1 object string
<static>
ASN1HEX.getStartPosOfV_AtObj(s, pos)
get ASN.1 value starting string position for ASN.1 object refered by index 'idx'.
- Parameters:
- {String} s
- hexadecimal string of ASN.1 DER encoded data
- {Number} pos
- string index
<static>
ASN1HEX.getVbyList(h, currentIndex, nthList, checkingTag)
get ASN.1 value by nthList
This static method is to get a ASN.1 value which specified "nthList" position with checking expected tag "checkingTag".
This static method is to get a ASN.1 value which specified "nthList" position with checking expected tag "checkingTag".
- Parameters:
- {String} h
- hexadecimal string of ASN.1 structure
- {Integer} currentIndex
- string index to start searching in hexadecimal string "h"
- {Array} nthList
- array of nth list index
- {String} checkingTag
- (OPTIONAL) string of expected ASN.1 tag for nthList
- Since:
- asn1hex 1.1.4
<static>
{String}
ASN1HEX.hextooidstr(hex)
get OID string from hexadecimal encoded value
- Parameters:
- {String} hex
- hexadecmal string of ASN.1 DER encoded OID value
- Since:
- asn1hex 1.1.5
- Returns:
- {String} OID string (ex. '1.2.3.4.567')
<static>
{Boolean}
ASN1HEX.isASN1HEX(hex)
check wheather the string is ASN.1 hexadecimal string or not
This method checks wheather the argument 'hex' is a hexadecimal string of
ASN.1 data or not.
ASN1HEX.isASN1HEX('0203012345') → true // PROPER ASN.1 INTEGER
ASN1HEX.isASN1HEX('0203012345ff') → false // TOO LONG VALUE
ASN1HEX.isASN1HEX('02030123') → false // TOO SHORT VALUE
ASN1HEX.isASN1HEX('fa3bcd') → false // WRONG FOR ASN.1
- Parameters:
- {String} hex
- string to check whether it is hexadecmal string for ASN.1 DER or not
- Since:
- jsrsasign 4.8.3 asn1hex 1.1.6
- Returns:
- {Boolean} true if it is hexadecimal string of ASN.1 data otherwise false
<static>
{String}
ASN1HEX.pemToHex(s, sHead)
get hexacedimal string from PEM format data
This static method gets a hexacedimal string of contents from PEM format data. You can explicitly specify PEM header by sHead argument. Any space characters such as white space or new line will be omitted.
NOTE: Now KEYUTIL.getHexFromPEM and X509.pemToHex have been deprecated since jsrsasign 7.0.1. Please use this method instead.
This static method gets a hexacedimal string of contents from PEM format data. You can explicitly specify PEM header by sHead argument. Any space characters such as white space or new line will be omitted.
NOTE: Now KEYUTIL.getHexFromPEM and X509.pemToHex have been deprecated since jsrsasign 7.0.1. Please use this method instead.
ASN1HEX.pemToHex("-----BEGIN PUBLIC KEY...") → "3082..."
ASN1HEX.pemToHex("-----BEGIN CERTIFICATE...", "CERTIFICATE") → "3082..."
ASN1HEX.pemToHex(" \r\n-----BEGIN DSA PRIVATE KEY...") → "3082..."
- Parameters:
- {String} s
- PEM formatted string
- {String} sHead
- PEM header string without BEGIN/END(OPTION)
- Since:
- jsrsasign 7.0.1 asn1hex 1.1.9
- Returns:
- {String} hexadecimal string data of PEM contents