### TBSCertList Constructor Example
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1x509-1.0.js.html
Example of initializing a TBSCertList object with parameters for signature algorithm, issuer, and revocation certificates.
```javascript
var o = new KJUR.asn1.x509.TBSCertList({
sigalg: "SHA256withRSA",
issuer: {array: [[{type:'C',value:'JP',ds:'prn'}],
```
--------------------------------
### RSA Key Generation and Signing Test Setup
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-rsasign.html
Initializes RSA key parameters and a sample signature for testing purposes. This setup is used within the QUnit test suite.
```javascript
var k_n = "00d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a0021";
var k_e = "010001";
var k_d = "03dfeadd993a89bd86151a4a0cb3bf3b628c9c07d1f9be1727accc19ea19ecb6e98b7316d0d6b093d72455a5f46551aac5b4885f90afa7fca31c7a70c3e41b505af0fe00a32e28988ccf44f02dee005e40289d2be0604f978bbc2b86e96d7792c5207ad3fc0f40589000955c039c61655cea36e177123b8a747b30f9d93e74f1";
var k_p = "00ee6d7fe55461600ffc58b9c873e7a61ced51d7fb9f015243527b04b3c0945b72e7aa9275d15b08fded25eaa6761f2aa66aefc767105d74496b2bfcd30a8beed7";
var k_q = "00e0f56a0effce6406d6af8b325d936ffcca65e2be6cbb360c3140fd53c076248467ae198664fccbc76dcdf49e21109f9787cb5229573cd233a4aef1a54aff81c7";
var k_dp = "6933ad8c0dd84d5fa053b1ddcdae77b029d2c3ff0560bae073a34e26d6215fdc6a75ebdbca7d65914d333ebf263d883f17ce26e8c5e2c66da2b92cfc1d9a32cf";
var k_dq = "462da9698679ff9076970ae8aa729d64124c18a1695039fb31be618928287319ef324bfa3634fae97b22de261a909208f6af0231ad6a66f4ff72282675b021ef";
var k_co = "40d5f2a22cee18496d8926815f1e07dbd11d5cd6160c9f524b97f4ef40516c022576a461deb70dbe963a04a26a15aa5d6b50e375c9dc64408c8b34ff18cadcd7";
var hSigAAA = "6f7df91d8f973a0619d525c319337741130b77b21f9667dc7d1d74853b644cbe5e6b0e84aacc2faee883d43affb811fc653b67c38203d4f206d1b838c4714b6b2cf17cd621303c21bac96090df3883e58784a0576e501c10cdefb12b6bf887e548f6b07b09ae80d8416151d7dab7066d645e2eee57ac5f7af2a70ee0724c8e47";
var hSigAAAkZ1SHA256 = "c27ebd5c0193244f7d3f08405b6821c2085ee522c630aad3e1a14e4ae2dee034f47e480fb37a729e074f98fb8b70dd387666b4b9def14c3b5e2a814cf13bc6fca24f252f396fdcf0aca55c0ca7782e9d07ca887714761ee0bdb8364a1816c2e43b0ceef5a507b8a939d8bbad1f38ee5dfdd30f04b21eeeb406b9d2d5478fac87"; // "z1.pkcs1.pem"
```
```javascript
var sKey1PEM = "-----BEGIN RSA PRIVATE KEY-----\n" +
"MIICWwIBAAKBgQDRhGF7X4A0ZVlEg594WmODVVUIiiPQs04aLmvfg8SborHss5gQ\n" +
"Xu0aIdUT6nb5rTh5hD2yfpF2WIW6M8z0WxRhwicgXwi80H1aLPf6lEPPLvN29EhQ\n" +
"NjBpkFkAJUbS8uuhJEeKw0cE49g80eBBF4BCqSL6PFQbP9/rByxdxEoAIQIDAQAB\n" +
"AoGAA9/q3Zk6ib2GFRpKDLO/O2KMnAfR+b4XJ6zMGeoZ7Lbpi3MW0Nawk9ckVaX0\n" +
"ZVGqxbSIX5Cvp/yjHHpww+QbUFrw/gCjLiiYjM9E8C3uAF5AKJ0r4GBPl4u8K4bp\n" +
"bXeSxSB60/wPQFiQAJVcA5xhZVzqNuF3EjuKdHsw+dk+dPECQQDubX/lVGFgD/xY\n" +
"uchz56Yc7VHX+58BUkNSewSzwJRbcueqknXRWwj97SXqpnYfKqZq78dnEF10SWsr\n" +
"/NMKi+7XAkEA4PVqDv/OZAbWr4syXZNv/Mpl4r5suzYMMUD9U8B2JIRnrhmGZPzL\n" +
"x23N9J4hEJ+Xh8tSKVc80jOkrvGlSv+BxwJAaTOtjA3YTV+gU7Hdza53sCnSw/8F\n" +
"YLrgc6NOJtYhX9xqdevbyn1lkU0zPr8mPYg/F84m6MXixm2iuSz8HZoyzwJARi2p\n" +
"aYZ5/5B2lwroqnKdZBJMGKFpUDn7Mb5hiSgocxnvMkv6NjT66Xsi3iYakJII9q8C\n" +
"Ma1qZvT/cigmdbAh7wJAQNXyoizuGEltiSaBXx4H29EdXNYWDJ9SS5f070BRbAIl\n" +
"dqRh3rcNvpY6BKJqFapda1DjdcncZECMizT/GMrc1w==\n" +
"-----END RSA PRIVATE KEY-----\n";
```
--------------------------------
### Signature Initialization and Signing (RSA Example)
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.crypto.Signature.html
Demonstrates how to initialize a Signature object with a specific algorithm (SHA1withRSA) and sign a string using a provided private key.
```APIDOC
## KJUR.crypto.Signature
### Description
Initializes a signature object for signing or verifying cryptographic data.
### Method
`new KJUR.crypto.Signature(params)`
### Parameters
#### Constructor Parameters
- **params** (Object) - Parameters for the constructor.
- **alg** (String) - The signature algorithm to use (e.g., "SHA1withRSA").
### Initialization
#### `init(key, pass)`
Initializes the signature object for signing or verifying.
##### Signing
- **key**: A private key in PEM format or a key object (RSAKey, KJUR.crypto.ECDSA, KJUR.crypto.DSA).
- **pass**: (Optional) Password for encrypted keys.
### Signing
#### `updateString(str)`
Updates the signature object with a string to be signed.
#### `sign()`
Generates the signature.
### Request Example
```javascript
// RSA signature generation
var sig = new KJUR.crypto.Signature({"alg": "SHA1withRSA"});
sig.init(prvKeyPEM);
sig.updateString('aaa');
var hSigVal = sig.sign();
```
```
--------------------------------
### ASN1HEX.getVidx
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Gets the starting string position of the ASN.1 value for an ASN.1 object.
```APIDOC
## ASN1HEX.getVidx(s, idx)
### Description
Gets the ASN.1 value starting string position for an ASN.1 object referred to by index 'idx'.
### Parameters
* **s** (string) - The hexadecimal string of ASN.1 data.
* **idx** (number) - The starting index of the ASN.1 object.
### Returns
(number) - The starting index of the ASN.1 value component.
```
--------------------------------
### ASN1HEX.getVidx
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Gets the starting string position for the ASN.1 value of an object referenced by an index.
```APIDOC
## ASN1HEX.getVidx(s, idx)
### Description
Gets the starting string position for the ASN.1 value of an object referenced by an index within a hexadecimal string.
### Parameters
#### Path Parameters
- **s** (String) - Required - hexadecimal string of ASN.1 DER encoded data
- **idx** (Number) - Required - string index
### Returns
- **String** - The starting string position of the ASN.1 value.
```
--------------------------------
### Instantiate TBSCertList with Parameters
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.asn1.x509.TBSCertList.html
Demonstrates how to create a new TBSCertList object by providing parameters as a JSON object. This includes setting signature algorithm, issuer, update times, revoked certificates, and extensions.
```javascript
var o = new KJUR.asn1.x509.TBSCertList({
sigalg: "SHA256withRSA",
issuer: {array: [[{type:'C',value:'JP',ds:'prn'}],
[{type:'O',value:'T1',ds:'prn'}]]},
thisupdate: "200821235959Z",
nextupdate: "200828235959Z", // OPTION
revcert: [
{sn: {hex: "12ab"}, date: "200401235959Z", ext: [{extname: "cRLReason", code:1}]},
{sn: {hex: "12bc"}, date: "200405235959Z", ext: [{extname: "cRLReason", code:2}]}
],
ext: [
{extname: "cRLNumber", num: {'int': 8}},
{extname: "authorityKeyIdentifier", "kid": {hex: "12ab"}}
]
});
o.tohex() → "30..."
```
--------------------------------
### ASN1HEX.getNextSiblingIdx
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Gets the starting index of the next sibling ASN.1 object. This method is deprecated.
```APIDOC
## ASN1HEX.getNextSiblingIdx
### Description
Gets the next sibling starting index for an ASN.1 object string. This method is deprecated.
### Method
`static getNextSiblingIdx(s, idx)`
### Parameters
- **s** (String) - Hexadecimal string of ASN.1 DER encoded data.
- **idx** (Number) - String index.
### Returns
- (Number) Next sibling starting index for the ASN.1 object string.
### Deprecated
- jsrsasign 9.1.5, asn1hex 1.2.5. Please use [ASN1HEX.getTLVblen](../symbols/ASN1HEX.html#.getTLVblen).
### Examples
```javascript
// SEQUENCE { INTEGER 3, INTEGER 4 }
// 3006
// 020103 :idx=4
// 020104 :next sibling idx=10
ASN1HEX.getNextSiblingIdx("3006020103020104", 4) // returns 10
```
```
--------------------------------
### ASN1HEX.getNextSiblingIdx
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Gets the next sibling starting index for an ASN.1 object string (DEPRECATED).
```APIDOC
## ASN1HEX.getNextSiblingIdx(s, idx)
### Description
Gets the next sibling starting index for an ASN.1 object string. This method is DEPRECATED.
### Parameters
* **s** (string) - The hexadecimal string of ASN.1 data.
* **idx** (number) - The starting index of the current ASN.1 object.
### Returns
(number) - The starting index of the next sibling object.
```
--------------------------------
### Initialize TBSCertList with Parameters
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1x509-1.0.js.html
Constructs a TBSCertList object and initializes it with provided parameters. Use this to create a new TBSCertList instance.
```javascript
KJUR.asn1.x509.TBSCertList = function(params) {
KJUR.asn1.x509.TBSCertList.superclass.constructor.call(this);
var _KJUR = KJUR,
_KJUR_asn1 = _KJUR.asn1,
_DERInteger = _KJUR_asn1.DERInteger,
_DERSequence = _KJUR_asn1.DERSequence,
_DERTaggedObject = _KJUR_asn1.DERTaggedObject,
_DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier,
_KJUR_asn1_x509 = _KJUR_asn1.x509,
_AlgorithmIdentifier = _KJUR_asn1_x509.AlgorithmIdentifier,
_Time = _KJUR_asn1_x509.Time,
_Extensions = _KJUR_asn1_x509.Extensions,
_X500Name = _KJUR_asn1_x509.X500Name;
this.params = null;
/**
* get array of ASN.1 object for extensions
* @name setByParam
* @memberOf KJUR.asn1.x509.TBSCertList#
* @function
* @param {Array} JSON object of TBSCertList parameters
* @example
* tbsc = new KJUR.asn1.x509.TBSCertificate();
* tbsc.setByParam({version:3, serial:{hex:'1234...'},...});
*/
this.setByParam = function(params) {
this.params = params;
};
/**
* get DERSequence for revokedCertificates
* @name getRevCertSequence
* @memberOf KJUR.asn1.x509.TBSCertList#
* @function
* @return {@link KJUR.asn1.DERSequence} of revokedCertificates
*/
this.getRevCertSequence = function() {
var a = [];
var aRevCert = this.params.revcert;
for (var i = 0; i < aRevCert.length; i++) {
var aEntry = [
new _DERInteger(aRevCert[i].sn),
new _Time(aRevCert[i].date)
];
if (aRevCert[i].ext != undefined) {
aEntry.push(new _Extensions(aRevCert[i].ext));
}
a.push(new _DERSequence({array: aEntry}));
}
return new _DERSequence({array: a});
};
this.tohex = function() {
var a = [];
var params = this.params;
if (params.version != undefined) {
var version = params.version - 1;
var obj = new _DERInteger({'int': version});
a.push(obj);
}
a.push(new _AlgorithmIdentifier({name: params.sigalg}));
a.push(new _X500Name(params.issuer));
a.push(new _Time(params.thisupdate));
if (params.nextupdate != undefined)
a.push(new _Time(params.nextupdate))
if (params.revcert != undefined) {
a.push(this.getRevCertSequence());
}
if (params.ext != undefined) {
var dExt = new _Extensions(params.ext);
a.push(new _DERTaggedObject({tag:'a0',
explicit:true,
obj:dExt}));
}
var seq = new _DERSequence({array: a});
return seq.tohex();
};
this.getEncodedHex = function() { return this.tohex(); };
if (params !== undefined) this.setByParam(params);
};
```
--------------------------------
### Get JWSJS JSON Object Example
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.jws.JWSJS.html
Shows how to obtain the JSON representation of a JWSJS object after it has been manipulated.
```javascript
jwsj1 = new KJUR.jws.JWSJS();
// do some jwsj1 operation then get result by getJSON()
jwsjsObj1 = jwsjs1.getJSON();
// jwsjsObj1 → { headers: [..."], payload: "ey...", signatures: [...] }
```
--------------------------------
### Signature Initialization and Verification (DSA Example)
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.crypto.Signature.html
Shows how to initialize a Signature object for verification using a specific algorithm (SHA1withDSA) and verify a signature against a public key.
```APIDOC
## KJUR.crypto.Signature
### Description
Initializes a signature object for signing or verifying cryptographic data.
### Method
`new KJUR.crypto.Signature(params)`
### Parameters
#### Constructor Parameters
- **params** (Object) - Parameters for the constructor.
- **alg** (String) - The signature algorithm to use (e.g., "SHA1withDSA").
### Initialization
#### `init(key, pass)`
Initializes the signature object for signing or verifying.
##### Verifying
- **key**: A public key or certificate in PEM format or a key object.
- **pass**: (Optional) Password for encrypted keys.
### Updating Data
#### `updateString(str)`
Updates the signature object with the data to be verified.
### Verification
#### `verify(signature)`
Verifies the provided signature against the updated data and initialized key.
### Request Example
```javascript
// DSA signature validation
var sig2 = new KJUR.crypto.Signature({"alg": "SHA1withDSA"});
sig2.init(certPEM);
sig.updateString('aaa'); // Assuming 'sig' is a previously initialized Signature object
var isValid = sig2.verify(hSigVal); // Assuming 'hSigVal' is the signature to verify
```
```
--------------------------------
### PKIFailureInfo Class Examples
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-asn1tsp.html
Demonstrates the initialization of PKIFailureInfo objects using integer codes, string representations of failure reasons, or an array of reasons. Shows encoding for various failure scenarios.
```javascript
var o;
o = new KJUR.asn1.tsp.PKIFailureInfo(0);
equal(o.getEncodedHex(), "03020780", "0");
o = new KJUR.asn1.tsp.PKIFailureInfo(2);
equal(o.getEncodedHex(), "03020520", "2");
o = new KJUR.asn1.tsp.PKIFailureInfo(25);
equal(o.getEncodedHex(), "03050600000040", "25");
o = new KJUR.asn1.tsp.PKIFailureInfo('badAlg');
equal(o.getEncodedHex(), "03020780", "badAlg");
o = new KJUR.asn1.tsp.PKIFailureInfo('badRequest');
equal(o.getEncodedHex(), "03020520", "badRequest");
o = new KJUR.asn1.tsp.PKIFailureInfo('systemFailure');
equal(o.getEncodedHex(), "03050600000040", "systemFailure");
o = new KJUR.asn1.tsp.PKIFailureInfo(['badAlg','badRequest']);
equal(o.getEncodedHex(), "030205a0", "[badAlg,badRequest]");
o = new KJUR.asn1.tsp.PKIFailureInfo(['badAlg','badRequest','systemFailure']);
equal(o.getEncodedHex(), "030506a0000040", "[badAlg,b
```
--------------------------------
### Get ASN.1 TLV Hex String
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Retrieves the hexadecimal string of an ASN.1 Tag-Length-Value (TLV) structure starting at a specified index.
```javascript
ASN1HEX.getTLV(s, idx)
```
--------------------------------
### Get ASN.1 TLV (getTLV)
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1hex-1.1.js.html
Constructs and returns the complete hexadecimal string of an ASN.1 TLV (Tag-Length-Value) structure starting from the specified index.
```javascript
ASN1HEX.getTLV = function(s, idx) {
return s.substr(idx, 2) + ASN1HEX.getL(s, idx) + ASN1HEX.getV(s, idx);
};
```
--------------------------------
### Initialize and Use JWSJS
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.jws.JWSJS.html
Demonstrates initializing a JWSJS object, reading existing JWSJS data, adding signatures with different algorithms and keys, and retrieving the final JSON object.
```javascript
// initialize
jwsjs1 = new KJUR.jws.JWSJS();
jwsjs1.readJWSJS("{headers: [..."], payload: "eyJ...", signatures: [...]}");
// add PS256 signature with RSA private key object
prvKeyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
jwsjs1.addSignature("PS256", {alg: "PS256"}, prvKeyObj);
// add HS256 signature with HMAC password "secret"
jwsjs1.addSignature(null, {alg: "HS256"}, {utf8: "secret"});
// get result finally
jwsjsObj1 = jwsjs1.getJSON();
```
--------------------------------
### Get Nth Child Index
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Finds the string index of the nth child ASN.1 object within a parent object specified by its starting index.
```javascript
ASN1HEX.getNthChildIdx(h, idx, nth)
```
--------------------------------
### Get Hash Length
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.crypto.MessageDigest.html
Access the static HASHLENGTH property to retrieve the byte length of a hash for a specific algorithm. For example, SHA-1 produces a 20-byte hash.
```javascript
KJUR.crypto.MessageDigest.HASHLENGTH['sha1'] &rarr 20
```
```javascript
KJUR.crypto.MessageDigest.HASHLENGTH['sha512'] &rarr 64
```
--------------------------------
### Instantiate KJUR.asn1.ocsp.TBSRequest
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.asn1.ocsp.TBSRequest.html
Demonstrates default instantiation and instantiation with a request list parameter. Use the constructor with the 'reqList' parameter to pre-populate the request list.
```javascript
o = new KJUR.asn1.ocsp.TBSRequest();
o = new KJUR.asn1.ocsp.TBSRequest({
reqList:[
{issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg:},
{issuerCert: "-----BEGIN...", subjectCert: "-----BEGIN...", alg: "sha256"}
]
});
```
--------------------------------
### Instantiate KJUR.asn1.x509.UserNotice
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.asn1.x509.UserNotice.html
Demonstrates how to instantiate the UserNotice class with both noticeref and exptext parameters. The noticeref parameter requires a KJUR.asn1.x509.NoticeReference object, while exptext takes a KJUR.asn1.x509.DisplayText object.
```javascript
new UserNotice({
noticeref: {
org: {type: "bmp", str: "Sample Org"},
noticenum: [{int: 3}, {hex: "01af"}]
},
exptext: {type: "ia5", str: "Sample Policy"}
})
```
--------------------------------
### FlexSlider Initialization
Source: https://github.com/kjur/jsrsasign/blob/master/sample/index.html
Initializes the FlexSlider plugin for creating image carousels or sliders. This example uses a 'slide' animation and removes a 'loading' class from the body on start.
```javascript
$(window).load(function(){ $('.flexslider').flexslider({ animation: "slide", start: function(slider){ $('body').removeClass('loading'); } }); });
```
--------------------------------
### Get Next Sibling Index (Deprecated)
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/ASN1HEX.html
Retrieves the starting index of the next sibling ASN.1 object. This method is deprecated and users should use getTLVblen instead.
```javascript
getNextSiblingIdx("3006020103020104", 4) → 10
```
--------------------------------
### Initialize Mac with Password
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.crypto.Mac.html
Demonstrates setting the password for a Mac instance using an explicit Base64URL string. This is useful when the password is provided in a specific encoded format.
```javascript
mac.setPassword({"b64u": "Mb-c3f_"});
```
--------------------------------
### Get JWK Thumbprint Example
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.jws.JWS.html
Calculates the JWK thumbprint for a given JWK object according to RFC 7638. Supports RSA, EC, and oct key types.
```javascript
jwk = {"kty":"RSA", "n":"0vx...", "e":"AQAB", ...};
thumbprint = KJUR.jws.JWS.getJWKthumbprint(jwk);
```
--------------------------------
### X509 Constructor
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/X509.html
Initializes a new instance of the X509 class with optional parameters.
```APIDOC
## X509(params)
### Description
Constructor for the X509 class. Initializes a hexadecimal X.509 certificate ASN.1 parser.
### Parameters
#### Path Parameters
- **params** (object) - Optional - Parameters for initializing the X509 object.
### Method
(Not specified, assumed to be a constructor call)
### Endpoint
(Not applicable for SDK method)
### Request Example
(Not applicable for SDK method)
### Response
(Not specified)
```
--------------------------------
### X500Name Constructor Examples
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-asn1x509.html
Demonstrates various ways to construct an X500Name object using different formats and rules.
```javascript
o = new KJUR.asn1.x509.X500Name({'C': 'US', 'O': 'aaa'}); equal(o.getEncodedHex(), "301b310b3009060355040613025553310c300a060355040a0c03616161", "constructor obj C:US, O:aaa");
```
```javascript
o = new KJUR.asn1.x509.X500Name({'C': 'US', 'O': 'aa/'}); equal(o.getEncodedHex(), "301b310b3009060355040613025553310c300a060355040a0c0361612f", "constructor obj C:US, O:aa/");
```
```javascript
o = new KJUR.asn1.x509.X500Name({'str': '/O=a/O=b/b/O=c/c/c'}); equal(o.getEncodedHex(), "302a310a3008060355040a0c0161310c300a060355040a0c03622f62310e300c060355040a0c05632f632f63", "constructor str /O=a/O=b/b/O=c/c/c");
```
```javascript
o = new KJUR.asn1.x509.X500Name({str:'/O=a/O=b',rule:'prn'}); equal(o.getEncodedHex(), "3018310a3008060355040a130161310a3008060355040a130162", "constructor /O=a/O=b rule=prn");
```
```javascript
o = new KJUR.asn1.x509.X500Name({str:'/C=JP/O=b/CN=a@a.jp',rule:'prn'}); equal(o.getEncodedHex(), "302a310b3009060355040613024a50310a3008060355040a130162310f300d060355040316066140612e6a70", "constructor /C=JP/O=b/CN=a@a.jp rule=prn");
```
```javascript
o = new KJUR.asn1.x509.X500Name({str:'/C=JP/O=b/CN=a@a.jp'}); equal(o.getEncodedHex(), "302a310b3009060355040613024a50310a3008060355040a0c0162310f300d060355040316066140612e6a70", "constructor /C=JP/O=b/CN=a@a.jp rule=default");
```
--------------------------------
### Get Next Sibling Index (getNextSiblingIdx) - DEPRECATED
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1hex-1.1.js.html
Calculates the starting index of the next sibling ASN.1 object in a hexadecimal string. This method is deprecated and users should prefer ASN1HEX.getTLVblen.
```javascript
ASN1HEX.getNextSiblingIdx = function(s, idx) {
var idx1 = ASN1HEX.getVidx(s, idx);
```
--------------------------------
### Instantiate KJUR.asn1.cms.SignerInfo
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.asn1.cms.SignerInfo.html
Demonstrates how to instantiate the SignerInfo class with various parameters including version, issuer, hash algorithm, signed attributes, signature algorithm, and signature value.
```javascript
new KJUR.asn1.cms.SignerInfo({
version: 1,
id: {type: 'isssn', issuer: {str: '/C=US/O=T1'}, serial: {int: 1}},
hashalg: "sha1",
sattrs: {array: [{"attr": "contentType", "type": '1.2.840.113549.1.7.1'},{"attr": "messageDigest", "hex": 'a1a2a3a4a5a6a7a8a9a0a1a2a3a4a5a6a7a8a9a0'}]},
sigalg: "SHA1withRSA",
sighex: 'b1b2b...'
})
```
--------------------------------
### Get X.509 Extended Key Usage
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-x509-ext.html
Retrieves the Extended Key Usage extension, which specifies the permitted uses of the public key. This example shows parsing a raw OID string.
```javascript
var x1 = new X509();
x1.readCertPEM(certGithubPEM);
deepEqual( x1.getExtExtKeyUsage(), {extname:"extKeyUsage", array: ["serverAuth", "clientAuth"]}, "for GitHub.com site");
```
```javascript
var x = new X509();
deepEqual( x.getExtExtKeyUsage("302006082b0601050507030206082b06010505070304060a2b0601040182370a0304", true), {extname:"extKeyUsage", array: ["clientAuth", "emailProtection", "1.3.6.1.4.1.311.10.3.4"], critical: true}, "three EKU");
```
--------------------------------
### Initialize KJUR.crypto.Mac with Different Password Formats
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/crypto-1.1.js.html
Demonstrates various ways to provide a password to the KJUR.crypto.Mac constructor, including hex, utf8, raw string, base64, and URL-safe base64.
```javascript
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"hex": "6161"}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"utf8": "aa"}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"rstr": "\x61\x61"}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64": "Mi02/+...a=="}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64u": "Mi02_-...a"}});
```
--------------------------------
### Get ASN.1 Value (getV)
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1hex-1.1.js.html
Extracts the hexadecimal string of the ASN.1 value (V) from a given index. It uses getVidx to find the value's start and getVblen to determine its length.
```javascript
ASN1HEX.getV = function(s, idx) {
var idx1 = ASN1HEX.getVidx(s, idx);
var blen = ASN1HEX.getVblen(s, idx);
return s.substr(idx1, blen * 2);
};
```
--------------------------------
### PKIStatus Class Examples
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-asn1tsp.html
Shows how to initialize a PKIStatus object using either an integer code or a string representation of the status.
```javascript
var o = new KJUR.asn1.tsp.PKIStatus(0);
equal(o.getEncodedHex(), "020100", "by int 0");
var o2 = new KJUR.asn1.tsp.PKIStatus('granted');
equal(o2.getEncodedHex(), "020100", "by name granted");
```
--------------------------------
### Get X.509 CRL Distribution Points
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-x509-ext.html
Retrieves the CRL Distribution Points extension, which provides URIs for obtaining Certificate Revocation Lists. This example shows parsing both HTTP and LDAP URIs.
```javascript
var x = new X509();
deepEqual( x.getExtCRLDistributionPoints("302e3015a013a011860f687474703a2f2f6161612e636f6d2f3015a013a011860f6c6461703a2f2f6161612e636f6d2f"), {extname:"cRLDistributionPoints", array: [ {dpname: {full: [{uri: "http://aaa.com/"}]}}, {dpname: {full: [{uri: "ldap://aaa.com/"}]}} ]}, "two dp {http,ldap}://aaa.com");
```
```javascript
var x2 = new X509();
x2.readCertPEM(certGithubPEM);
deepEqual( x2.getExtCRLDistributionPoints(), {extname:"cRLDistributionPoints", array: [ {dpname: {full: [{uri: "http://crl3.digicert.com/sha2-ev-server-g1.crl"}]}}, {dpname: {full: [{uri: "http://crl4.digicert.com/sha2-ev-server-g1.crl"}]}} ]}, "for github.com site");
```
--------------------------------
### CompleteCertificateRefs Examples
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-asn1cades.html
Demonstrates the creation of CompleteCertificateRefs structures, which can contain an array of certificates.
```javascript
var _CompleteCertificateRefs = KJUR.asn1.cades.CompleteCertificateRefs;
var hExpect = "3059060b2a864886f70d0109100215314a30483016041476c19d787741bdaf76cab1c42d166cb536aa83f83016041476c19d787741bdaf76cab1c42d166cb536aa83f83016041476c19d787741bdaf76cab1c42d166cb536aa83f8";
var params = {array: [sZ4_CERPEM,sZ4_CERPEM,sZ4_CERPEM]};
var o = new _CompleteCertificateRefs(params);
equal(o.getEncodedHex(), hExpect, "hex array=[certz4,certz4,certz4]");
equal( ASN1HEX.dump(o.getEncodedHex()), ASN1HEX.dump(hExpect), "dump array=[certz4,certz4,certz4]");
```
```javascript
var hExpect = "30820123060b2a864886f70d0109100215318201123082010e30583031300d060960864801650304020105000420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a3402010130583031300d060960864801650304020105000420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c025a3402010130583031300d060960864801650304020105000420c355dc4ee1dca2a95053ed90d27ff13025c887824da7d7cc83348ab2a0e944423023301ea41c301a310b3009060355040613025553310b3009060355040a0c0";
```
--------------------------------
### Get Public Key Content Index from Hex Certificate
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/X509.html
Finds the starting string index of the subjectPublicKeyInfo BITSTRING value within a hexadecimal certificate string. Useful for manual parsing or byte manipulation.
```javascript
x = new X509();
x.readCertPEM(sCertPEM);
idx = x.getPublicKeyContentIdx(); // return string index in x.hex parameter
```
--------------------------------
### Instantiate KJUR.asn1.x509.Extensions
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.asn1.x509.Extensions.html
Instantiate the Extensions class with an array of extension parameters. This example shows how to include standard extensions like keyUsage and subjectAltName, as well as a private extension.
```javascript
o = new KJUR.asn1.x509.Extensions([
{extname:"keyUsage",critical:true,names:["digitalSignature"]},
{extname:"subjectAltName",array:[{dns:"example.com"}]},
{extname:"1.2.3.4",extn:{prnstr:"aa"}} // private extension
]);
o.tohex() → "30..."
```
--------------------------------
### Get X.509 Subject Alternative Name
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-x509-ext.html
Retrieves the Subject Alternative Name extension, which can include DNS names, IP addresses, and email addresses. This example shows parsing a certificate with multiple SAN entries.
```javascript
var x = new X509();
x.readCertPEM(certGithubPEM);
deepEqual( x.getExtSubjectAltName(), {extname:"subjectAltName", array: [{dns: "github.com"},{dns: "www.github.com"}] }, "for GitHub.com site");
deepEqual( x.getExtSubjectAltName("302481226a6f686e2e7468652e726970706572406161613131312e6578616d706c652e636f6d"), {extname:"subjectAltName", array: [{rfc822: "john.the.ripper@aaa111.example.com"}] }, "mail");
```
```javascript
var x2 = new X509();
x2.readCertPEM(cfip1111PEM);
deepEqual( x2.getExtSubjectAltName(), { extname:"subjectAltName", array: [ {dns: "*.cloudflare-dns.com"}, {ip: "1.1.1.1"}, {ip: "1.0.0.1"}, {dns: "cloudflare-dns.com"}, {ip: "2606:4700:4700::1111"}, {ip: "2606:4700:4700::1001"} ] }, "cloudflare 1.1.1.1 cert" );
```
--------------------------------
### Initialize KeyUsage with Binary String
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/KJUR.asn1.x509.KeyUsage.html
Create a KeyUsage object using a binary string representation. The 'bin' parameter accepts a string of '0's and '1's corresponding to the key usage flags.
```javascript
o = new KJUR.asn1.x509.KeyUsage({bin: "11"});
```
--------------------------------
### Get PEM PKCS8PRV plain for ECDSA
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-keyutil-getpem.html
Converts an ECDSA private key to a plain PKCS8PRV PEM format. The output PEM string will start with '-BEGIN PRIVATE KEY-'. The key can be re-loaded directly using KEYUTIL.getKey.
```javascript
test("getPEM private ECDSA k1.prv.p5p.pem > PKCS8PRV plain", function() {
var key = KEYUTIL.getKey(k1PrvP8PPEM);
var pem = KEYUTIL.getPEM(key, "PKCS8PRV");
var key2 = KEYUTIL.getKey(pem);
expect(2);
equal(pem.indexOf("-BEGIN P
```
--------------------------------
### PKIStatusInfo Class Examples
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-asn1tsp.html
Demonstrates the creation of PKIStatusInfo objects with different status types and associated information. Covers rejection with status string and failure info, and a simple granted status.
```javascript
var o = new KJUR.asn1.tsp.PKIStatusInfo({ status: 'rejection', statusstr: ['aaa'], failinfo: 'badAlg' });
equal(o.getEncodedHex(), "300e02010230050c0361616103020780", "rejection/str=[aaa]/badAlg");
var o2 = new KJUR.asn1.tsp.PKIStatusInfo("granted");
equal(o2.getEncodedHex(), "3003020100", "granted");
```
--------------------------------
### Get PEM PKCS8PRV plain for RSA
Source: https://github.com/kjur/jsrsasign/blob/master/test/qunit-do-keyutil-getpem.html
Converts an RSA private key to a plain PKCS8PRV PEM format. The output PEM string will start with '-BEGIN PRIVATE KEY-'. The key can be re-loaded directly using KEYUTIL.getKey.
```javascript
test("getPEM private RSA z1.prv.p5p.pem > PKCS8PRV plain", function() {
var key = KEYUTIL.getKey(z1PrvP5PPEM);
var pem = KEYUTIL.getPEM(key, "PKCS8PRV");
var key2 = KEYUTIL.getKey(pem)
expect(2);
equal(pem.indexOf("-BEGIN PRIVATE KEY-") != -1, true, "");
equal(key2.d.toString(16), "78bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d", "");
});
```
--------------------------------
### Get Child Positions from Hex PKCS#5 RSA Private Key
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/rsapem-1.1.js.html
Extracts the starting positions of child fields within a hexadecimal PKCS#5 RSA private key. Useful for parsing the key structure.
```javascript
RSAKey.getPosArrayOfChildrenFromHex = function(hPrivateKey) {
return ASN1HEX.getChildIdx(hPrivateKey, 0);
};
```
--------------------------------
### Initialize DERBitString with various parameters
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1-1.0.js.html
Demonstrates different ways to construct a DERBitString object using binary, array, hex, or encapsulated object parameters.
```javascript
o = new KJUR.asn1.DERBitString();
```
```javascript
o = new KJUR.asn1.DERBitString({bin: "1011"});
```
```javascript
o = new KJUR.asn1.DERBitString({array: [true,false,true,true]});
```
```javascript
o = new KJUR.asn1.DERBitString({hex: "04bac0"});
```
```javascript
o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
```
--------------------------------
### GeneralName Construction Examples
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1x509-1.0.js.html
Demonstrates various ways to instantiate a KJUR.asn1.x509.GeneralName object with different name types.
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject);
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: {str: '/C=US/O=Test'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'});
```
```javascript
gn = new KJUR.asn1.x509.GeneralName({
other: {
oid: "1.2.3.4",
value: {utf8str: "example"} // any ASN.1 which passed to ASN1Util.newObject
}
});
```
--------------------------------
### Get ASN.1 Value Index (getVidx)
Source: https://github.com/kjur/jsrsasign/blob/master/api/symbols/src/asn1hex-1.1.js.html
Calculates the starting index of the ASN.1 value (V) within a hexadecimal string, based on the type, length, and current index. Returns -1 for indefinite length or malformed data.
```javascript
ASN1HEX.getVidx = function(s, idx) {
var l_len = ASN1HEX.getLblen(s, idx);
if (l_len < 0) return l_len;
return idx + (l_len + 1) * 2;
};
```