From 32f73aff77ecf4fdbccbd503dee380bc9cfb0473 Mon Sep 17 00:00:00 2001 From: Kenji Urushima Date: Mon, 27 Nov 2023 20:36:45 +0900 Subject: [PATCH] update jsdoc --- api/files.html | 10 +- api/symbols/KEYUTIL.html | 293 ++- api/symbols/KJUR.crypto.Cipher.html | 52 +- api/symbols/global__.html | 161 ++ api/symbols/src/asn1-1.0.js.html | 3473 +++++++++++++------------- api/symbols/src/asn1x509-1.0.js.html | 979 ++++---- api/symbols/src/base64x-1.1.js.html | 699 +++--- api/symbols/src/crypto-1.1.js.html | 298 ++- api/symbols/src/keyutil-1.0.js.html | 3409 +++++++++++++------------ 9 files changed, 5158 insertions(+), 4216 deletions(-) diff --git a/api/files.html b/api/files.html index b5874659..b2ce4865 100644 --- a/api/files.html +++ b/api/files.html @@ -535,7 +535,7 @@

asn1-1.0.js

Version:
-
jsrsasign 10.8.0 asn1 1.0.27 (2023-Apr-08)
+
jsrsasign 10.9.0 asn1 1.0.28 (2023-Nov-27)
@@ -668,7 +668,7 @@

asn1x509-1.0.js

Version:
-
jsrsasign 10.8.4 asn1x509 2.1.20 (2023-Apr-26)
+
jsrsasign 10.9.0 asn1x509 2.1.21 (2023-Nov-27)
@@ -687,7 +687,7 @@

base64x-1.1.js

Version:
-
jsrsasign 10.8.4 base64x 1.1.33 (2023-Apr-26)
+
jsrsasign 10.9.0 base64x 1.1.34 (2023-Nov-27)
@@ -706,7 +706,7 @@

crypto-1.1.js

Version:
-
jsrsasign 10.5.0 crypto 1.2.6 (2021-Nov-21)
+
jsrsasign 10.9.0 crypto 1.3.0 (2023-Nov-27)
@@ -820,7 +820,7 @@

keyutil-1.0.js

Version:
-
jsrsasign 10.5.16 keyutil 1.2.7 (2022-Apr-08)
+
jsrsasign 10.9.0 keyutil 1.3.0 (2023-Nov-25)
diff --git a/api/symbols/KEYUTIL.html b/api/symbols/KEYUTIL.html index 2b79f973..5a7e043b 100644 --- a/api/symbols/KEYUTIL.html +++ b/api/symbols/KEYUTIL.html @@ -634,6 +634,17 @@

+ + <static>   + +
KEYUTIL.getDKFromPBES2Param(pPBES2, passcode) +
+
get derived key from PBES2 parameters and passcode +This method derives a key from a passcode and a PBES2 parameter by +KEYUTIL.parsePBES2.
+ + + <static>   @@ -746,7 +757,7 @@

KEYUTIL.getPBKDF2KeyHexFromParam(info, passcode)
-
generate PBKDF2 key hexstring with specified passcode and information +
generate PBKDF2 key hexstring with specified passcode and information (DEPRECATED) As for info, this uses following properties:
  • info.pbkdf2Salt - hexadecimal string of PBKDF2 salt
  • @@ -776,6 +787,17 @@

    + + <static>   + +
    KEYUTIL.getPlainHexFromEncryptedPKCS8PEM(pkcs8PEM, passcode) +
    +
    get plaintext hexadecimal PKCS#8 private key from encrypted PKCS#8 PEM private key +This will get a plaintext hexadecimal PKCS#8 private key from a +encrypted PKCS#8 PEM private key.
    + + + <static>   @@ -794,7 +816,7 @@

    KEYUTIL.parseHexOfEncryptedPKCS8(passcode)
    -
    generate PBKDF2 key hexstring with specified passcode and information +
    generate PBKDF2 key hexstring with specified passcode and information (DEPRECATED) The associative array which is returned by this method has following properties:
    • info.pbkdf2Salt - hexadecimal string of PBKDF2 salt
    • @@ -807,6 +829,18 @@

      + + <static>   + +
      KEYUTIL.parsePBES2(hP8Prv) +
      +
      parse ASN.1 hexadecimal encrypted PKCS#8 private key and return as JSON +This method parses ASN.1 hexadecimal encrypted PKCS#8 private key and returns as +JSON object based on +RFC 8018.
      + + + <static>   @@ -1104,6 +1138,87 @@

      +
      + + +
      <static> + + {string} + KEYUTIL.getDKFromPBES2Param(pPBES2, passcode) + +
      +
      + get derived key from PBES2 parameters and passcode +This method derives a key from a passcode and a PBES2 parameter by +KEYUTIL.parsePBES2. +Currently following algorithms are supported: +
        +
      • prf(psudorandom function) - hmacWithSHA1,SHA224,SHA256,SHA384,SHA512
      • +
      • encryptionScheme - des-EDE3-CBC,aes128-CBC,aes256-CBC
      • +
      + + +
      + + + +
      pPBES2 = {
      +  "prf": "hmacWithSHA256",
      +  "salt": "1234567890abcdef",
      +  "iter": 2048,
      +  "encalg": "aes256-CBC",
      +  "enciv": "12ab...",
      +  "enc": "34cd..."
      +}
      +KEYUTIL.getDKFromPBES2Param(pPBES2, "passwd") → "3ab10fd..."
      + + + + +
      +
      Parameters:
      + +
      + {object} pPBES2 + +
      +
      parsed PBES2 parameter by KEYUTIL.parsePBES2 method
      + +
      + {string} passcode + +
      +
      password to derive the key
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 10.9.0 keyutil 1.3.0
      +
      + + + + +
      +
      Returns:
      + +
      {string} hexadecimal string of derived key
      + +
      + + + +
      +
      See:
      + +
      KEYUTIL.parsePBES2
      + +
      + +
      @@ -1819,7 +1934,7 @@

      EXAMPLE
    - generate PBKDF2 key hexstring with specified passcode and information + generate PBKDF2 key hexstring with specified passcode and information (DEPRECATED) As for info, this uses following properties:
    • info.pbkdf2Salt - hexadecimal string of PBKDF2 salt
    • @@ -1838,7 +1953,7 @@
      EXAMPLE
      // to convert plain PKCS#5 private key to encrypted PKCS#8 private
       // key with PBKDF2 with TripleDES
      -% openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
      +% openssl pkcs8 -in plain_p5.pem -topk8 -v2 des3 -out encrypted_p8.pem @@ -1861,6 +1976,13 @@
      EXAMPLE
      +
      +
      Deprecated:
      +
      + since jsrsasign 10.9.0 keyutil 1.3.0. Use KEYUTIL.getDKFromPBES2Param instead. +
      +
      +
      Since:
      @@ -1977,6 +2099,80 @@
      EXAMPLE
      +
      + + +
      <static> + + {string} + KEYUTIL.getPlainHexFromEncryptedPKCS8PEM(pkcs8PEM, passcode) + +
      +
      + get plaintext hexadecimal PKCS#8 private key from encrypted PKCS#8 PEM private key +This will get a plaintext hexadecimal PKCS#8 private key from a +encrypted PKCS#8 PEM private key. +Currently following algorithms are supported: +
        +
      • prf(psudorandom function) - hmacWithSHA1,SHA224,SHA256,SHA384,SHA512
      • +
      • encryptionScheme - des-EDE3-CBC,aes128-CBC,aes256-CBC
      • +
      + + +
      + + + +
      pem = "-----BEGIN ENCRYPTED PRIVATE KEY...";
      +KEYUTIL.getPlainHexFromEncryptedPKCS8PEM(pem, "passwd") → "3082..."
      + + + + +
      +
      Parameters:
      + +
      + {string} pkcs8PEM + +
      +
      PEM string of encrypted PKCS#8 private key
      + +
      + {string} passcode + +
      +
      passcode to decrypt the private key
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 10.9.0 keyutil 1.3.0
      +
      +
      + + + +
      +
      Returns:
      + +
      {string} hexadecimal string of decrypted plaintext PKCS#8 private key
      + +
      + + + +
      +
      See:
      + +
      KEYUTIL.parsePBES2
      + +
      + +
      @@ -2040,7 +2236,7 @@
      EXAMPLE
    - generate PBKDF2 key hexstring with specified passcode and information + generate PBKDF2 key hexstring with specified passcode and information (DEPRECATED) The associative array which is returned by this method has following properties:
    • info.pbkdf2Salt - hexadecimal string of PBKDF2 salt
    • @@ -2079,6 +2275,13 @@
      EXAMPLE
      +
      +
      Deprecated:
      +
      + since jsrsasign 10.9.0 keyutil 1.3.0. Use KEYUTIL.parsePBES2 instead. +
      +
      +
      Since:
      @@ -2098,6 +2301,86 @@
      EXAMPLE
      +
      + + +
      <static> + + {object} + KEYUTIL.parsePBES2(hP8Prv) + +
      +
      + parse ASN.1 hexadecimal encrypted PKCS#8 private key and return as JSON +This method parses ASN.1 hexadecimal encrypted PKCS#8 private key and returns as +JSON object based on +RFC 8018. +Currently following algorithms are supported: +
        +
      • prf(psudorandom function) - hmacWithSHA1,SHA224,SHA256,SHA384,SHA512
      • +
      • encryptionScheme - des-EDE3-CBC,aes128-CBC,aes256-CBC
      • +
      + + +
      + + + +
      KEYUTIL.parsePBES2("3082...") →
      +{
      +  "prf": "hmacWithSHA256",
      +  "salt": "1234567890abcdef",
      +  "iter": 2048,
      +  "encalg": "aes256-CBC",
      +  "enciv": "12ab...",
      +  "enc": "34cd..."
      +}
      +
      +// to convert plain PKCS#5 private key to encrypted PKCS#8 private
      +// key with PBKDF2 with TripleDES
      +% openssl pkcs8 -in plain_p5.pem -topk8 -v2 des3 -out encrypted_p8.pem
      + + + + +
      +
      Parameters:
      + +
      + {string} hP8Prv + +
      +
      hexadecimal encrypted PKCS#8 private key
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 10.9.0 keyutil 1.3.0
      +
      +
      + + + +
      +
      Returns:
      + +
      {object} parsed PBES2 parameters JSON object
      + +
      + + + +
      +
      See:
      + +
      KEYUTIL.getDKFromPBES2Param
      + +
      + +
      diff --git a/api/symbols/KJUR.crypto.Cipher.html b/api/symbols/KJUR.crypto.Cipher.html index 5412b7e6..526c754f 100644 --- a/api/symbols/KJUR.crypto.Cipher.html +++ b/api/symbols/KJUR.crypto.Cipher.html @@ -599,7 +599,7 @@

      <static>   -
      KJUR.crypto.Cipher.decrypt(hex, keyObj, algName) +
      KJUR.crypto.Cipher.decrypt(hex, keyObj, algName, param)
      decrypt encrypted hexadecimal string with specified key and algorithm
      This static method decrypts encrypted hexadecimal string with specified key and algorithm.
      @@ -609,7 +609,7 @@

      <static>   -
      KJUR.crypto.Cipher.encrypt(s, keyObj, algName) +
      KJUR.crypto.Cipher.encrypt(s, keyObj, algName, param)
      encrypt raw string by specified key and algorithm
      This static method encrypts raw string with specified key and algorithm.
      @@ -716,12 +716,14 @@

      <static> {String} - KJUR.crypto.Cipher.decrypt(hex, keyObj, algName) + KJUR.crypto.Cipher.decrypt(hex, keyObj, algName, param)
      decrypt encrypted hexadecimal string with specified key and algorithm
      This static method decrypts encrypted hexadecimal string with specified key and algorithm. +
      +NOTE: From jsrsasign 10.9.0, asymmetric cipher ({des-EDE3,aes{128,256}}-CBCis also supported.
      @@ -729,8 +731,14 @@

      +// asynchronous cipher
       KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj) → "1abc2d..."
      -KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj, "RSAOAEP) → "23ab02..."
      +KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj, "RSAOAEP) → "23ab02..." +// synchronous cipher +KJUR.crypto.Cipher.decrypt("12abcd...", "5a7d...", "aes256-CBC", { iv: "1b3c..." }) +KJUR.crypto.Cipher.decrypt("12abcd...", "5a7d...", any, { encalg: "aes128-CBC", iv: "1b3c..." }) +KJUR.crypto.Cipher.decrypt("12abcd...", any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41..." }) +KJUR.crypto.Cipher.decrypt(any, any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41...", enc: "12abcd..." }) @@ -739,22 +747,28 @@

      Parameters:
      - {String} hex + {string} hex
      -
      hexadecial string of encrypted message
      +
      hexadecimal string of encrypted message
      - {Object} keyObj + {object} keyObj
      RSAKey object or hexadecimal string of symmetric cipher key
      - {String} algName + {string} algName
      -
      short/long algorithm name for encryption/decryption
      +
      short/long algorithm name for encryption/decryption (OPTION)
      + +
      + {object} param + +
      +
      parameters for synchronous cipher such as initial vector (OPTION)
      @@ -784,12 +798,14 @@

      <static> {String} - KJUR.crypto.Cipher.encrypt(s, keyObj, algName) + KJUR.crypto.Cipher.encrypt(s, keyObj, algName, param)
      encrypt raw string by specified key and algorithm
      This static method encrypts raw string with specified key and algorithm. +
      +NOTE: From jsrsasign 10.9.0, asymmetric cipher ({des-EDE3,aes{128,256}}-CBC) is also supported.
      @@ -797,8 +813,14 @@

      +// asynchronous cipher
       KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj) → "1abc2d..."
      -KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj, "RSAOAEP") → "23ab02..."
      +KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj, "RSAOAEP") → "23ab02..." +// synchronous cipher +KJUR.crypto.Cipher.encrypt("12abcd...", "5a7d...", "aes256-CBC", { iv: "1b3c..." }) +KJUR.crypto.Cipher.encrypt("12abcd...", "5a7d...", any, { encalg: "aes128-CBC", iv: "1b3c..." }) +KJUR.crypto.Cipher.encrypt("12abcd...", any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41..." }) +KJUR.crypto.Cipher.encrypt(any, any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41...", enc: "12abcd..." }) @@ -822,7 +844,13 @@

      {String} algName -
      short/long algorithm name for encryption/decryption
      +
      short/long algorithm name for encryption/decryption (OPTION)
      + +
      + {object} param + +
      +
      parameters for synchronous cipher such as initial vector (OPTION)
      diff --git a/api/symbols/global__.html b/api/symbols/global__.html index e49d845e..0f6cda65 100644 --- a/api/symbols/global__.html +++ b/api/symbols/global__.html @@ -895,6 +895,17 @@

      + +   + +
      inttohex(i) +
      +
      get hexadecimal string of minimum two's complement of integer
      +This static method converts from integer value to a minimum length +hexadecimal string of two's complement of the integer.
      + + +   @@ -1200,6 +1211,17 @@

      + +   + +
      twoscompl(bi) +
      +
      get hexadecimal string of minimum two's complement of BigInteger
      +This static method converts from a BigInteger object to a minimum length +hexadecimal string of two's complement of the integer.
      + + +   @@ -3356,6 +3378,77 @@

      +
      + + +
      + + {string} + inttohex(i) + +
      +
      + get hexadecimal string of minimum two's complement of integer
      +This static method converts from integer value to a minimum length +hexadecimal string of two's complement of the integer. +This method is useful for DERInteger. + +
      + Defined in: base64x-1.1.js. + + +
      + + + +
      inttohex(1) → "01"
      +inttohex(-1) → "ff"
      +inttohex(2048) → "0800"
      +inttohex(-2048) → "f800"
      + + + + +
      +
      Parameters:
      + +
      + {number} i + +
      +
      integer value
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 10.9.0 base64x 1.1.34
      +
      + + + + +
      +
      Returns:
      + +
      {string} hexadecimal string of two's complement of the integer
      + +
      + + + +
      +
      See:
      + +
      twoscompl
      + +
      DERInteger
      + +
      + +
      @@ -5126,6 +5219,74 @@

      +
      + + +
      + + {string} + twoscompl(bi) + +
      +
      + get hexadecimal string of minimum two's complement of BigInteger
      +This static method converts from a BigInteger object to a minimum length +hexadecimal string of two's complement of the integer. +
      +NOTE: This function is a replacement of deprecated ASN1Util.bigIntToMinTwosComplementsHex method. + +
      + Defined in: base64x-1.1.js. + + +
      + + + +
      twoscompl(new BigInteger("1", 10)) → "01"
      +twoscompl(new BigInteger("-1", 10)) → "ff"
      + + + + +
      +
      Parameters:
      + +
      + {BigInteger} bi + +
      +
      BigInteger object
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 10.9.0 base64x 1.1.34
      +
      + + + + +
      +
      Returns:
      + +
      {string} hexadecimal string of two's complement of the integer
      + +
      + + + +
      +
      See:
      + +
      inttohex
      + +
      + +
      diff --git a/api/symbols/src/asn1-1.0.js.html b/api/symbols/src/asn1-1.0.js.html index 6a8f569c..09fbe2c1 100644 --- a/api/symbols/src/asn1-1.0.js.html +++ b/api/symbols/src/asn1-1.0.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
        1 /* asn1-1.0.27.js (c) 2013-2023 Kenji Urushima | kjur.github.io/jsrsasign/license
      +	
        1 /* asn1-1.0.28.js (c) 2013-2023 Kenji Urushima | kjur.github.io/jsrsasign/license
         2  */
         3 /*
         4  * asn1.js - ASN.1 DER encoder classes
      @@ -23,7 +23,7 @@
        16  * @fileOverview
        17  * @name asn1-1.0.js
        18  * @author Kenji Urushima kenji.urushima@gmail.com
      - 19  * @version jsrsasign 10.8.0 asn1 1.0.27 (2023-Apr-08)
      + 19  * @version jsrsasign 10.9.0 asn1 1.0.28 (2023-Nov-27)
        20  * @since jsrsasign 2.1
        21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
        22  */
      @@ -110,1762 +110,1735 @@
       103         if ((h.length % 2) == 1) h = '0' + h;
       104         return h;
       105     };
      -106     this.bigIntToMinTwosComplementsHex = function(bigIntegerValue) {
      -107         var h = bigIntegerValue.toString(16);
      -108         if (h.substr(0, 1) != '-') {
      -109             if (h.length % 2 == 1) {
      -110                 h = '0' + h;
      -111             } else {
      -112                 if (! h.match(/^[0-7]/)) {
      -113                     h = '00' + h;
      -114                 }
      -115             }
      -116         } else {
      -117             var hPos = h.substr(1);
      -118             var xorLen = hPos.length;
      -119             if (xorLen % 2 == 1) {
      -120                 xorLen += 1;
      -121             } else {
      -122                 if (! h.match(/^[0-7]/)) {
      -123                     xorLen += 2;
      -124                 }
      -125             }
      -126             var hMask = '';
      -127             for (var i = 0; i < xorLen; i++) {
      -128                 hMask += 'f';
      -129             }
      -130             var biMask = new BigInteger(hMask, 16);
      -131             var biNeg = biMask.xor(bigIntegerValue).add(BigInteger.ONE);
      -132             h = biNeg.toString(16).replace(/^-/, '');
      -133         }
      -134         return h;
      -135     };
      -136     /**
      -137      * get PEM string from hexadecimal data and header string
      -138      * @name getPEMStringFromHex
      -139      * @memberOf KJUR.asn1.ASN1Util
      -140      * @function
      -141      * @param {String} dataHex hexadecimal string of PEM body
      -142      * @param {String} pemHeader PEM header string (ex. 'RSA PRIVATE KEY')
      -143      * @return {String} PEM formatted string of input data
      -144      * @description
      -145      * This method converts a hexadecimal string to a PEM string with
      -146      * a specified header. Its line break will be CRLF("\r\n").
      -147      * @example
      -148      * var pem  = KJUR.asn1.ASN1Util.getPEMStringFromHex('616161', 'RSA PRIVATE KEY');
      -149      * // value of pem will be:
      -150      * -----BEGIN PRIVATE KEY-----
      -151      * YWFh
      -152      * -----END PRIVATE KEY-----
      -153      */
      -154     this.getPEMStringFromHex = function(dataHex, pemHeader) {
      -155 	return hextopem(dataHex, pemHeader);
      -156     };
      -157 
      -158     /**
      -159      * generate ASN1Object specifed by JSON parameters
      -160      * @name newObject
      -161      * @memberOf KJUR.asn1.ASN1Util
      -162      * @function
      -163      * @param {Array} param JSON parameter to generate ASN1Object
      -164      * @return {KJUR.asn1.ASN1Object} generated object
      -165      * @since asn1 1.0.3
      -166      * @description
      -167      * generate any ASN1Object specified by JSON param
      -168      * including ASN.1 primitive or structured.
      -169      * Generally 'param' can be described as follows:
      -170      * <blockquote>
      -171      * {TYPE-OF-ASNOBJ: ASN1OBJ-PARAMETER}
      -172      * </blockquote>
      -173      * 'TYPE-OF-ASN1OBJ' can be one of following symbols:
      -174      * <ul>
      -175      * <li>'bool' - {@link KJUR.asn1.DERBoolean}</li>
      -176      * <li>'int' - {@link KJUR.asn1.DERInteger}</li>
      -177      * <li>'bitstr' - {@link KJUR.asn1.DERBitString}</li>
      -178      * <li>'octstr' - {@link KJUR.asn1.DEROctetString}</li>
      -179      * <li>'null' - {@link KJUR.asn1.DERNull}</li>
      -180      * <li>'oid' - {@link KJUR.asn1.DERObjectIdentifier}</li>
      -181      * <li>'enum' - {@link KJUR.asn1.DEREnumerated}</li>
      -182      * <li>'utf8str' - {@link KJUR.asn1.DERUTF8String}</li>
      -183      * <li>'numstr' - {@link KJUR.asn1.DERNumericString}</li>
      -184      * <li>'prnstr' - {@link KJUR.asn1.DERPrintableString}</li>
      -185      * <li>'telstr' - {@link KJUR.asn1.DERTeletexString}</li>
      -186      * <li>'ia5str' - {@link KJUR.asn1.DERIA5String}</li>
      -187      * <li>'utctime' - {@link KJUR.asn1.DERUTCTime}</li>
      -188      * <li>'gentime' - {@link KJUR.asn1.DERGeneralizedTime}</li>
      -189      * <li>'visstr' - {@link KJUR.asn1.DERVisibleString}</li>
      -190      * <li>'bmpstr' - {@link KJUR.asn1.DERBMPString}</li>
      -191      * <li>'seq' - {@link KJUR.asn1.DERSequence}</li>
      -192      * <li>'set' - {@link KJUR.asn1.DERSet}</li>
      -193      * <li>'tag' - {@link KJUR.asn1.DERTaggedObject}</li>
      -194      * <li>'asn1' - {@link KJUR.asn1.ASN1Object}</li>
      -195      * </ul>
      -196      * <br/>
      -197      * NOTE: Structured object such as SEQUENCE or SET can conclude
      -198      * ASN1Object as well as JSON parameters since jsrsasign 9.0.0.
      -199      *
      -200      * @example
      -201      * newObject({'prnstr': 'aaa'});
      -202      * newObject({'seq': [{'int': 3}, {'prnstr': 'aaa'}]})
      -203      * newObject({seq: [{int: 3}, new DERInteger({int: 3})]}) // mixed
      -204      * // ASN.1 Tagged Object
      -205      * newObject({'tag': {'tag': 'a1', 
      -206      *                    'explicit': true,
      -207      *                    'obj': {'seq': [{'int': 3}, {'prnstr': 'aaa'}]}}});
      -208      * // more simple representation of ASN.1 Tagged Object
      -209      * newObject({'tag': ['a1',
      -210      *                    true,
      -211      *                    {'seq': [
      -212      *                      {'int': 3}, 
      -213      *                      {'prnstr': 'aaa'}]}
      -214      *                   ]});
      -215      */
      -216     this.newObject = function(param) {
      -217 	var _KJUR = KJUR,
      -218 	    _KJUR_asn1 = _KJUR.asn1,
      -219 	    _ASN1Object = _KJUR_asn1.ASN1Object,
      -220 	    _DERBoolean = _KJUR_asn1.DERBoolean,
      -221 	    _DERInteger = _KJUR_asn1.DERInteger,
      -222 	    _DERBitString = _KJUR_asn1.DERBitString,
      -223 	    _DEROctetString = _KJUR_asn1.DEROctetString,
      -224 	    _DERNull = _KJUR_asn1.DERNull,
      -225 	    _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier,
      -226 	    _DEREnumerated = _KJUR_asn1.DEREnumerated,
      -227 	    _DERUTF8String = _KJUR_asn1.DERUTF8String,
      -228 	    _DERNumericString = _KJUR_asn1.DERNumericString,
      -229 	    _DERPrintableString = _KJUR_asn1.DERPrintableString,
      -230 	    _DERTeletexString = _KJUR_asn1.DERTeletexString,
      -231 	    _DERIA5String = _KJUR_asn1.DERIA5String,
      -232 	    _DERUTCTime = _KJUR_asn1.DERUTCTime,
      -233 	    _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime,
      -234 	    _DERVisibleString = _KJUR_asn1.DERVisibleString,
      -235 	    _DERBMPString = _KJUR_asn1.DERBMPString,
      -236 	    _DERSequence = _KJUR_asn1.DERSequence,
      -237 	    _DERSet = _KJUR_asn1.DERSet,
      -238 	    _DERTaggedObject = _KJUR_asn1.DERTaggedObject,
      -239 	    _newObject = _KJUR_asn1.ASN1Util.newObject;
      -240 
      -241 	if (param instanceof _KJUR_asn1.ASN1Object) return param;
      -242 
      -243         var keys = Object.keys(param);
      -244         if (keys.length != 1)
      -245             throw new Error("key of param shall be only one.");
      -246         var key = keys[0];
      -247 
      -248         if (":asn1:bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:visstr:bmpstr:seq:set:tag:".indexOf(":" + key + ":") == -1)
      -249             throw new Error("undefined key: " + key);
      -250 
      -251         if (key == "bool")    return new _DERBoolean(param[key]);
      -252         if (key == "int")     return new _DERInteger(param[key]);
      -253         if (key == "bitstr")  return new _DERBitString(param[key]);
      -254         if (key == "octstr")  return new _DEROctetString(param[key]);
      -255         if (key == "null")    return new _DERNull(param[key]);
      -256         if (key == "oid")     return new _DERObjectIdentifier(param[key]);
      -257         if (key == "enum")    return new _DEREnumerated(param[key]);
      -258         if (key == "utf8str") return new _DERUTF8String(param[key]);
      -259         if (key == "numstr")  return new _DERNumericString(param[key]);
      -260         if (key == "prnstr")  return new _DERPrintableString(param[key]);
      -261         if (key == "telstr")  return new _DERTeletexString(param[key]);
      -262         if (key == "ia5str")  return new _DERIA5String(param[key]);
      -263         if (key == "utctime") return new _DERUTCTime(param[key]);
      -264         if (key == "gentime") return new _DERGeneralizedTime(param[key]);
      -265         if (key == "visstr")  return new _DERVisibleString(param[key]);
      -266         if (key == "bmpstr")  return new _DERBMPString(param[key]);
      -267         if (key == "asn1")    return new _ASN1Object(param[key]);
      -268 
      -269         if (key == "seq") {
      -270             var paramList = param[key];
      -271             var a = [];
      -272             for (var i = 0; i < paramList.length; i++) {
      -273                 var asn1Obj = _newObject(paramList[i]);
      -274                 a.push(asn1Obj);
      -275             }
      -276             return new _DERSequence({'array': a});
      -277         }
      -278 
      -279         if (key == "set") {
      -280             var paramList = param[key];
      -281             var a = [];
      -282             for (var i = 0; i < paramList.length; i++) {
      -283                 var asn1Obj = _newObject(paramList[i]);
      -284                 a.push(asn1Obj);
      -285             }
      -286             return new _DERSet({'array': a});
      -287         }
      -288 
      -289         if (key == "tag") {
      -290             var tagParam = param[key];
      -291             if (Object.prototype.toString.call(tagParam) === '[object Array]' &&
      -292                 tagParam.length == 3) {
      -293                 var obj = _newObject(tagParam[2]);
      -294                 return new _DERTaggedObject({tag: tagParam[0],
      -295 					     explicit: tagParam[1],
      -296 					     obj: obj});
      -297             } else {
      -298 		return new _DERTaggedObject(tagParam);
      -299             }
      -300         }
      -301     };
      -302 
      -303     /**
      -304      * get encoded hexadecimal string of ASN1Object specifed by JSON parameters
      -305      * @name jsonToASN1HEX
      -306      * @memberOf KJUR.asn1.ASN1Util
      -307      * @function
      -308      * @param {Array} param JSON parameter to generate ASN1Object
      -309      * @return hexadecimal string of ASN1Object
      -310      * @since asn1 1.0.4
      -311      * @description
      -312      * As for ASN.1 object representation of JSON object,
      -313      * please see {@link newObject}.
      -314      * @example
      -315      * jsonToASN1HEX({'prnstr': 'aaa'}); 
      -316      */
      -317     this.jsonToASN1HEX = function(param) {
      -318         var asn1Obj = this.newObject(param);
      -319         return asn1Obj.tohex();
      -320     };
      -321 };
      -322 
      -323 /**
      -324  * get dot noted oid number string from hexadecimal value of OID
      -325  * @name oidHexToInt
      -326  * @memberOf KJUR.asn1.ASN1Util
      -327  * @function
      -328  * @param {String} hex hexadecimal value of object identifier
      -329  * @return {String} dot noted string of object identifier
      -330  * @since jsrsasign 4.8.3 asn1 1.0.7
      -331  * @description
      -332  * This static method converts from hexadecimal string representation of 
      -333  * ASN.1 value of object identifier to oid number string.
      -334  * @example
      -335  * KJUR.asn1.ASN1Util.oidHexToInt('550406') → "2.5.4.6"
      -336  */
      -337 KJUR.asn1.ASN1Util.oidHexToInt = function(hex) {
      -338     var s = "";
      -339     var i01 = parseInt(hex.substr(0, 2), 16);
      -340     var i0 = Math.floor(i01 / 40);
      -341     var i1 = i01 % 40;
      -342     var s = i0 + "." + i1;
      -343 
      -344     var binbuf = "";
      -345     for (var i = 2; i < hex.length; i += 2) {
      -346 	var value = parseInt(hex.substr(i, 2), 16);
      -347         var bin = ("00000000" + value.toString(2)).slice(- 8);
      -348 	binbuf = binbuf + bin.substr(1, 7);
      -349 	if (bin.substr(0, 1) == "0") {
      -350 	    var bi = new BigInteger(binbuf, 2);
      -351 	    s = s + "." + bi.toString(10);
      -352 	    binbuf = "";
      -353 	}
      -354     };
      -355 
      -356     return s;
      -357 };
      -358 
      -359 /**
      -360  * get hexadecimal value of object identifier from dot noted oid value (DEPRECATED)
      -361  * @name oidIntToHex
      -362  * @memberOf KJUR.asn1.ASN1Util
      -363  * @function
      -364  * @param {String} oidString dot noted string of object identifier
      -365  * @return {String} hexadecimal value of object identifier
      -366  * @since jsrsasign 4.8.3 asn1 1.0.7
      -367  * @see {@link ASN1HEX.hextooidstr}
      -368  * @deprecated from jsrsasign 10.0.6. please use {@link oidtohex}
      -369  *
      -370  * @description
      -371  * This static method converts from object identifier value string.
      -372  * to hexadecimal string representation of it.
      -373  * {@link ASN1HEX.hextooidstr} is a reverse function of this.
      -374  * @example
      -375  * KJUR.asn1.ASN1Util.oidIntToHex("2.5.4.6") → "550406"
      -376  */
      -377 KJUR.asn1.ASN1Util.oidIntToHex = function(oidString) {
      -378     var itox = function(i) {
      -379         var h = i.toString(16);
      -380         if (h.length == 1) h = '0' + h;
      -381         return h;
      -382     };
      -383 
      -384     var roidtox = function(roid) {
      -385         var h = '';
      -386         var bi = new BigInteger(roid, 10);
      -387         var b = bi.toString(2);
      -388         var padLen = 7 - b.length % 7;
      -389         if (padLen == 7) padLen = 0;
      -390         var bPad = '';
      -391         for (var i = 0; i < padLen; i++) bPad += '0';
      -392         b = bPad + b;
      -393         for (var i = 0; i < b.length - 1; i += 7) {
      -394             var b8 = b.substr(i, 7);
      -395             if (i != b.length - 7) b8 = '1' + b8;
      -396             h += itox(parseInt(b8, 2));
      -397         }
      -398         return h;
      -399     };
      -400     
      -401     if (! oidString.match(/^[0-9.]+$/)) {
      -402         throw "malformed oid string: " + oidString;
      -403     }
      -404     var h = '';
      -405     var a = oidString.split('.');
      -406     var i0 = parseInt(a[0]) * 40 + parseInt(a[1]);
      -407     h += itox(i0);
      -408     a.splice(0, 2);
      -409     for (var i = 0; i < a.length; i++) {
      -410         h += roidtox(a[i]);
      -411     }
      -412     return h;
      -413 };
      -414 
      -415 
      -416 // ********************************************************************
      -417 //  Abstract ASN.1 Classes
      -418 // ********************************************************************
      -419 
      -420 // ********************************************************************
      -421 
      -422 /**
      -423  * base class for ASN.1 DER encoder object<br/>
      -424  * @name KJUR.asn1.ASN1Object
      -425  * @class base class for ASN.1 DER encoder object
      -426  * @param {Array} params JSON object parameter for constructor
      -427  * @property {Boolean} isModified flag whether internal data was changed
      -428  * @property {Array} params JSON object parameter for ASN.1 encode
      -429  * @property {String} hTLV hexadecimal string of ASN.1 TLV
      -430  * @property {String} hT hexadecimal string of ASN.1 TLV tag(T)
      -431  * @property {String} hL hexadecimal string of ASN.1 TLV length(L)
      -432  * @property {String} hV hexadecimal string of ASN.1 TLV value(V)
      -433  *
      -434  * @description
      -435  * This class is ASN.1 DER object encode base class.
      -436  * 
      -437  * @example
      -438  * new KJUR.asn1.ASN1Object({tlv: "030101"})
      -439  */
      -440 KJUR.asn1.ASN1Object = function(params) {
      -441     var isModified = true;
      -442     var hTLV = null;
      -443     var hT = '00';
      -444     var hL = '00';
      -445     var hV = '';
      -446     this.params = null;
      -447 
      -448     /**
      -449      * get hexadecimal ASN.1 TLV length(L) bytes from TLV value(V)<br/>
      -450      * @name getLengthHexFromValue
      -451      * @memberOf KJUR.asn1.ASN1Object#
      -452      * @function
      -453      * @return {String} hexadecimal string of ASN.1 TLV length(L)
      -454      */
      -455     this.getLengthHexFromValue = function() {
      -456         if (typeof this.hV == "undefined" || this.hV == null) {
      -457             throw new Error("this.hV is null or undefined");
      -458         }
      -459         if (this.hV.length % 2 == 1) {
      -460             throw new Error("value hex must be even length: n=" +
      -461 			    hV.length + ",v=" + this.hV);
      -462         }
      -463         var n = this.hV.length / 2;
      -464         var hN = n.toString(16);
      -465         if (hN.length % 2 == 1) {
      -466             hN = "0" + hN;
      -467         }
      -468         if (n < 128) {
      -469             return hN;
      -470         } else {
      -471             var hNlen = hN.length / 2;
      -472             if (hNlen > 15) {
      -473                 throw new Error("ASN.1 length too long to represent by 8x: n = "
      -474 				+ n.toString(16));
      -475             }
      -476             var head = 128 + hNlen;
      -477             return head.toString(16) + hN;
      -478         }
      -479     };
      -480 
      -481     /**
      -482      * get hexadecimal string of ASN.1 TLV bytes<br/>
      -483      * @name tohex
      -484      * @memberOf KJUR.asn1.ASN1Object#
      -485      * @function
      -486      * @return {String} hexadecimal string of ASN.1 TLV
      -487      * @since jsrsasign 10.5.16 asn1 1.0.24
      -488      * @see KJUR.asn1.ASN1Object#getEncodedHex
      -489      * @example
      -490      * ...ASN1ObjectInstance.tohex() → "3003020101"
      -491      */
      -492     this.tohex = function() {
      -493         if (this.hTLV == null || this.isModified) {
      -494             this.hV = this.getFreshValueHex();
      -495             this.hL = this.getLengthHexFromValue();
      -496             this.hTLV = this.hT + this.hL + this.hV;
      -497             this.isModified = false;
      -498             //alert("first time: " + this.hTLV);
      -499         }
      -500         return this.hTLV;
      -501     };
      -502 
      -503     /**
      -504      * get hexadecimal string of ASN.1 TLV bytes (DEPRECATED)<br/>
      -505      * @name getEncodedHex
      -506      * @memberOf KJUR.asn1.ASN1Object#
      -507      * @function
      -508      * @return {String} hexadecimal string of ASN.1 TLV
      -509      * @deprecated since jsrsasign 10.5.16 please use {@link KJUR.asn1.ASN1Object#tohex}
      -510      */
      -511     this.getEncodedHex = function() { return this.tohex(); };
      -512 
      -513     /**
      -514      * get hexadecimal string of ASN.1 TLV value(V) bytes
      -515      * @name getValueHex
      -516      * @memberOf KJUR.asn1.ASN1Object#
      -517      * @function
      -518      * @return {String} hexadecimal string of ASN.1 TLV value(V) bytes
      -519      */
      -520     this.getValueHex = function() {
      -521         this.tohex();
      -522         return this.hV;
      -523     }
      -524 
      -525     this.getFreshValueHex = function() {
      -526         return '';
      -527     };
      -528 
      -529     this.setByParam = function(params) {
      -530 	this.params = params;
      -531     };
      -532 
      -533     if (params != undefined) {
      -534 	if (params.tlv != undefined) {
      -535 	    this.hTLV = params.tlv;
      -536 	    this.isModified = false;
      -537 	}
      -538     }
      -539 };
      -540 
      -541 // == BEGIN DERAbstractString ================================================
      -542 /**
      -543  * base class for ASN.1 DER string classes
      -544  * @name KJUR.asn1.DERAbstractString
      -545  * @class base class for ASN.1 DER string classes
      -546  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -547  * @property {String} s internal string of value
      -548  * @extends KJUR.asn1.ASN1Object
      -549  * @description
      -550  * <br/>
      -551  * As for argument 'params' for constructor, you can specify one of
      -552  * following properties:
      -553  * <ul>
      -554  * <li>str - specify initial ASN.1 value(V) by a string</li>
      -555  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      -556  * </ul>
      -557  * NOTE: 'params' can be omitted.
      -558  */
      -559 KJUR.asn1.DERAbstractString = function(params) {
      -560     KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
      -561     var s = null;
      -562     var hV = null;
      -563 
      -564     /**
      -565      * get string value of this string object
      -566      * @name getString
      -567      * @memberOf KJUR.asn1.DERAbstractString#
      -568      * @function
      -569      * @return {String} string value of this string object
      -570      */
      -571     this.getString = function() {
      -572         return this.s;
      -573     };
      -574 
      -575     /**
      -576      * set value by a string
      -577      * @name setString
      -578      * @memberOf KJUR.asn1.DERAbstractString#
      -579      * @function
      -580      * @param {String} newS value by a string to set
      -581      * @description
      -582      * This method set value by string. <br/>
      -583      * NOTE: This method assumes that the argument string is
      -584      * UTF-8 encoded even though ASN.1 primitive 
      -585      * such as IA5String or PrintableString doesn't
      -586      * support all of UTF-8 characters.
      -587      * @example
      -588      * o = new KJUR.asn1.DERIA5String();
      -589      * o.setString("abc");
      -590      * o.setString("あいう");
      -591      */
      -592     this.setString = function(newS) {
      -593         this.hTLV = null;
      -594         this.isModified = true;
      -595         this.s = newS;
      -596         this.hV = utf8tohex(this.s).toLowerCase();
      -597     };
      -598 
      -599     /**
      -600      * set value by a hexadecimal string
      -601      * @name setStringHex
      -602      * @memberOf KJUR.asn1.DERAbstractString#
      -603      * @function
      -604      * @param {String} newHexString value by a hexadecimal string to set
      -605      */
      -606     this.setStringHex = function(newHexString) {
      -607         this.hTLV = null;
      -608         this.isModified = true;
      -609         this.s = null;
      -610         this.hV = newHexString;
      -611     };
      -612 
      -613     this.getFreshValueHex = function() {
      -614         return this.hV;
      -615     };
      -616 
      -617     if (typeof params != "undefined") {
      -618         if (typeof params == "string") {
      -619             this.setString(params);
      -620         } else if (typeof params['str'] != "undefined") {
      -621             this.setString(params['str']);
      -622         } else if (typeof params['hex'] != "undefined") {
      -623             this.setStringHex(params['hex']);
      -624         }
      -625     }
      -626 };
      -627 extendClass(KJUR.asn1.DERAbstractString, KJUR.asn1.ASN1Object);
      -628 // == END   DERAbstractString ================================================
      -629 
      -630 // == BEGIN DERAbstractTime ==================================================
      -631 /**
      -632  * base class for ASN.1 DER Generalized/UTCTime class
      -633  * @name KJUR.asn1.DERAbstractTime
      -634  * @class base class for ASN.1 DER Generalized/UTCTime class
      -635  * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
      -636  * @extends KJUR.asn1.ASN1Object
      -637  * @description
      -638  * @see KJUR.asn1.ASN1Object - superclass
      -639  * @see KJUR.asn1.DERGeneralizedTime
      -640  * @see KJUR.asn1.DERUTCTime
      -641  * @see KJUR.asn1.x509.Time
      -642  */
      -643 KJUR.asn1.DERAbstractTime = function(params) {
      -644     KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);
      -645     var s = null;
      -646     var date = null;
      -647 
      -648     // --- PRIVATE METHODS --------------------
      -649     this.localDateToUTC = function(d) {
      -650         var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
      -651         var utcDate = new Date(utc);
      -652         return utcDate;
      -653     };
      -654 
      -655     /*
      -656      * format date string by Data object
      -657      * @name formatDate
      -658      * @memberOf KJUR.asn1.AbstractTime;
      -659      * @param {Date} dateObject 
      -660      * @param {string} type 'utc' or 'gen'
      -661      * @param {boolean} withMillis flag for with millisections or not
      -662      * @description
      -663      * 'withMillis' flag is supported from asn1 1.0.6.
      -664      */
      -665     this.formatDate = function(dateObject, type, withMillis) {
      -666         var pad = this.zeroPadding;
      -667         var d = this.localDateToUTC(dateObject);
      -668         var year = String(d.getFullYear());
      -669         if (type == 'utc') year = year.substr(2, 2);
      -670         var month = pad(String(d.getMonth() + 1), 2);
      -671         var day = pad(String(d.getDate()), 2);
      -672         var hour = pad(String(d.getHours()), 2);
      -673         var min = pad(String(d.getMinutes()), 2);
      -674         var sec = pad(String(d.getSeconds()), 2);
      -675         var s = year + month + day + hour + min + sec;
      -676         if (withMillis === true) {
      -677             var millis = d.getMilliseconds();
      -678             if (millis != 0) {
      -679                 var sMillis = pad(String(millis), 3);
      -680                 sMillis = sMillis.replace(/[0]+$/, "");
      -681                 s = s + "." + sMillis;
      -682             }
      -683         }
      -684         return s + "Z";
      -685     };
      -686 
      -687     this.zeroPadding = function(s, len) {
      -688         if (s.length >= len) return s;
      -689         return new Array(len - s.length + 1).join('0') + s;
      -690     };
      -691 
      -692     // --- PUBLIC METHODS --------------------
      -693 
      -694     /**
      -695      * set parameter of time
      -696      * @name setByParam
      -697      * @memberOf KJUR.asn1.DERAbstractTime#
      -698      * @function
      -699      * @param {Object} params JSON object, Date object or string of time
      -700      * @since jsrsasign 10.4.1 asn1 1.0.22
      -701      *
      -702      * NOTE: If a member "millis" has a value "true",
      -703      * a fraction of second will be specified for this object. 
      -704      * This default is "false".
      -705      *
      -706      * @example
      -707      * d1 = new KJUR.asn1.DERGeneralizedTime();
      -708      * d1.setByParam("20210930235959.123Z");
      -709      * d1.setByParam({str: "20210930235959.123Z"});
      -710      *
      -711      * d1.setByParam(new Date("2013/12/31 23:59:59.12"));
      -712      * date1 = new Date(Date.UTC(2021,8,31,23,59,59,123));
      -713      * d1.setByParam(date1);
      -714      * d1.setByParam({date: date1});
      -715      * d1.setByParam({date: date1, millis: true});
      -716      */
      -717     this.setByParam = function(params) {
      -718 	this.hV = null;
      -719 	this.hTLV = null;
      -720 	this.params = params;
      +106     this.bigIntToMinTwosComplementsHex = function(bigIntegerValue) { // DEPRECATED. use twoscompl
      +107 	return twoscompl(bigIntegerValue);
      +108     }
      +109     /**
      +110      * get PEM string from hexadecimal data and header string
      +111      * @name getPEMStringFromHex
      +112      * @memberOf KJUR.asn1.ASN1Util
      +113      * @function
      +114      * @param {String} dataHex hexadecimal string of PEM body
      +115      * @param {String} pemHeader PEM header string (ex. 'RSA PRIVATE KEY')
      +116      * @return {String} PEM formatted string of input data
      +117      * @description
      +118      * This method converts a hexadecimal string to a PEM string with
      +119      * a specified header. Its line break will be CRLF("\r\n").
      +120      * @example
      +121      * var pem  = KJUR.asn1.ASN1Util.getPEMStringFromHex('616161', 'RSA PRIVATE KEY');
      +122      * // value of pem will be:
      +123      * -----BEGIN PRIVATE KEY-----
      +124      * YWFh
      +125      * -----END PRIVATE KEY-----
      +126      */
      +127     this.getPEMStringFromHex = function(dataHex, pemHeader) {
      +128 	return hextopem(dataHex, pemHeader);
      +129     };
      +130 
      +131     /**
      +132      * generate ASN1Object specifed by JSON parameters
      +133      * @name newObject
      +134      * @memberOf KJUR.asn1.ASN1Util
      +135      * @function
      +136      * @param {Array} param JSON parameter to generate ASN1Object
      +137      * @return {KJUR.asn1.ASN1Object} generated object
      +138      * @since asn1 1.0.3
      +139      * @description
      +140      * generate any ASN1Object specified by JSON param
      +141      * including ASN.1 primitive or structured.
      +142      * Generally 'param' can be described as follows:
      +143      * <blockquote>
      +144      * {TYPE-OF-ASNOBJ: ASN1OBJ-PARAMETER}
      +145      * </blockquote>
      +146      * 'TYPE-OF-ASN1OBJ' can be one of following symbols:
      +147      * <ul>
      +148      * <li>'bool' - {@link KJUR.asn1.DERBoolean}</li>
      +149      * <li>'int' - {@link KJUR.asn1.DERInteger}</li>
      +150      * <li>'bitstr' - {@link KJUR.asn1.DERBitString}</li>
      +151      * <li>'octstr' - {@link KJUR.asn1.DEROctetString}</li>
      +152      * <li>'null' - {@link KJUR.asn1.DERNull}</li>
      +153      * <li>'oid' - {@link KJUR.asn1.DERObjectIdentifier}</li>
      +154      * <li>'enum' - {@link KJUR.asn1.DEREnumerated}</li>
      +155      * <li>'utf8str' - {@link KJUR.asn1.DERUTF8String}</li>
      +156      * <li>'numstr' - {@link KJUR.asn1.DERNumericString}</li>
      +157      * <li>'prnstr' - {@link KJUR.asn1.DERPrintableString}</li>
      +158      * <li>'telstr' - {@link KJUR.asn1.DERTeletexString}</li>
      +159      * <li>'ia5str' - {@link KJUR.asn1.DERIA5String}</li>
      +160      * <li>'utctime' - {@link KJUR.asn1.DERUTCTime}</li>
      +161      * <li>'gentime' - {@link KJUR.asn1.DERGeneralizedTime}</li>
      +162      * <li>'visstr' - {@link KJUR.asn1.DERVisibleString}</li>
      +163      * <li>'bmpstr' - {@link KJUR.asn1.DERBMPString}</li>
      +164      * <li>'seq' - {@link KJUR.asn1.DERSequence}</li>
      +165      * <li>'set' - {@link KJUR.asn1.DERSet}</li>
      +166      * <li>'tag' - {@link KJUR.asn1.DERTaggedObject}</li>
      +167      * <li>'asn1' - {@link KJUR.asn1.ASN1Object}</li>
      +168      * </ul>
      +169      * <br/>
      +170      * NOTE: Structured object such as SEQUENCE or SET can conclude
      +171      * ASN1Object as well as JSON parameters since jsrsasign 9.0.0.
      +172      *
      +173      * @example
      +174      * newObject({'prnstr': 'aaa'});
      +175      * newObject({'seq': [{'int': 3}, {'prnstr': 'aaa'}]})
      +176      * newObject({seq: [{int: 3}, new DERInteger({int: 3})]}) // mixed
      +177      * // ASN.1 Tagged Object
      +178      * newObject({'tag': {'tag': 'a1', 
      +179      *                    'explicit': true,
      +180      *                    'obj': {'seq': [{'int': 3}, {'prnstr': 'aaa'}]}}});
      +181      * // more simple representation of ASN.1 Tagged Object
      +182      * newObject({'tag': ['a1',
      +183      *                    true,
      +184      *                    {'seq': [
      +185      *                      {'int': 3}, 
      +186      *                      {'prnstr': 'aaa'}]}
      +187      *                   ]});
      +188      */
      +189     this.newObject = function(param) {
      +190 	var _KJUR = KJUR,
      +191 	    _KJUR_asn1 = _KJUR.asn1,
      +192 	    _ASN1Object = _KJUR_asn1.ASN1Object,
      +193 	    _DERBoolean = _KJUR_asn1.DERBoolean,
      +194 	    _DERInteger = _KJUR_asn1.DERInteger,
      +195 	    _DERBitString = _KJUR_asn1.DERBitString,
      +196 	    _DEROctetString = _KJUR_asn1.DEROctetString,
      +197 	    _DERNull = _KJUR_asn1.DERNull,
      +198 	    _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier,
      +199 	    _DEREnumerated = _KJUR_asn1.DEREnumerated,
      +200 	    _DERUTF8String = _KJUR_asn1.DERUTF8String,
      +201 	    _DERNumericString = _KJUR_asn1.DERNumericString,
      +202 	    _DERPrintableString = _KJUR_asn1.DERPrintableString,
      +203 	    _DERTeletexString = _KJUR_asn1.DERTeletexString,
      +204 	    _DERIA5String = _KJUR_asn1.DERIA5String,
      +205 	    _DERUTCTime = _KJUR_asn1.DERUTCTime,
      +206 	    _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime,
      +207 	    _DERVisibleString = _KJUR_asn1.DERVisibleString,
      +208 	    _DERBMPString = _KJUR_asn1.DERBMPString,
      +209 	    _DERSequence = _KJUR_asn1.DERSequence,
      +210 	    _DERSet = _KJUR_asn1.DERSet,
      +211 	    _DERTaggedObject = _KJUR_asn1.DERTaggedObject,
      +212 	    _newObject = _KJUR_asn1.ASN1Util.newObject;
      +213 
      +214 	if (param instanceof _KJUR_asn1.ASN1Object) return param;
      +215 
      +216         var keys = Object.keys(param);
      +217         if (keys.length != 1)
      +218             throw new Error("key of param shall be only one.");
      +219         var key = keys[0];
      +220 
      +221         if (":asn1:bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:visstr:bmpstr:seq:set:tag:".indexOf(":" + key + ":") == -1)
      +222             throw new Error("undefined key: " + key);
      +223 
      +224         if (key == "bool")    return new _DERBoolean(param[key]);
      +225         if (key == "int")     return new _DERInteger(param[key]);
      +226         if (key == "bitstr")  return new _DERBitString(param[key]);
      +227         if (key == "octstr")  return new _DEROctetString(param[key]);
      +228         if (key == "null")    return new _DERNull(param[key]);
      +229         if (key == "oid")     return new _DERObjectIdentifier(param[key]);
      +230         if (key == "enum")    return new _DEREnumerated(param[key]);
      +231         if (key == "utf8str") return new _DERUTF8String(param[key]);
      +232         if (key == "numstr")  return new _DERNumericString(param[key]);
      +233         if (key == "prnstr")  return new _DERPrintableString(param[key]);
      +234         if (key == "telstr")  return new _DERTeletexString(param[key]);
      +235         if (key == "ia5str")  return new _DERIA5String(param[key]);
      +236         if (key == "utctime") return new _DERUTCTime(param[key]);
      +237         if (key == "gentime") return new _DERGeneralizedTime(param[key]);
      +238         if (key == "visstr")  return new _DERVisibleString(param[key]);
      +239         if (key == "bmpstr")  return new _DERBMPString(param[key]);
      +240         if (key == "asn1")    return new _ASN1Object(param[key]);
      +241 
      +242         if (key == "seq") {
      +243             var paramList = param[key];
      +244             var a = [];
      +245             for (var i = 0; i < paramList.length; i++) {
      +246                 var asn1Obj = _newObject(paramList[i]);
      +247                 a.push(asn1Obj);
      +248             }
      +249             return new _DERSequence({'array': a});
      +250         }
      +251 
      +252         if (key == "set") {
      +253             var paramList = param[key];
      +254             var a = [];
      +255             for (var i = 0; i < paramList.length; i++) {
      +256                 var asn1Obj = _newObject(paramList[i]);
      +257                 a.push(asn1Obj);
      +258             }
      +259             return new _DERSet({'array': a});
      +260         }
      +261 
      +262         if (key == "tag") {
      +263             var tagParam = param[key];
      +264             if (Object.prototype.toString.call(tagParam) === '[object Array]' &&
      +265                 tagParam.length == 3) {
      +266                 var obj = _newObject(tagParam[2]);
      +267                 return new _DERTaggedObject({tag: tagParam[0],
      +268 					     explicit: tagParam[1],
      +269 					     obj: obj});
      +270             } else {
      +271 		return new _DERTaggedObject(tagParam);
      +272             }
      +273         }
      +274     };
      +275 
      +276     /**
      +277      * get encoded hexadecimal string of ASN1Object specifed by JSON parameters
      +278      * @name jsonToASN1HEX
      +279      * @memberOf KJUR.asn1.ASN1Util
      +280      * @function
      +281      * @param {Array} param JSON parameter to generate ASN1Object
      +282      * @return hexadecimal string of ASN1Object
      +283      * @since asn1 1.0.4
      +284      * @description
      +285      * As for ASN.1 object representation of JSON object,
      +286      * please see {@link newObject}.
      +287      * @example
      +288      * jsonToASN1HEX({'prnstr': 'aaa'}); 
      +289      */
      +290     this.jsonToASN1HEX = function(param) {
      +291         var asn1Obj = this.newObject(param);
      +292         return asn1Obj.tohex();
      +293     };
      +294 };
      +295 
      +296 /**
      +297  * get dot noted oid number string from hexadecimal value of OID
      +298  * @name oidHexToInt
      +299  * @memberOf KJUR.asn1.ASN1Util
      +300  * @function
      +301  * @param {String} hex hexadecimal value of object identifier
      +302  * @return {String} dot noted string of object identifier
      +303  * @since jsrsasign 4.8.3 asn1 1.0.7
      +304  * @description
      +305  * This static method converts from hexadecimal string representation of 
      +306  * ASN.1 value of object identifier to oid number string.
      +307  * @example
      +308  * KJUR.asn1.ASN1Util.oidHexToInt('550406') → "2.5.4.6"
      +309  */
      +310 KJUR.asn1.ASN1Util.oidHexToInt = function(hex) {
      +311     var s = "";
      +312     var i01 = parseInt(hex.substr(0, 2), 16);
      +313     var i0 = Math.floor(i01 / 40);
      +314     var i1 = i01 % 40;
      +315     var s = i0 + "." + i1;
      +316 
      +317     var binbuf = "";
      +318     for (var i = 2; i < hex.length; i += 2) {
      +319 	var value = parseInt(hex.substr(i, 2), 16);
      +320         var bin = ("00000000" + value.toString(2)).slice(- 8);
      +321 	binbuf = binbuf + bin.substr(1, 7);
      +322 	if (bin.substr(0, 1) == "0") {
      +323 	    var bi = new BigInteger(binbuf, 2);
      +324 	    s = s + "." + bi.toString(10);
      +325 	    binbuf = "";
      +326 	}
      +327     };
      +328 
      +329     return s;
      +330 };
      +331 
      +332 /**
      +333  * get hexadecimal value of object identifier from dot noted oid value (DEPRECATED)
      +334  * @name oidIntToHex
      +335  * @memberOf KJUR.asn1.ASN1Util
      +336  * @function
      +337  * @param {String} oidString dot noted string of object identifier
      +338  * @return {String} hexadecimal value of object identifier
      +339  * @since jsrsasign 4.8.3 asn1 1.0.7
      +340  * @see {@link ASN1HEX.hextooidstr}
      +341  * @deprecated from jsrsasign 10.0.6. please use {@link oidtohex}
      +342  *
      +343  * @description
      +344  * This static method converts from object identifier value string.
      +345  * to hexadecimal string representation of it.
      +346  * {@link ASN1HEX.hextooidstr} is a reverse function of this.
      +347  * @example
      +348  * KJUR.asn1.ASN1Util.oidIntToHex("2.5.4.6") → "550406"
      +349  */
      +350 KJUR.asn1.ASN1Util.oidIntToHex = function(oidString) {
      +351     var itox = function(i) {
      +352         var h = i.toString(16);
      +353         if (h.length == 1) h = '0' + h;
      +354         return h;
      +355     };
      +356 
      +357     var roidtox = function(roid) {
      +358         var h = '';
      +359         var bi = new BigInteger(roid, 10);
      +360         var b = bi.toString(2);
      +361         var padLen = 7 - b.length % 7;
      +362         if (padLen == 7) padLen = 0;
      +363         var bPad = '';
      +364         for (var i = 0; i < padLen; i++) bPad += '0';
      +365         b = bPad + b;
      +366         for (var i = 0; i < b.length - 1; i += 7) {
      +367             var b8 = b.substr(i, 7);
      +368             if (i != b.length - 7) b8 = '1' + b8;
      +369             h += itox(parseInt(b8, 2));
      +370         }
      +371         return h;
      +372     };
      +373     
      +374     if (! oidString.match(/^[0-9.]+$/)) {
      +375         throw "malformed oid string: " + oidString;
      +376     }
      +377     var h = '';
      +378     var a = oidString.split('.');
      +379     var i0 = parseInt(a[0]) * 40 + parseInt(a[1]);
      +380     h += itox(i0);
      +381     a.splice(0, 2);
      +382     for (var i = 0; i < a.length; i++) {
      +383         h += roidtox(a[i]);
      +384     }
      +385     return h;
      +386 };
      +387 
      +388 
      +389 // ********************************************************************
      +390 //  Abstract ASN.1 Classes
      +391 // ********************************************************************
      +392 
      +393 // ********************************************************************
      +394 
      +395 /**
      +396  * base class for ASN.1 DER encoder object<br/>
      +397  * @name KJUR.asn1.ASN1Object
      +398  * @class base class for ASN.1 DER encoder object
      +399  * @param {Array} params JSON object parameter for constructor
      +400  * @property {Boolean} isModified flag whether internal data was changed
      +401  * @property {Array} params JSON object parameter for ASN.1 encode
      +402  * @property {String} hTLV hexadecimal string of ASN.1 TLV
      +403  * @property {String} hT hexadecimal string of ASN.1 TLV tag(T)
      +404  * @property {String} hL hexadecimal string of ASN.1 TLV length(L)
      +405  * @property {String} hV hexadecimal string of ASN.1 TLV value(V)
      +406  *
      +407  * @description
      +408  * This class is ASN.1 DER object encode base class.
      +409  * 
      +410  * @example
      +411  * new KJUR.asn1.ASN1Object({tlv: "030101"})
      +412  */
      +413 KJUR.asn1.ASN1Object = function(params) {
      +414     var isModified = true;
      +415     var hTLV = null;
      +416     var hT = '00';
      +417     var hL = '00';
      +418     var hV = '';
      +419     this.params = null;
      +420 
      +421     /**
      +422      * get hexadecimal ASN.1 TLV length(L) bytes from TLV value(V)<br/>
      +423      * @name getLengthHexFromValue
      +424      * @memberOf KJUR.asn1.ASN1Object#
      +425      * @function
      +426      * @return {String} hexadecimal string of ASN.1 TLV length(L)
      +427      */
      +428     this.getLengthHexFromValue = function() {
      +429         if (typeof this.hV == "undefined" || this.hV == null) {
      +430             throw new Error("this.hV is null or undefined");
      +431         }
      +432         if (this.hV.length % 2 == 1) {
      +433             throw new Error("value hex must be even length: n=" +
      +434 			    hV.length + ",v=" + this.hV);
      +435         }
      +436         var n = this.hV.length / 2;
      +437         var hN = n.toString(16);
      +438         if (hN.length % 2 == 1) {
      +439             hN = "0" + hN;
      +440         }
      +441         if (n < 128) {
      +442             return hN;
      +443         } else {
      +444             var hNlen = hN.length / 2;
      +445             if (hNlen > 15) {
      +446                 throw new Error("ASN.1 length too long to represent by 8x: n = "
      +447 				+ n.toString(16));
      +448             }
      +449             var head = 128 + hNlen;
      +450             return head.toString(16) + hN;
      +451         }
      +452     };
      +453 
      +454     /**
      +455      * get hexadecimal string of ASN.1 TLV bytes<br/>
      +456      * @name tohex
      +457      * @memberOf KJUR.asn1.ASN1Object#
      +458      * @function
      +459      * @return {String} hexadecimal string of ASN.1 TLV
      +460      * @since jsrsasign 10.5.16 asn1 1.0.24
      +461      * @see KJUR.asn1.ASN1Object#getEncodedHex
      +462      * @example
      +463      * ...ASN1ObjectInstance.tohex() → "3003020101"
      +464      */
      +465     this.tohex = function() {
      +466         if (this.hTLV == null || this.isModified) {
      +467             this.hV = this.getFreshValueHex();
      +468             this.hL = this.getLengthHexFromValue();
      +469             this.hTLV = this.hT + this.hL + this.hV;
      +470             this.isModified = false;
      +471             //alert("first time: " + this.hTLV);
      +472         }
      +473         return this.hTLV;
      +474     };
      +475 
      +476     /**
      +477      * get hexadecimal string of ASN.1 TLV bytes (DEPRECATED)<br/>
      +478      * @name getEncodedHex
      +479      * @memberOf KJUR.asn1.ASN1Object#
      +480      * @function
      +481      * @return {String} hexadecimal string of ASN.1 TLV
      +482      * @deprecated since jsrsasign 10.5.16 please use {@link KJUR.asn1.ASN1Object#tohex}
      +483      */
      +484     this.getEncodedHex = function() { return this.tohex(); };
      +485 
      +486     /**
      +487      * get hexadecimal string of ASN.1 TLV value(V) bytes
      +488      * @name getValueHex
      +489      * @memberOf KJUR.asn1.ASN1Object#
      +490      * @function
      +491      * @return {String} hexadecimal string of ASN.1 TLV value(V) bytes
      +492      */
      +493     this.getValueHex = function() {
      +494         this.tohex();
      +495         return this.hV;
      +496     }
      +497 
      +498     this.getFreshValueHex = function() {
      +499         return '';
      +500     };
      +501 
      +502     this.setByParam = function(params) {
      +503 	this.params = params;
      +504     };
      +505 
      +506     if (params != undefined) {
      +507 	if (params.tlv != undefined) {
      +508 	    this.hTLV = params.tlv;
      +509 	    this.isModified = false;
      +510 	}
      +511     }
      +512 };
      +513 
      +514 // == BEGIN DERAbstractString ================================================
      +515 /**
      +516  * base class for ASN.1 DER string classes
      +517  * @name KJUR.asn1.DERAbstractString
      +518  * @class base class for ASN.1 DER string classes
      +519  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +520  * @property {String} s internal string of value
      +521  * @extends KJUR.asn1.ASN1Object
      +522  * @description
      +523  * <br/>
      +524  * As for argument 'params' for constructor, you can specify one of
      +525  * following properties:
      +526  * <ul>
      +527  * <li>str - specify initial ASN.1 value(V) by a string</li>
      +528  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      +529  * </ul>
      +530  * NOTE: 'params' can be omitted.
      +531  */
      +532 KJUR.asn1.DERAbstractString = function(params) {
      +533     KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
      +534     var s = null;
      +535     var hV = null;
      +536 
      +537     /**
      +538      * get string value of this string object
      +539      * @name getString
      +540      * @memberOf KJUR.asn1.DERAbstractString#
      +541      * @function
      +542      * @return {String} string value of this string object
      +543      */
      +544     this.getString = function() {
      +545         return this.s;
      +546     };
      +547 
      +548     /**
      +549      * set value by a string
      +550      * @name setString
      +551      * @memberOf KJUR.asn1.DERAbstractString#
      +552      * @function
      +553      * @param {String} newS value by a string to set
      +554      * @description
      +555      * This method set value by string. <br/>
      +556      * NOTE: This method assumes that the argument string is
      +557      * UTF-8 encoded even though ASN.1 primitive 
      +558      * such as IA5String or PrintableString doesn't
      +559      * support all of UTF-8 characters.
      +560      * @example
      +561      * o = new KJUR.asn1.DERIA5String();
      +562      * o.setString("abc");
      +563      * o.setString("あいう");
      +564      */
      +565     this.setString = function(newS) {
      +566         this.hTLV = null;
      +567         this.isModified = true;
      +568         this.s = newS;
      +569         this.hV = utf8tohex(this.s).toLowerCase();
      +570     };
      +571 
      +572     /**
      +573      * set value by a hexadecimal string
      +574      * @name setStringHex
      +575      * @memberOf KJUR.asn1.DERAbstractString#
      +576      * @function
      +577      * @param {String} newHexString value by a hexadecimal string to set
      +578      */
      +579     this.setStringHex = function(newHexString) {
      +580         this.hTLV = null;
      +581         this.isModified = true;
      +582         this.s = null;
      +583         this.hV = newHexString;
      +584     };
      +585 
      +586     this.getFreshValueHex = function() {
      +587         return this.hV;
      +588     };
      +589 
      +590     if (typeof params != "undefined") {
      +591         if (typeof params == "string") {
      +592             this.setString(params);
      +593         } else if (typeof params['str'] != "undefined") {
      +594             this.setString(params['str']);
      +595         } else if (typeof params['hex'] != "undefined") {
      +596             this.setStringHex(params['hex']);
      +597         }
      +598     }
      +599 };
      +600 extendClass(KJUR.asn1.DERAbstractString, KJUR.asn1.ASN1Object);
      +601 // == END   DERAbstractString ================================================
      +602 
      +603 // == BEGIN DERAbstractTime ==================================================
      +604 /**
      +605  * base class for ASN.1 DER Generalized/UTCTime class
      +606  * @name KJUR.asn1.DERAbstractTime
      +607  * @class base class for ASN.1 DER Generalized/UTCTime class
      +608  * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
      +609  * @extends KJUR.asn1.ASN1Object
      +610  * @description
      +611  * @see KJUR.asn1.ASN1Object - superclass
      +612  * @see KJUR.asn1.DERGeneralizedTime
      +613  * @see KJUR.asn1.DERUTCTime
      +614  * @see KJUR.asn1.x509.Time
      +615  */
      +616 KJUR.asn1.DERAbstractTime = function(params) {
      +617     KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);
      +618     var s = null;
      +619     var date = null;
      +620 
      +621     // --- PRIVATE METHODS --------------------
      +622     this.localDateToUTC = function(d) {
      +623         var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
      +624         var utcDate = new Date(utc);
      +625         return utcDate;
      +626     };
      +627 
      +628     /*
      +629      * format date string by Data object
      +630      * @name formatDate
      +631      * @memberOf KJUR.asn1.AbstractTime;
      +632      * @param {Date} dateObject 
      +633      * @param {string} type 'utc' or 'gen'
      +634      * @param {boolean} withMillis flag for with millisections or not
      +635      * @description
      +636      * 'withMillis' flag is supported from asn1 1.0.6.
      +637      */
      +638     this.formatDate = function(dateObject, type, withMillis) {
      +639         var pad = this.zeroPadding;
      +640         var d = this.localDateToUTC(dateObject);
      +641         var year = String(d.getFullYear());
      +642         if (type == 'utc') year = year.substr(2, 2);
      +643         var month = pad(String(d.getMonth() + 1), 2);
      +644         var day = pad(String(d.getDate()), 2);
      +645         var hour = pad(String(d.getHours()), 2);
      +646         var min = pad(String(d.getMinutes()), 2);
      +647         var sec = pad(String(d.getSeconds()), 2);
      +648         var s = year + month + day + hour + min + sec;
      +649         if (withMillis === true) {
      +650             var millis = d.getMilliseconds();
      +651             if (millis != 0) {
      +652                 var sMillis = pad(String(millis), 3);
      +653                 sMillis = sMillis.replace(/[0]+$/, "");
      +654                 s = s + "." + sMillis;
      +655             }
      +656         }
      +657         return s + "Z";
      +658     };
      +659 
      +660     this.zeroPadding = function(s, len) {
      +661         if (s.length >= len) return s;
      +662         return new Array(len - s.length + 1).join('0') + s;
      +663     };
      +664 
      +665     // --- PUBLIC METHODS --------------------
      +666 
      +667     /**
      +668      * set parameter of time
      +669      * @name setByParam
      +670      * @memberOf KJUR.asn1.DERAbstractTime#
      +671      * @function
      +672      * @param {Object} params JSON object, Date object or string of time
      +673      * @since jsrsasign 10.4.1 asn1 1.0.22
      +674      *
      +675      * NOTE: If a member "millis" has a value "true",
      +676      * a fraction of second will be specified for this object. 
      +677      * This default is "false".
      +678      *
      +679      * @example
      +680      * d1 = new KJUR.asn1.DERGeneralizedTime();
      +681      * d1.setByParam("20210930235959.123Z");
      +682      * d1.setByParam({str: "20210930235959.123Z"});
      +683      *
      +684      * d1.setByParam(new Date("2013/12/31 23:59:59.12"));
      +685      * date1 = new Date(Date.UTC(2021,8,31,23,59,59,123));
      +686      * d1.setByParam(date1);
      +687      * d1.setByParam({date: date1});
      +688      * d1.setByParam({date: date1, millis: true});
      +689      */
      +690     this.setByParam = function(params) {
      +691 	this.hV = null;
      +692 	this.hTLV = null;
      +693 	this.params = params;
      +694     };
      +695 
      +696     /**
      +697      * get string value of this string object (DEPRECATED)
      +698      * @name getString
      +699      * @memberOf KJUR.asn1.DERAbstractTime#
      +700      * @function
      +701      * @return {String} string value of this time object
      +702      * @deprecated from jsrsasign 10.4.1 asn1 1.0.22.
      +703      */
      +704     this.getString = function() {
      +705         return undefined;
      +706     };
      +707 
      +708     /**
      +709      * set value by a string (DEPRECATED)
      +710      * @name setString
      +711      * @memberOf KJUR.asn1.DERAbstractTime#
      +712      * @function
      +713      * @param {String} newS value by a string to set such like "130430235959Z"
      +714      * @deprecated from jsrsasign 10.4.1 asn1 1.0.22.
      +715      */
      +716     this.setString = function(newS) {
      +717         this.hTLV = null;
      +718         this.isModified = true;
      +719 	if (this.params == undefined) this.params = {};
      +720 	this.params.str = newS;
       721     };
       722 
       723     /**
      -724      * get string value of this string object (DEPRECATED)
      -725      * @name getString
      +724      * set value by a Date object<br/>
      +725      * @name setByDate
       726      * @memberOf KJUR.asn1.DERAbstractTime#
       727      * @function
      -728      * @return {String} string value of this time object
      -729      * @deprecated from jsrsasign 10.4.1 asn1 1.0.22.
      -730      */
      -731     this.getString = function() {
      -732         return undefined;
      -733     };
      -734 
      -735     /**
      -736      * set value by a string (DEPRECATED)
      -737      * @name setString
      -738      * @memberOf KJUR.asn1.DERAbstractTime#
      -739      * @function
      -740      * @param {String} newS value by a string to set such like "130430235959Z"
      -741      * @deprecated from jsrsasign 10.4.1 asn1 1.0.22.
      -742      */
      -743     this.setString = function(newS) {
      -744         this.hTLV = null;
      -745         this.isModified = true;
      -746 	if (this.params == undefined) this.params = {};
      -747 	this.params.str = newS;
      -748     };
      -749 
      -750     /**
      -751      * set value by a Date object<br/>
      -752      * @name setByDate
      -753      * @memberOf KJUR.asn1.DERAbstractTime#
      -754      * @function
      -755      * @param {Date} dateObject Date object to set ASN.1 value(V)
      -756      * @since jsrsasign 10.4.1 asn1 1.0.22
      -757      *
      -758      * @example
      -759      * o = new KJUR.asn1.DERUTCTime();
      -760      * o.setByDate(new Date("2016/12/31 23:59:59.12"));
      -761      * // 2015-Jan-31 23:59:59.12
      -762      * o.setByDate(new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)));
      -763      */
      -764     this.setByDate = function(dateObject) {
      -765         this.hTLV = null;
      -766         this.isModified = true;
      -767 	if (this.params == undefined) this.params = {};
      -768 	this.params.date = dateObject;
      -769     };
      -770 
      -771     /**
      -772      * set value by a Date object
      -773      * @name setByDateValue
      -774      * @memberOf KJUR.asn1.DERAbstractTime#
      -775      * @function
      -776      * @param {Integer} year year of date (ex. 2013)
      -777      * @param {Integer} month month of date between 1 and 12 (ex. 12)
      -778      * @param {Integer} day day of month
      -779      * @param {Integer} hour hours of date
      -780      * @param {Integer} min minutes of date
      -781      * @param {Integer} sec seconds of date
      -782      */
      -783     this.setByDateValue = function(year, month, day, hour, min, sec) {
      -784         var dateObject = new Date(Date.UTC(year, month - 1, day, 
      -785 					   hour, min, sec, 0));
      -786         this.setByDate(dateObject);
      -787     };
      -788 
      -789     this.getFreshValueHex = function() {
      -790         return this.hV;
      -791     };
      -792 };
      -793 extendClass(KJUR.asn1.DERAbstractTime, KJUR.asn1.ASN1Object);
      -794 // == END   DERAbstractTime ==================================================
      +728      * @param {Date} dateObject Date object to set ASN.1 value(V)
      +729      * @since jsrsasign 10.4.1 asn1 1.0.22
      +730      *
      +731      * @example
      +732      * o = new KJUR.asn1.DERUTCTime();
      +733      * o.setByDate(new Date("2016/12/31 23:59:59.12"));
      +734      * // 2015-Jan-31 23:59:59.12
      +735      * o.setByDate(new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)));
      +736      */
      +737     this.setByDate = function(dateObject) {
      +738         this.hTLV = null;
      +739         this.isModified = true;
      +740 	if (this.params == undefined) this.params = {};
      +741 	this.params.date = dateObject;
      +742     };
      +743 
      +744     /**
      +745      * set value by a Date object
      +746      * @name setByDateValue
      +747      * @memberOf KJUR.asn1.DERAbstractTime#
      +748      * @function
      +749      * @param {Integer} year year of date (ex. 2013)
      +750      * @param {Integer} month month of date between 1 and 12 (ex. 12)
      +751      * @param {Integer} day day of month
      +752      * @param {Integer} hour hours of date
      +753      * @param {Integer} min minutes of date
      +754      * @param {Integer} sec seconds of date
      +755      */
      +756     this.setByDateValue = function(year, month, day, hour, min, sec) {
      +757         var dateObject = new Date(Date.UTC(year, month - 1, day, 
      +758 					   hour, min, sec, 0));
      +759         this.setByDate(dateObject);
      +760     };
      +761 
      +762     this.getFreshValueHex = function() {
      +763         return this.hV;
      +764     };
      +765 };
      +766 extendClass(KJUR.asn1.DERAbstractTime, KJUR.asn1.ASN1Object);
      +767 // == END   DERAbstractTime ==================================================
      +768 
      +769 // == BEGIN DERAbstractStructured ============================================
      +770 /**
      +771  * base class for ASN.1 DER structured class
      +772  * @name KJUR.asn1.DERAbstractStructured
      +773  * @class base class for ASN.1 DER structured class
      +774  * @property {Array} asn1Array internal array of ASN1Object
      +775  * @extends KJUR.asn1.ASN1Object
      +776  * @description
      +777  * @see KJUR.asn1.ASN1Object - superclass
      +778  */
      +779 KJUR.asn1.DERAbstractStructured = function(params) {
      +780     KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
      +781     var asn1Array = null;
      +782 
      +783     /**
      +784      * set value by array of ASN1Object
      +785      * @name setByASN1ObjectArray
      +786      * @memberOf KJUR.asn1.DERAbstractStructured#
      +787      * @function
      +788      * @param {array} asn1ObjectArray array of ASN1Object to set
      +789      */
      +790     this.setByASN1ObjectArray = function(asn1ObjectArray) {
      +791         this.hTLV = null;
      +792         this.isModified = true;
      +793         this.asn1Array = asn1ObjectArray;
      +794     };
       795 
      -796 // == BEGIN DERAbstractStructured ============================================
      -797 /**
      -798  * base class for ASN.1 DER structured class
      -799  * @name KJUR.asn1.DERAbstractStructured
      -800  * @class base class for ASN.1 DER structured class
      -801  * @property {Array} asn1Array internal array of ASN1Object
      -802  * @extends KJUR.asn1.ASN1Object
      -803  * @description
      -804  * @see KJUR.asn1.ASN1Object - superclass
      -805  */
      -806 KJUR.asn1.DERAbstractStructured = function(params) {
      -807     KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
      -808     var asn1Array = null;
      -809 
      -810     /**
      -811      * set value by array of ASN1Object
      -812      * @name setByASN1ObjectArray
      -813      * @memberOf KJUR.asn1.DERAbstractStructured#
      -814      * @function
      -815      * @param {array} asn1ObjectArray array of ASN1Object to set
      -816      */
      -817     this.setByASN1ObjectArray = function(asn1ObjectArray) {
      -818         this.hTLV = null;
      -819         this.isModified = true;
      -820         this.asn1Array = asn1ObjectArray;
      -821     };
      +796     /**
      +797      * append an ASN1Object to internal array
      +798      * @name appendASN1Object
      +799      * @memberOf KJUR.asn1.DERAbstractStructured#
      +800      * @function
      +801      * @param {ASN1Object} asn1Object to add
      +802      */
      +803     this.appendASN1Object = function(asn1Object) {
      +804         this.hTLV = null;
      +805         this.isModified = true;
      +806         this.asn1Array.push(asn1Object);
      +807     };
      +808 
      +809     this.asn1Array = new Array();
      +810     if (typeof params != "undefined") {
      +811         if (typeof params['array'] != "undefined") {
      +812             this.asn1Array = params['array'];
      +813         }
      +814     }
      +815 };
      +816 extendClass(KJUR.asn1.DERAbstractStructured, KJUR.asn1.ASN1Object);
      +817 
      +818 
      +819 // ********************************************************************
      +820 //  ASN.1 Object Classes
      +821 // ********************************************************************
       822 
      -823     /**
      -824      * append an ASN1Object to internal array
      -825      * @name appendASN1Object
      -826      * @memberOf KJUR.asn1.DERAbstractStructured#
      -827      * @function
      -828      * @param {ASN1Object} asn1Object to add
      -829      */
      -830     this.appendASN1Object = function(asn1Object) {
      -831         this.hTLV = null;
      -832         this.isModified = true;
      -833         this.asn1Array.push(asn1Object);
      -834     };
      -835 
      -836     this.asn1Array = new Array();
      -837     if (typeof params != "undefined") {
      -838         if (typeof params['array'] != "undefined") {
      -839             this.asn1Array = params['array'];
      -840         }
      -841     }
      -842 };
      -843 extendClass(KJUR.asn1.DERAbstractStructured, KJUR.asn1.ASN1Object);
      -844 
      -845 
      -846 // ********************************************************************
      -847 //  ASN.1 Object Classes
      -848 // ********************************************************************
      -849 
      -850 // ********************************************************************
      -851 /**
      -852  * class for ASN.1 DER Boolean
      -853  * @name KJUR.asn1.DERBoolean
      -854  * @class class for ASN.1 DER Boolean
      -855  * @extends KJUR.asn1.ASN1Object
      -856  * @see KJUR.asn1.ASN1Object - superclass
      -857  * @description
      -858  * In ASN.1 DER, DER Boolean "false" shall be omitted.
      -859  * However this supports boolean false for future BER support.
      -860  * @example
      -861  * new KJUR.asn1.DERBoolean(true)
      -862  * new KJUR.asn1.DERBoolean(false)
      +823 // ********************************************************************
      +824 /**
      +825  * class for ASN.1 DER Boolean
      +826  * @name KJUR.asn1.DERBoolean
      +827  * @class class for ASN.1 DER Boolean
      +828  * @extends KJUR.asn1.ASN1Object
      +829  * @see KJUR.asn1.ASN1Object - superclass
      +830  * @description
      +831  * In ASN.1 DER, DER Boolean "false" shall be omitted.
      +832  * However this supports boolean false for future BER support.
      +833  * @example
      +834  * new KJUR.asn1.DERBoolean(true)
      +835  * new KJUR.asn1.DERBoolean(false)
      +836  */
      +837 KJUR.asn1.DERBoolean = function(params) {
      +838     KJUR.asn1.DERBoolean.superclass.constructor.call(this);
      +839     this.hT = "01";
      +840     if (params == false)
      +841 	this.hTLV = "010100";
      +842     else 
      +843 	this.hTLV = "0101ff";
      +844 };
      +845 extendClass(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object);
      +846 
      +847 // ********************************************************************
      +848 /**
      +849  * class for ASN.1 DER Integer
      +850  * @name KJUR.asn1.DERInteger
      +851  * @class class for ASN.1 DER Integer
      +852  * @extends KJUR.asn1.ASN1Object
      +853  * @description
      +854  * <br/>
      +855  * As for argument 'params' for constructor, you can specify one of
      +856  * following properties:
      +857  * <ul>
      +858  * <li>int - specify initial ASN.1 value(V) by integer value</li>
      +859  * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li>
      +860  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      +861  * </ul>
      +862  * NOTE: 'params' can be omitted.
       863  */
      -864 KJUR.asn1.DERBoolean = function(params) {
      -865     KJUR.asn1.DERBoolean.superclass.constructor.call(this);
      -866     this.hT = "01";
      -867     if (params == false)
      -868 	this.hTLV = "010100";
      -869     else 
      -870 	this.hTLV = "0101ff";
      -871 };
      -872 extendClass(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object);
      -873 
      -874 // ********************************************************************
      -875 /**
      -876  * class for ASN.1 DER Integer
      -877  * @name KJUR.asn1.DERInteger
      -878  * @class class for ASN.1 DER Integer
      -879  * @extends KJUR.asn1.ASN1Object
      -880  * @description
      -881  * <br/>
      -882  * As for argument 'params' for constructor, you can specify one of
      -883  * following properties:
      -884  * <ul>
      -885  * <li>int - specify initial ASN.1 value(V) by integer value</li>
      -886  * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li>
      -887  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      -888  * </ul>
      -889  * NOTE: 'params' can be omitted.
      -890  */
      -891 KJUR.asn1.DERInteger = function(params) {
      -892     KJUR.asn1.DERInteger.superclass.constructor.call(this);
      -893     this.hT = "02";
      -894     this.params = null;
      -895     var _biToTwoCompl = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex;
      -896 
      -897     /**
      -898      * set value by Tom Wu's BigInteger object
      -899      * @name setByBigInteger
      -900      * @memberOf KJUR.asn1.DERInteger#
      -901      * @function
      -902      * @param {BigInteger} bigIntegerValue to set
      -903      */
      -904     this.setByBigInteger = function(bigIntegerValue) {
      -905 	this.isModified = true;
      -906 	this.params = { bigint: bigIntegerValue };
      -907     };
      -908 
      -909     /**
      -910      * set value by integer value
      -911      * @name setByInteger
      -912      * @memberOf KJUR.asn1.DERInteger
      -913      * @function
      -914      * @param {Integer} integer value to set
      -915      */
      -916     this.setByInteger = function(intValue) {
      -917 	this.isModified = true;
      -918 	this.params = intValue;
      -919     };
      -920 
      -921     /**
      -922      * set value by integer value
      -923      * @name setValueHex
      -924      * @memberOf KJUR.asn1.DERInteger#
      -925      * @function
      -926      * @param {String} hexadecimal string of integer value
      -927      * @description
      -928      * <br/>
      -929      * NOTE: Value shall be represented by minimum octet length of
      -930      * two's complement representation.
      -931      * @example
      -932      * new KJUR.asn1.DERInteger(123);
      -933      * new KJUR.asn1.DERInteger({'int': 123});
      -934      * new KJUR.asn1.DERInteger({'hex': '1fad'});
      -935      * new KJUR.asn1.DERInteger({'bigint': new BigInteger("1234", 10)});
      -936      */
      -937     this.setValueHex = function(newHexString) {
      -938 	this.isModified = true;
      -939 	this.params = { hex: newHexString };
      -940     };
      -941 
      -942     this.getFreshValueHex = function() {
      -943 	var params = this.params;
      -944 	var bi = null;
      -945 	if (params == null) throw new Error("value not set");
      -946 
      -947 	if (typeof params == "object" && params.hex != undefined) {
      -948 	    this.hV = params.hex;
      -949             return this.hV;
      -950 	}
      -951 
      -952 	if (typeof params == "number") {
      -953 	    bi = new BigInteger(String(params), 10);
      -954 	} else if (params["int"] != undefined) {
      -955 	    bi = new BigInteger(String(params["int"]), 10);
      -956 	} else if (params.bigint != undefined) {
      -957 	    bi = params.bigint;
      -958 	} else {
      -959 	    throw new Error("wrong parameter");
      -960 	}
      -961 	this.hV = _biToTwoCompl(bi);
      -962         return this.hV;
      -963     };
      -964 
      -965     if (params != undefined) {
      -966 	this.params = params;
      -967     }
      -968 };
      -969 extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object);
      -970 
      -971 // ********************************************************************
      -972 /**
      -973  * class for ASN.1 DER encoded BitString primitive
      -974  * @name KJUR.asn1.DERBitString
      -975  * @class class for ASN.1 DER encoded BitString primitive
      -976  * @extends KJUR.asn1.ASN1Object
      -977  * @description 
      -978  * <br/>
      -979  * As for argument 'params' for constructor, you can specify one of
      -980  * following properties:
      -981  * <ul>
      -982  * <li>bin - specify binary string (ex. '10111')</li>
      -983  * <li>array - specify array of boolean (ex. [true,false,true,true])</li>
      -984  * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li>
      -985  * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} 
      -986  * argument for "BitString encapsulates" structure.</li>
      -987  * </ul>
      -988  * NOTE1: 'params' can be omitted.<br/>
      -989  * NOTE2: 'obj' parameter have been supported since
      -990  * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/>
      -991  *
      -992  * @example
      -993  * // default constructor
      -994  * o = new KJUR.asn1.DERBitString();
      -995  * // initialize with binary string
      -996  * o = new KJUR.asn1.DERBitString({bin: "1011"});
      -997  * // initialize with boolean array
      -998  * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]});
      -999  * // initialize with hexadecimal string (04 is unused bits)
      -1000  * o = new KJUR.asn1.DERBitString({hex: "04bac0"});
      -1001  * // initialize with ASN1Util.newObject argument for encapsulated
      -1002  * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
      -1003  * // above generates a ASN.1 data like this:
      -1004  * // BIT STRING, encapsulates {
      -1005  * //   SEQUENCE {
      -1006  * //     INTEGER 3
      -1007  * //     PrintableString 'aaa'
      -1008  * //     }
      -1009  * //   } 
      -1010  */
      -1011 KJUR.asn1.DERBitString = function(params) {
      -1012     if (params !== undefined && typeof params.obj !== "undefined") {
      -1013 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
      -1014 	params.hex = "00" + o.tohex();
      -1015     }
      -1016     KJUR.asn1.DERBitString.superclass.constructor.call(this);
      -1017     this.hT = "03";
      -1018 
      -1019     /**
      -1020      * set ASN.1 value(V) by a hexadecimal string including unused bits
      -1021      * @name setHexValueIncludingUnusedBits
      -1022      * @memberOf KJUR.asn1.DERBitString#
      -1023      * @function
      -1024      * @param {String} newHexStringIncludingUnusedBits
      -1025      */
      -1026     this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) {
      -1027         this.hTLV = null;
      -1028         this.isModified = true;
      -1029         this.hV = newHexStringIncludingUnusedBits;
      -1030     };
      -1031 
      -1032     /**
      -1033      * set ASN.1 value(V) by unused bit and hexadecimal string of value
      -1034      * @name setUnusedBitsAndHexValue
      -1035      * @memberOf KJUR.asn1.DERBitString#
      -1036      * @function
      -1037      * @param {Integer} unusedBits
      -1038      * @param {String} hValue
      -1039      */
      -1040     this.setUnusedBitsAndHexValue = function(unusedBits, hValue) {
      -1041         if (unusedBits < 0 || 7 < unusedBits) {
      -1042             throw "unused bits shall be from 0 to 7: u = " + unusedBits;
      -1043         }
      -1044         var hUnusedBits = "0" + unusedBits;
      -1045         this.hTLV = null;
      -1046         this.isModified = true;
      -1047         this.hV = hUnusedBits + hValue;
      -1048     };
      -1049 
      -1050     /**
      -1051      * set ASN.1 DER BitString by binary string<br/>
      -1052      * @name setByBinaryString
      -1053      * @memberOf KJUR.asn1.DERBitString#
      -1054      * @function
      -1055      * @param {String} binaryString binary value string (i.e. '10111')
      -1056      * @description
      -1057      * Its unused bits will be calculated automatically by length of 
      -1058      * 'binaryValue'. <br/>
      -1059      * NOTE: Leading zeros '0' will be ignored.
      -1060      * @example
      -1061      * o = new KJUR.asn1.DERBitString();
      -1062      * o.setByBinaryString("1011");
      -1063      * o.setByBinaryString("001"); // leading zeros ignored
      -1064      */
      -1065     this.setByBinaryString = function(binaryString) {
      -1066         binaryString = binaryString.replace(/0+$/, '');
      -1067         var unusedBits = 8 - binaryString.length % 8;
      -1068         if (unusedBits == 8) unusedBits = 0;
      -1069 	
      -1070 	binaryString += "0000000".substr(0, unusedBits);
      -1071 
      -1072         var h = '';
      -1073         for (var i = 0; i < binaryString.length - 1; i += 8) {
      -1074             var b = binaryString.substr(i, 8);
      -1075             var x = parseInt(b, 2).toString(16);
      -1076             if (x.length == 1) x = '0' + x;
      -1077             h += x;  
      -1078         }
      -1079         this.hTLV = null;
      -1080         this.isModified = true;
      -1081         this.hV = '0' + unusedBits + h;
      -1082     };
      -1083 
      -1084     /**
      -1085      * set ASN.1 TLV value(V) by an array of boolean<br/>
      -1086      * @name setByBooleanArray
      -1087      * @memberOf KJUR.asn1.DERBitString#
      -1088      * @function
      -1089      * @param {array} booleanArray array of boolean (ex. [true, false, true])
      -1090      * @description
      -1091      * NOTE: Trailing falses will be ignored in the ASN.1 DER Object.
      -1092      * @example
      -1093      * o = new KJUR.asn1.DERBitString();
      -1094      * o.setByBooleanArray([false, true, false, true, true]);
      -1095      */
      -1096     this.setByBooleanArray = function(booleanArray) {
      -1097         var s = '';
      -1098         for (var i = 0; i < booleanArray.length; i++) {
      -1099             if (booleanArray[i] == true) {
      -1100                 s += '1';
      -1101             } else {
      -1102                 s += '0';
      -1103             }
      -1104         }
      -1105         this.setByBinaryString(s);
      -1106     };
      -1107 
      -1108     /**
      -1109      * generate an array of falses with specified length<br/>
      -1110      * @name newFalseArray
      -1111      * @memberOf KJUR.asn1.DERBitString
      -1112      * @function
      -1113      * @param {Integer} nLength length of array to generate
      -1114      * @return {array} array of boolean falses
      -1115      * @description
      -1116      * This static method may be useful to initialize boolean array.
      -1117      * @example
      -1118      * o = new KJUR.asn1.DERBitString();
      -1119      * o.newFalseArray(3) → [false, false, false]
      -1120      */
      -1121     this.newFalseArray = function(nLength) {
      -1122         var a = new Array(nLength);
      -1123         for (var i = 0; i < nLength; i++) {
      -1124             a[i] = false;
      -1125         }
      -1126         return a;
      -1127     };
      -1128 
      -1129     this.getFreshValueHex = function() {
      -1130         return this.hV;
      -1131     };
      -1132 
      -1133     if (typeof params != "undefined") {
      -1134         if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) {
      -1135             this.setHexValueIncludingUnusedBits(params);
      -1136         } else if (typeof params['hex'] != "undefined") {
      -1137             this.setHexValueIncludingUnusedBits(params['hex']);
      -1138         } else if (typeof params['bin'] != "undefined") {
      -1139             this.setByBinaryString(params['bin']);
      -1140         } else if (typeof params['array'] != "undefined") {
      -1141             this.setByBooleanArray(params['array']);
      -1142         }
      -1143     }
      -1144 };
      -1145 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object);
      -1146 
      -1147 // ********************************************************************
      -1148 /**
      -1149  * class for ASN.1 DER OctetString<br/>
      -1150  * @name KJUR.asn1.DEROctetString
      -1151  * @class class for ASN.1 DER OctetString
      -1152  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1153  * @extends KJUR.asn1.DERAbstractString
      -1154  * @description
      -1155  * This class provides ASN.1 OctetString simple type.<br/>
      -1156  * Supported "params" attributes are:
      -1157  * <ul>
      -1158  * <li>str - to set a string as a value</li>
      -1159  * <li>hex - to set a hexadecimal string as a value</li>
      -1160  * <li>obj - to set a encapsulated ASN.1 value by JSON object 
      -1161  * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li>
      -1162  * </ul>
      -1163  * NOTE: A parameter 'obj' have been supported 
      -1164  * for "OCTET STRING, encapsulates" structure.
      -1165  * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).
      -1166  * @see KJUR.asn1.DERAbstractString - superclass
      -1167  * @example
      -1168  * // default constructor
      -1169  * o = new KJUR.asn1.DEROctetString();
      -1170  * // initialize with string
      -1171  * o = new KJUR.asn1.DEROctetString({str: "aaa"});
      -1172  * // initialize with hexadecimal string
      -1173  * o = new KJUR.asn1.DEROctetString({hex: "616161"});
      -1174  * // initialize with ASN1Util.newObject argument 
      -1175  * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
      -1176  * // above generates a ASN.1 data like this:
      -1177  * // OCTET STRING, encapsulates {
      -1178  * //   SEQUENCE {
      -1179  * //     INTEGER 3
      -1180  * //     PrintableString 'aaa'
      -1181  * //     }
      -1182  * //   } 
      -1183  */
      -1184 KJUR.asn1.DEROctetString = function(params) {
      -1185     if (params !== undefined && typeof params.obj !== "undefined") {
      -1186 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
      -1187 	params.hex = o.tohex();
      -1188     }
      -1189     KJUR.asn1.DEROctetString.superclass.constructor.call(this, params);
      -1190     this.hT = "04";
      -1191 };
      -1192 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString);
      -1193 
      -1194 // ********************************************************************
      -1195 /**
      -1196  * class for ASN.1 DER Null
      -1197  * @name KJUR.asn1.DERNull
      -1198  * @class class for ASN.1 DER Null
      -1199  * @extends KJUR.asn1.ASN1Object
      -1200  * @description
      -1201  * @see KJUR.asn1.ASN1Object - superclass
      -1202  */
      -1203 KJUR.asn1.DERNull = function() {
      -1204     KJUR.asn1.DERNull.superclass.constructor.call(this);
      -1205     this.hT = "05";
      -1206     this.hTLV = "0500";
      -1207 };
      -1208 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object);
      -1209 
      -1210 // ********************************************************************
      -1211 /**
      -1212  * class for ASN.1 DER ObjectIdentifier
      -1213  * @name KJUR.asn1.DERObjectIdentifier
      -1214  * @class class for ASN.1 DER ObjectIdentifier
      -1215  * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'})
      -1216  * @extends KJUR.asn1.ASN1Object
      -1217  * @see oidtohex
      -1218  * 
      -1219  * @description
      -1220  * <br/>
      -1221  * As for argument 'params' for constructor, you can specify one of
      -1222  * following properties:
      -1223  * <ul>
      -1224  * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li>
      -1225  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      -1226  * </ul>
      -1227  * NOTE: 'params' can be omitted.
      -1228  * @example
      -1229  * new DERObjectIdentifier({"name": "sha1"})
      -1230  * new DERObjectIdentifier({"oid": "1.2.3.4"})
      -1231  * new DERObjectIdentifier({"hex": "2d..."})
      -1232  * new DERObjectIdentifier("1.2.3.4")
      -1233  * new DERObjectIdentifier("SHA1withRSA")
      -1234  */
      -1235 KJUR.asn1.DERObjectIdentifier = function(params) {
      -1236     KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this);
      -1237     this.hT = "06";
      -1238 
      -1239     /**
      -1240      * set value by a hexadecimal string
      -1241      * @name setValueHex
      -1242      * @memberOf KJUR.asn1.DERObjectIdentifier#
      -1243      * @function
      -1244      * @param {String} newHexString hexadecimal value of OID bytes
      -1245      */
      -1246     this.setValueHex = function(newHexString) {
      -1247         this.hTLV = null;
      -1248         this.isModified = true;
      -1249         this.s = null;
      -1250         this.hV = newHexString;
      -1251     };
      -1252 
      -1253     /**
      -1254      * set value by a OID string<br/>
      -1255      * @name setValueOidString
      -1256      * @memberOf KJUR.asn1.DERObjectIdentifier#
      -1257      * @function
      -1258      * @param {String} oidString OID string (ex. 2.5.4.13)
      -1259      * @example
      -1260      * o = new KJUR.asn1.DERObjectIdentifier();
      -1261      * o.setValueOidString("2.5.4.13");
      -1262      */
      -1263     this.setValueOidString = function(oidString) {
      -1264 	var h = oidtohex(oidString);
      -1265 	if (h == null)
      -1266             throw new Error("malformed oid string: " + oidString);
      -1267         this.hTLV = null;
      -1268         this.isModified = true;
      -1269         this.s = null;
      -1270         this.hV = h;
      -1271     };
      -1272 
      -1273     /**
      -1274      * set value by a OID name
      -1275      * @name setValueName
      -1276      * @memberOf KJUR.asn1.DERObjectIdentifier#
      -1277      * @function
      -1278      * @param {String} oidName OID name (ex. 'serverAuth')
      -1279      * @since 1.0.1
      -1280      * @description
      -1281      * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'.
      -1282      * Otherwise raise error.
      -1283      * @example
      -1284      * o = new KJUR.asn1.DERObjectIdentifier();
      -1285      * o.setValueName("serverAuth");
      -1286      */
      -1287     this.setValueName = function(oidName) {
      -1288 	var oid = KJUR.asn1.x509.OID.name2oid(oidName);
      -1289 	if (oid !== '') {
      -1290             this.setValueOidString(oid);
      -1291         } else {
      -1292             throw new Error("DERObjectIdentifier oidName undefined: " + oidName);
      -1293         }
      -1294     };
      -1295 
      -1296     this.setValueNameOrOid = function(nameOrOid) {
      -1297 	if (nameOrOid.match(/^[0-2].[0-9.]+$/)) {
      -1298 	    this.setValueOidString(nameOrOid);
      -1299 	} else {
      -1300 	    this.setValueName(nameOrOid);
      -1301 	}
      -1302     }
      -1303 
      -1304     this.getFreshValueHex = function() {
      -1305         return this.hV;
      -1306     };
      -1307 
      -1308     this.setByParam = function(params) {
      -1309         if (typeof params === "string") {
      -1310 	    this.setValueNameOrOid(params);
      -1311         } else if (params.oid !== undefined) {
      -1312 	    this.setValueNameOrOid(params.oid);
      -1313         } else if (params.name !== undefined) {
      -1314             this.setValueNameOrOid(params.name);
      -1315         } else if (params.hex !== undefined) {
      -1316             this.setValueHex(params.hex);
      -1317         }
      -1318     };
      -1319 
      -1320     if (params !== undefined) this.setByParam(params);
      -1321 };
      -1322 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object);
      -1323 
      -1324 // ********************************************************************
      -1325 /**
      -1326  * class for ASN.1 DER Enumerated
      -1327  * @name KJUR.asn1.DEREnumerated
      -1328  * @class class for ASN.1 DER Enumerated
      -1329  * @extends KJUR.asn1.ASN1Object
      -1330  * @description
      -1331  * <br/>
      -1332  * As for argument 'params' for constructor, you can specify one of
      -1333  * following properties:
      -1334  * <ul>
      -1335  * <li>int - specify initial ASN.1 value(V) by integer value</li>
      -1336  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      -1337  * </ul>
      -1338  * NOTE: 'params' can be omitted.
      -1339  * @example
      -1340  * new KJUR.asn1.DEREnumerated(123);
      -1341  * new KJUR.asn1.DEREnumerated({int: 123});
      -1342  * new KJUR.asn1.DEREnumerated({hex: '1fad'});
      -1343  */
      -1344 KJUR.asn1.DEREnumerated = function(params) {
      -1345     KJUR.asn1.DEREnumerated.superclass.constructor.call(this);
      -1346     this.hT = "0a";
      -1347 
      -1348     /**
      -1349      * set value by Tom Wu's BigInteger object
      -1350      * @name setByBigInteger
      -1351      * @memberOf KJUR.asn1.DEREnumerated#
      -1352      * @function
      -1353      * @param {BigInteger} bigIntegerValue to set
      -1354      */
      -1355     this.setByBigInteger = function(bigIntegerValue) {
      -1356         this.hTLV = null;
      -1357         this.isModified = true;
      -1358         this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
      +864 KJUR.asn1.DERInteger = function(params) {
      +865     KJUR.asn1.DERInteger.superclass.constructor.call(this);
      +866     this.hT = "02";
      +867     this.params = null;
      +868     var _biToTwoCompl = twoscompl;
      +869 
      +870     /**
      +871      * set value by Tom Wu's BigInteger object
      +872      * @name setByBigInteger
      +873      * @memberOf KJUR.asn1.DERInteger#
      +874      * @function
      +875      * @param {BigInteger} bigIntegerValue to set
      +876      */
      +877     this.setByBigInteger = function(bigIntegerValue) {
      +878 	this.isModified = true;
      +879 	this.params = { bigint: bigIntegerValue };
      +880     };
      +881 
      +882     /**
      +883      * set value by integer value
      +884      * @name setByInteger
      +885      * @memberOf KJUR.asn1.DERInteger
      +886      * @function
      +887      * @param {Integer} integer value to set
      +888      */
      +889     this.setByInteger = function(intValue) {
      +890 	this.isModified = true;
      +891 	this.params = intValue;
      +892     };
      +893 
      +894     /**
      +895      * set value by integer value
      +896      * @name setValueHex
      +897      * @memberOf KJUR.asn1.DERInteger#
      +898      * @function
      +899      * @param {String} hexadecimal string of integer value
      +900      * @description
      +901      * <br/>
      +902      * NOTE: Value shall be represented by minimum octet length of
      +903      * two's complement representation.
      +904      * @example
      +905      * new KJUR.asn1.DERInteger(123);
      +906      * new KJUR.asn1.DERInteger({'int': 123});
      +907      * new KJUR.asn1.DERInteger({'hex': '1fad'});
      +908      * new KJUR.asn1.DERInteger({'bigint': new BigInteger("1234", 10)});
      +909      */
      +910     this.setValueHex = function(newHexString) {
      +911 	this.isModified = true;
      +912 	this.params = { hex: newHexString };
      +913     };
      +914 
      +915     this.getFreshValueHex = function() {
      +916 	var params = this.params;
      +917 	var bi = null;
      +918 	if (params == null) throw new Error("value not set");
      +919 
      +920 	if (typeof params == "object" && params.hex != undefined) {
      +921 	    this.hV = params.hex;
      +922             return this.hV;
      +923 	}
      +924 
      +925 	if (typeof params == "number") {
      +926 	    bi = new BigInteger(String(params), 10);
      +927 	} else if (params["int"] != undefined) {
      +928 	    bi = new BigInteger(String(params["int"]), 10);
      +929 	} else if (params.bigint != undefined) {
      +930 	    bi = params.bigint;
      +931 	} else {
      +932 	    throw new Error("wrong parameter");
      +933 	}
      +934 	this.hV = _biToTwoCompl(bi);
      +935         return this.hV;
      +936     };
      +937 
      +938     if (params != undefined) {
      +939 	this.params = params;
      +940     }
      +941 };
      +942 extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object);
      +943 
      +944 // ********************************************************************
      +945 /**
      +946  * class for ASN.1 DER encoded BitString primitive
      +947  * @name KJUR.asn1.DERBitString
      +948  * @class class for ASN.1 DER encoded BitString primitive
      +949  * @extends KJUR.asn1.ASN1Object
      +950  * @description 
      +951  * <br/>
      +952  * As for argument 'params' for constructor, you can specify one of
      +953  * following properties:
      +954  * <ul>
      +955  * <li>bin - specify binary string (ex. '10111')</li>
      +956  * <li>array - specify array of boolean (ex. [true,false,true,true])</li>
      +957  * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li>
      +958  * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} 
      +959  * argument for "BitString encapsulates" structure.</li>
      +960  * </ul>
      +961  * NOTE1: 'params' can be omitted.<br/>
      +962  * NOTE2: 'obj' parameter have been supported since
      +963  * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/>
      +964  *
      +965  * @example
      +966  * // default constructor
      +967  * o = new KJUR.asn1.DERBitString();
      +968  * // initialize with binary string
      +969  * o = new KJUR.asn1.DERBitString({bin: "1011"});
      +970  * // initialize with boolean array
      +971  * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]});
      +972  * // initialize with hexadecimal string (04 is unused bits)
      +973  * o = new KJUR.asn1.DERBitString({hex: "04bac0"});
      +974  * // initialize with ASN1Util.newObject argument for encapsulated
      +975  * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
      +976  * // above generates a ASN.1 data like this:
      +977  * // BIT STRING, encapsulates {
      +978  * //   SEQUENCE {
      +979  * //     INTEGER 3
      +980  * //     PrintableString 'aaa'
      +981  * //     }
      +982  * //   } 
      +983  */
      +984 KJUR.asn1.DERBitString = function(params) {
      +985     if (params !== undefined && typeof params.obj !== "undefined") {
      +986 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
      +987 	params.hex = "00" + o.tohex();
      +988     }
      +989     KJUR.asn1.DERBitString.superclass.constructor.call(this);
      +990     this.hT = "03";
      +991 
      +992     /**
      +993      * set ASN.1 value(V) by a hexadecimal string including unused bits
      +994      * @name setHexValueIncludingUnusedBits
      +995      * @memberOf KJUR.asn1.DERBitString#
      +996      * @function
      +997      * @param {String} newHexStringIncludingUnusedBits
      +998      */
      +999     this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) {
      +1000         this.hTLV = null;
      +1001         this.isModified = true;
      +1002         this.hV = newHexStringIncludingUnusedBits;
      +1003     };
      +1004 
      +1005     /**
      +1006      * set ASN.1 value(V) by unused bit and hexadecimal string of value
      +1007      * @name setUnusedBitsAndHexValue
      +1008      * @memberOf KJUR.asn1.DERBitString#
      +1009      * @function
      +1010      * @param {Integer} unusedBits
      +1011      * @param {String} hValue
      +1012      */
      +1013     this.setUnusedBitsAndHexValue = function(unusedBits, hValue) {
      +1014         if (unusedBits < 0 || 7 < unusedBits) {
      +1015             throw "unused bits shall be from 0 to 7: u = " + unusedBits;
      +1016         }
      +1017         var hUnusedBits = "0" + unusedBits;
      +1018         this.hTLV = null;
      +1019         this.isModified = true;
      +1020         this.hV = hUnusedBits + hValue;
      +1021     };
      +1022 
      +1023     /**
      +1024      * set ASN.1 DER BitString by binary string<br/>
      +1025      * @name setByBinaryString
      +1026      * @memberOf KJUR.asn1.DERBitString#
      +1027      * @function
      +1028      * @param {String} binaryString binary value string (i.e. '10111')
      +1029      * @description
      +1030      * Its unused bits will be calculated automatically by length of 
      +1031      * 'binaryValue'. <br/>
      +1032      * NOTE: Leading zeros '0' will be ignored.
      +1033      * @example
      +1034      * o = new KJUR.asn1.DERBitString();
      +1035      * o.setByBinaryString("1011");
      +1036      * o.setByBinaryString("001"); // leading zeros ignored
      +1037      */
      +1038     this.setByBinaryString = function(binaryString) {
      +1039         binaryString = binaryString.replace(/0+$/, '');
      +1040         var unusedBits = 8 - binaryString.length % 8;
      +1041         if (unusedBits == 8) unusedBits = 0;
      +1042 	
      +1043 	binaryString += "0000000".substr(0, unusedBits);
      +1044 
      +1045         var h = '';
      +1046         for (var i = 0; i < binaryString.length - 1; i += 8) {
      +1047             var b = binaryString.substr(i, 8);
      +1048             var x = parseInt(b, 2).toString(16);
      +1049             if (x.length == 1) x = '0' + x;
      +1050             h += x;  
      +1051         }
      +1052         this.hTLV = null;
      +1053         this.isModified = true;
      +1054         this.hV = '0' + unusedBits + h;
      +1055     };
      +1056 
      +1057     /**
      +1058      * set ASN.1 TLV value(V) by an array of boolean<br/>
      +1059      * @name setByBooleanArray
      +1060      * @memberOf KJUR.asn1.DERBitString#
      +1061      * @function
      +1062      * @param {array} booleanArray array of boolean (ex. [true, false, true])
      +1063      * @description
      +1064      * NOTE: Trailing falses will be ignored in the ASN.1 DER Object.
      +1065      * @example
      +1066      * o = new KJUR.asn1.DERBitString();
      +1067      * o.setByBooleanArray([false, true, false, true, true]);
      +1068      */
      +1069     this.setByBooleanArray = function(booleanArray) {
      +1070         var s = '';
      +1071         for (var i = 0; i < booleanArray.length; i++) {
      +1072             if (booleanArray[i] == true) {
      +1073                 s += '1';
      +1074             } else {
      +1075                 s += '0';
      +1076             }
      +1077         }
      +1078         this.setByBinaryString(s);
      +1079     };
      +1080 
      +1081     /**
      +1082      * generate an array of falses with specified length<br/>
      +1083      * @name newFalseArray
      +1084      * @memberOf KJUR.asn1.DERBitString
      +1085      * @function
      +1086      * @param {Integer} nLength length of array to generate
      +1087      * @return {array} array of boolean falses
      +1088      * @description
      +1089      * This static method may be useful to initialize boolean array.
      +1090      * @example
      +1091      * o = new KJUR.asn1.DERBitString();
      +1092      * o.newFalseArray(3) → [false, false, false]
      +1093      */
      +1094     this.newFalseArray = function(nLength) {
      +1095         var a = new Array(nLength);
      +1096         for (var i = 0; i < nLength; i++) {
      +1097             a[i] = false;
      +1098         }
      +1099         return a;
      +1100     };
      +1101 
      +1102     this.getFreshValueHex = function() {
      +1103         return this.hV;
      +1104     };
      +1105 
      +1106     if (typeof params != "undefined") {
      +1107         if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) {
      +1108             this.setHexValueIncludingUnusedBits(params);
      +1109         } else if (typeof params['hex'] != "undefined") {
      +1110             this.setHexValueIncludingUnusedBits(params['hex']);
      +1111         } else if (typeof params['bin'] != "undefined") {
      +1112             this.setByBinaryString(params['bin']);
      +1113         } else if (typeof params['array'] != "undefined") {
      +1114             this.setByBooleanArray(params['array']);
      +1115         }
      +1116     }
      +1117 };
      +1118 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object);
      +1119 
      +1120 // ********************************************************************
      +1121 /**
      +1122  * class for ASN.1 DER OctetString<br/>
      +1123  * @name KJUR.asn1.DEROctetString
      +1124  * @class class for ASN.1 DER OctetString
      +1125  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1126  * @extends KJUR.asn1.DERAbstractString
      +1127  * @description
      +1128  * This class provides ASN.1 OctetString simple type.<br/>
      +1129  * Supported "params" attributes are:
      +1130  * <ul>
      +1131  * <li>str - to set a string as a value</li>
      +1132  * <li>hex - to set a hexadecimal string as a value</li>
      +1133  * <li>obj - to set a encapsulated ASN.1 value by JSON object 
      +1134  * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li>
      +1135  * </ul>
      +1136  * NOTE: A parameter 'obj' have been supported 
      +1137  * for "OCTET STRING, encapsulates" structure.
      +1138  * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).
      +1139  * @see KJUR.asn1.DERAbstractString - superclass
      +1140  * @example
      +1141  * // default constructor
      +1142  * o = new KJUR.asn1.DEROctetString();
      +1143  * // initialize with string
      +1144  * o = new KJUR.asn1.DEROctetString({str: "aaa"});
      +1145  * // initialize with hexadecimal string
      +1146  * o = new KJUR.asn1.DEROctetString({hex: "616161"});
      +1147  * // initialize with ASN1Util.newObject argument 
      +1148  * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
      +1149  * // above generates a ASN.1 data like this:
      +1150  * // OCTET STRING, encapsulates {
      +1151  * //   SEQUENCE {
      +1152  * //     INTEGER 3
      +1153  * //     PrintableString 'aaa'
      +1154  * //     }
      +1155  * //   } 
      +1156  */
      +1157 KJUR.asn1.DEROctetString = function(params) {
      +1158     if (params !== undefined && typeof params.obj !== "undefined") {
      +1159 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
      +1160 	params.hex = o.tohex();
      +1161     }
      +1162     KJUR.asn1.DEROctetString.superclass.constructor.call(this, params);
      +1163     this.hT = "04";
      +1164 };
      +1165 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString);
      +1166 
      +1167 // ********************************************************************
      +1168 /**
      +1169  * class for ASN.1 DER Null
      +1170  * @name KJUR.asn1.DERNull
      +1171  * @class class for ASN.1 DER Null
      +1172  * @extends KJUR.asn1.ASN1Object
      +1173  * @description
      +1174  * @see KJUR.asn1.ASN1Object - superclass
      +1175  */
      +1176 KJUR.asn1.DERNull = function() {
      +1177     KJUR.asn1.DERNull.superclass.constructor.call(this);
      +1178     this.hT = "05";
      +1179     this.hTLV = "0500";
      +1180 };
      +1181 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object);
      +1182 
      +1183 // ********************************************************************
      +1184 /**
      +1185  * class for ASN.1 DER ObjectIdentifier
      +1186  * @name KJUR.asn1.DERObjectIdentifier
      +1187  * @class class for ASN.1 DER ObjectIdentifier
      +1188  * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'})
      +1189  * @extends KJUR.asn1.ASN1Object
      +1190  * @see oidtohex
      +1191  * 
      +1192  * @description
      +1193  * <br/>
      +1194  * As for argument 'params' for constructor, you can specify one of
      +1195  * following properties:
      +1196  * <ul>
      +1197  * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li>
      +1198  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      +1199  * </ul>
      +1200  * NOTE: 'params' can be omitted.
      +1201  * @example
      +1202  * new DERObjectIdentifier({"name": "sha1"})
      +1203  * new DERObjectIdentifier({"oid": "1.2.3.4"})
      +1204  * new DERObjectIdentifier({"hex": "2d..."})
      +1205  * new DERObjectIdentifier("1.2.3.4")
      +1206  * new DERObjectIdentifier("SHA1withRSA")
      +1207  */
      +1208 KJUR.asn1.DERObjectIdentifier = function(params) {
      +1209     KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this);
      +1210     this.hT = "06";
      +1211 
      +1212     /**
      +1213      * set value by a hexadecimal string
      +1214      * @name setValueHex
      +1215      * @memberOf KJUR.asn1.DERObjectIdentifier#
      +1216      * @function
      +1217      * @param {String} newHexString hexadecimal value of OID bytes
      +1218      */
      +1219     this.setValueHex = function(newHexString) {
      +1220         this.hTLV = null;
      +1221         this.isModified = true;
      +1222         this.s = null;
      +1223         this.hV = newHexString;
      +1224     };
      +1225 
      +1226     /**
      +1227      * set value by a OID string<br/>
      +1228      * @name setValueOidString
      +1229      * @memberOf KJUR.asn1.DERObjectIdentifier#
      +1230      * @function
      +1231      * @param {String} oidString OID string (ex. 2.5.4.13)
      +1232      * @example
      +1233      * o = new KJUR.asn1.DERObjectIdentifier();
      +1234      * o.setValueOidString("2.5.4.13");
      +1235      */
      +1236     this.setValueOidString = function(oidString) {
      +1237 	var h = oidtohex(oidString);
      +1238 	if (h == null)
      +1239             throw new Error("malformed oid string: " + oidString);
      +1240         this.hTLV = null;
      +1241         this.isModified = true;
      +1242         this.s = null;
      +1243         this.hV = h;
      +1244     };
      +1245 
      +1246     /**
      +1247      * set value by a OID name
      +1248      * @name setValueName
      +1249      * @memberOf KJUR.asn1.DERObjectIdentifier#
      +1250      * @function
      +1251      * @param {String} oidName OID name (ex. 'serverAuth')
      +1252      * @since 1.0.1
      +1253      * @description
      +1254      * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'.
      +1255      * Otherwise raise error.
      +1256      * @example
      +1257      * o = new KJUR.asn1.DERObjectIdentifier();
      +1258      * o.setValueName("serverAuth");
      +1259      */
      +1260     this.setValueName = function(oidName) {
      +1261 	var oid = KJUR.asn1.x509.OID.name2oid(oidName);
      +1262 	if (oid !== '') {
      +1263             this.setValueOidString(oid);
      +1264         } else {
      +1265             throw new Error("DERObjectIdentifier oidName undefined: " + oidName);
      +1266         }
      +1267     };
      +1268 
      +1269     this.setValueNameOrOid = function(nameOrOid) {
      +1270 	if (nameOrOid.match(/^[0-2].[0-9.]+$/)) {
      +1271 	    this.setValueOidString(nameOrOid);
      +1272 	} else {
      +1273 	    this.setValueName(nameOrOid);
      +1274 	}
      +1275     }
      +1276 
      +1277     this.getFreshValueHex = function() {
      +1278         return this.hV;
      +1279     };
      +1280 
      +1281     this.setByParam = function(params) {
      +1282         if (typeof params === "string") {
      +1283 	    this.setValueNameOrOid(params);
      +1284         } else if (params.oid !== undefined) {
      +1285 	    this.setValueNameOrOid(params.oid);
      +1286         } else if (params.name !== undefined) {
      +1287             this.setValueNameOrOid(params.name);
      +1288         } else if (params.hex !== undefined) {
      +1289             this.setValueHex(params.hex);
      +1290         }
      +1291     };
      +1292 
      +1293     if (params !== undefined) this.setByParam(params);
      +1294 };
      +1295 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object);
      +1296 
      +1297 // ********************************************************************
      +1298 /**
      +1299  * class for ASN.1 DER Enumerated
      +1300  * @name KJUR.asn1.DEREnumerated
      +1301  * @class class for ASN.1 DER Enumerated
      +1302  * @extends KJUR.asn1.ASN1Object
      +1303  * @description
      +1304  * <br/>
      +1305  * As for argument 'params' for constructor, you can specify one of
      +1306  * following properties:
      +1307  * <ul>
      +1308  * <li>int - specify initial ASN.1 value(V) by integer value</li>
      +1309  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
      +1310  * </ul>
      +1311  * NOTE: 'params' can be omitted.
      +1312  * @example
      +1313  * new KJUR.asn1.DEREnumerated(123);
      +1314  * new KJUR.asn1.DEREnumerated({int: 123});
      +1315  * new KJUR.asn1.DEREnumerated({hex: '1fad'});
      +1316  */
      +1317 KJUR.asn1.DEREnumerated = function(params) {
      +1318     KJUR.asn1.DEREnumerated.superclass.constructor.call(this);
      +1319     this.hT = "0a";
      +1320 
      +1321     /**
      +1322      * set value by Tom Wu's BigInteger object
      +1323      * @name setByBigInteger
      +1324      * @memberOf KJUR.asn1.DEREnumerated#
      +1325      * @function
      +1326      * @param {BigInteger} bigIntegerValue to set
      +1327      */
      +1328     this.setByBigInteger = function(bigIntegerValue) {
      +1329         this.hTLV = null;
      +1330         this.isModified = true;
      +1331         this.hV = twoscompl(bigIntegerValue);
      +1332     };
      +1333 
      +1334     /**
      +1335      * set value by integer value
      +1336      * @name setByInteger
      +1337      * @memberOf KJUR.asn1.DEREnumerated#
      +1338      * @function
      +1339      * @param {Integer} integer value to set
      +1340      */
      +1341     this.setByInteger = function(intValue) {
      +1342         var bi = new BigInteger(String(intValue), 10);
      +1343         this.setByBigInteger(bi);
      +1344     };
      +1345 
      +1346     /**
      +1347      * set value by integer value
      +1348      * @name setValueHex
      +1349      * @memberOf KJUR.asn1.DEREnumerated#
      +1350      * @function
      +1351      * @param {String} hexadecimal string of integer value
      +1352      * @description
      +1353      * <br/>
      +1354      * NOTE: Value shall be represented by minimum octet length of
      +1355      * two's complement representation.
      +1356      */
      +1357     this.setValueHex = function(newHexString) {
      +1358         this.hV = newHexString;
       1359     };
       1360 
      -1361     /**
      -1362      * set value by integer value
      -1363      * @name setByInteger
      -1364      * @memberOf KJUR.asn1.DEREnumerated#
      -1365      * @function
      -1366      * @param {Integer} integer value to set
      -1367      */
      -1368     this.setByInteger = function(intValue) {
      -1369         var bi = new BigInteger(String(intValue), 10);
      -1370         this.setByBigInteger(bi);
      -1371     };
      -1372 
      -1373     /**
      -1374      * set value by integer value
      -1375      * @name setValueHex
      -1376      * @memberOf KJUR.asn1.DEREnumerated#
      -1377      * @function
      -1378      * @param {String} hexadecimal string of integer value
      -1379      * @description
      -1380      * <br/>
      -1381      * NOTE: Value shall be represented by minimum octet length of
      -1382      * two's complement representation.
      -1383      */
      -1384     this.setValueHex = function(newHexString) {
      -1385         this.hV = newHexString;
      -1386     };
      -1387 
      -1388     this.getFreshValueHex = function() {
      -1389         return this.hV;
      -1390     };
      -1391 
      -1392     if (typeof params != "undefined") {
      -1393         if (typeof params['int'] != "undefined") {
      -1394             this.setByInteger(params['int']);
      -1395         } else if (typeof params == "number") {
      -1396             this.setByInteger(params);
      -1397         } else if (typeof params['hex'] != "undefined") {
      -1398             this.setValueHex(params['hex']);
      -1399         }
      -1400     }
      -1401 };
      -1402 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object);
      -1403 
      -1404 // ********************************************************************
      -1405 /**
      -1406  * class for ASN.1 DER UTF8String
      -1407  * @name KJUR.asn1.DERUTF8String
      -1408  * @class class for ASN.1 DER UTF8String
      -1409  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1410  * @extends KJUR.asn1.DERAbstractString
      -1411  * @description
      -1412  * @see KJUR.asn1.DERAbstractString - superclass
      -1413  */
      -1414 KJUR.asn1.DERUTF8String = function(params) {
      -1415     KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params);
      -1416     this.hT = "0c";
      -1417 };
      -1418 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString);
      -1419 
      -1420 // ********************************************************************
      -1421 /**
      -1422  * class for ASN.1 DER NumericString
      -1423  * @name KJUR.asn1.DERNumericString
      -1424  * @class class for ASN.1 DER NumericString
      -1425  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1426  * @extends KJUR.asn1.DERAbstractString
      -1427  * @description
      -1428  * @see KJUR.asn1.DERAbstractString - superclass
      -1429  */
      -1430 KJUR.asn1.DERNumericString = function(params) {
      -1431     KJUR.asn1.DERNumericString.superclass.constructor.call(this, params);
      -1432     this.hT = "12";
      -1433 };
      -1434 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString);
      -1435 
      -1436 // ********************************************************************
      -1437 /**
      -1438  * class for ASN.1 DER PrintableString
      -1439  * @name KJUR.asn1.DERPrintableString
      -1440  * @class class for ASN.1 DER PrintableString
      -1441  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1442  * @extends KJUR.asn1.DERAbstractString
      -1443  * @description
      -1444  * @see KJUR.asn1.DERAbstractString - superclass
      -1445  */
      -1446 KJUR.asn1.DERPrintableString = function(params) {
      -1447     KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params);
      -1448     this.hT = "13";
      -1449 };
      -1450 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString);
      -1451 
      -1452 // ********************************************************************
      -1453 /**
      -1454  * class for ASN.1 DER TeletexString
      -1455  * @name KJUR.asn1.DERTeletexString
      -1456  * @class class for ASN.1 DER TeletexString
      -1457  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1458  * @extends KJUR.asn1.DERAbstractString
      -1459  * @description
      -1460  * @see KJUR.asn1.DERAbstractString - superclass
      -1461  */
      -1462 KJUR.asn1.DERTeletexString = function(params) {
      -1463     KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params);
      -1464     this.hT = "14";
      -1465 };
      -1466 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString);
      -1467 
      -1468 // ********************************************************************
      -1469 /**
      -1470  * class for ASN.1 DER IA5String
      -1471  * @name KJUR.asn1.DERIA5String
      -1472  * @class class for ASN.1 DER IA5String
      -1473  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1474  * @extends KJUR.asn1.DERAbstractString
      -1475  * @description
      -1476  * @see KJUR.asn1.DERAbstractString - superclass
      -1477  */
      -1478 KJUR.asn1.DERIA5String = function(params) {
      -1479     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
      -1480     this.hT = "16";
      -1481 };
      -1482 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString);
      -1483 
      -1484 // ********************************************************************
      -1485 /**
      -1486  * class for ASN.1 DER VisibleString
      -1487  * @name KJUR.asn1.DERVisibleString
      -1488  * @class class for ASN.1 DER VisibleString
      -1489  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1490  * @extends KJUR.asn1.DERAbstractString
      -1491  * @since jsrsasign 8.0.23 asn1 1.0.15
      -1492  * @description
      -1493  * @see KJUR.asn1.DERAbstractString - superclass
      -1494  */
      -1495 KJUR.asn1.DERVisibleString = function(params) {
      -1496     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
      -1497     this.hT = "1a";
      -1498 };
      -1499 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString);
      -1500 
      -1501 // ********************************************************************
      -1502 /**
      -1503  * class for ASN.1 DER BMPString
      -1504  * @name KJUR.asn1.DERBMPString
      -1505  * @class class for ASN.1 DER BMPString
      -1506  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      -1507  * @extends KJUR.asn1.DERAbstractString
      -1508  * @since jsrsasign 8.0.23 asn1 1.0.15
      -1509  * @description
      -1510  * @see KJUR.asn1.DERAbstractString - superclass
      -1511  */
      -1512 KJUR.asn1.DERBMPString = function(params) {
      -1513     KJUR.asn1.DERBMPString.superclass.constructor.call(this, params);
      -1514     this.hT = "1e";
      -1515 };
      -1516 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString);
      -1517 
      -1518 // ********************************************************************
      -1519 /**
      -1520  * class for ASN.1 DER UTCTime
      -1521  * @name KJUR.asn1.DERUTCTime
      -1522  * @class class for ASN.1 DER UTCTime
      -1523  * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
      -1524  * @extends KJUR.asn1.DERAbstractTime
      -1525  * @see KJUR.asn1.DERGeneralizedTime
      -1526  * @see KJUR.asn1.x509.Time
      -1527  *
      -1528  * @description
      -1529  * <br/>
      -1530  * As for argument 'params' for constructor, you can specify one of
      -1531  * following properties:
      -1532  * <ul>
      -1533  * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li>
      -1534  * <li>date - specify Date object.</li>
      -1535  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
      -1536  * </ul>
      -1537  * NOTE1: 'params' can be omitted.
      -1538  * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22.
      -1539  *
      -1540  * <h4>EXAMPLES</h4>
      -1541  * @example
      -1542  * new DERUTCTime("20151231235959Z")
      -1543  * new DERUTCTime("20151231235959.123Z")
      -1544  * new DERUTCTime(new Date())
      -1545  * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
      -1546  * new DERUTCTime({str: "20151231235959.123Z"})
      -1547  * new DERUTCTime({date: new Date()})
      -1548  * new DERUTCTime({date: new Date(), millis: true})
      -1549  * new DERUTCTime({millis: true})
      -1550  */
      -1551 KJUR.asn1.DERUTCTime = function(params) {
      -1552     KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params);
      -1553     this.hT = "17";
      -1554     this.params = undefined;
      -1555 
      -1556     this.getFreshValueHex = function() {
      -1557 	var params = this.params;
      -1558 
      -1559 	if (this.params == undefined) params = { date: new Date() };
      -1560 
      -1561 	if (typeof params == "string") {
      -1562 	    if (params.match(/^[0-9]{12}Z$/) ||
      -1563 		params.match(/^[0-9]{12}\.[0-9]+Z$/)) {
      -1564 		this.hV = stohex(params);
      -1565 	    } else {
      -1566 		throw new Error("malformed string for UTCTime: " + params);
      -1567 	    }
      -1568 	} else if (params.str != undefined) {
      -1569 	    this.hV = stohex(params.str);
      -1570 	} else if (params.date == undefined && params.millis == true) {
      -1571 	    var date = new Date();
      -1572 	    this.hV = stohex(this.formatDate(date, 'utc', true));
      -1573 	} else if (params.date != undefined &&
      -1574 		   params.date instanceof Date) {
      -1575 	    var withMillis = (params.millis === true);
      -1576 	    this.hV = stohex(this.formatDate(params.date, 'utc', withMillis));
      -1577 	} else if (params instanceof Date) {
      -1578 	    this.hV = stohex(this.formatDate(params, 'utc'));
      -1579 	}
      -1580 
      -1581 	if (this.hV == undefined) {
      -1582 	    throw new Error("parameter not specified properly for UTCTime");
      -1583 	}
      -1584 	return this.hV;
      -1585     };
      -1586 
      -1587     if (params != undefined) this.setByParam(params);
      -1588 };
      -1589 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime);
      -1590 
      -1591 // ********************************************************************
      -1592 /**
      -1593  * class for ASN.1 DER GeneralizedTime
      -1594  * @name KJUR.asn1.DERGeneralizedTime
      -1595  * @class class for ASN.1 DER GeneralizedTime
      -1596  * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'})
      -1597  * @property {Boolean} withMillis flag to show milliseconds or not
      -1598  * @extends KJUR.asn1.DERAbstractTime
      -1599  * @see KJUR.asn1.DERUTCTime
      -1600  * @see KJUR.asn1.x509.Time
      -1601  *
      -1602  * @description
      -1603  * <br/>
      -1604  * As for argument 'params' for constructor, you can specify one of
      -1605  * following properties:
      -1606  * <ul>
      -1607  * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li>
      -1608  * <li>date - specify Date object.</li>
      -1609  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
      -1610  * </ul>
      -1611  * NOTE1: 'params' can be omitted.
      -1612  * NOTE2: 'millis' property is supported from asn1 1.0.6.
      -1613  *
      -1614  * <h4>EXAMPLES</h4>
      -1615  * @example
      -1616  * new DERGeneralizedTime("20151231235959Z")
      -1617  * new DERGeneralizedTime("20151231235959.123Z")
      -1618  * new DERGeneralizedTime(new Date())
      -1619  * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
      -1620  * new DERGeneralizedTime({str: "20151231235959.123Z"})
      -1621  * new DERGeneralizedTime({date: new Date()})
      -1622  * new DERGeneralizedTime({date: new Date(), millis: true})
      -1623  * new DERGeneralizedTime({millis: true})
      -1624  */
      -1625 KJUR.asn1.DERGeneralizedTime = function(params) {
      -1626     KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params);
      -1627     this.hT = "18";
      -1628     this.params = params;
      -1629 
      -1630     this.getFreshValueHex = function() {
      -1631 	var params = this.params;
      -1632 
      -1633 	if (this.params == undefined) params = { date: new Date() };
      -1634 
      -1635 	if (typeof params == "string") {
      -1636 	    if (params.match(/^[0-9]{14}Z$/) ||
      -1637 		params.match(/^[0-9]{14}\.[0-9]+Z$/)) {
      -1638 		this.hV = stohex(params);
      -1639 	    } else {
      -1640 		throw new Error("malformed string for GeneralizedTime: " + params);
      -1641 	    }
      -1642 	} else if (params.str != undefined) {
      -1643 	    this.hV = stohex(params.str);
      -1644 	} else if (params.date == undefined && params.millis == true) {
      -1645 	    var date = new Date();
      -1646 	    this.hV = stohex(this.formatDate(date, 'gen', true));
      -1647 	} else if (params.date != undefined &&
      -1648 		   params.date instanceof Date) {
      -1649 	    var withMillis = (params.millis === true);
      -1650 	    this.hV = stohex(this.formatDate(params.date, 'gen', withMillis));
      -1651 	} else if (params instanceof Date) {
      -1652 	    this.hV = stohex(this.formatDate(params, 'gen'));
      -1653 	}
      -1654 
      -1655 	if (this.hV == undefined) {
      -1656 	    throw new Error("parameter not specified properly for GeneralizedTime");
      -1657 	}
      -1658 	return this.hV;
      -1659     };
      -1660 
      -1661     if (params != undefined) this.setByParam(params);
      -1662 };
      -1663 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime);
      -1664 
      -1665 // ********************************************************************
      -1666 /**
      -1667  * class for ASN.1 DER Sequence
      -1668  * @name KJUR.asn1.DERSequence
      -1669  * @class class for ASN.1 DER Sequence
      -1670  * @extends KJUR.asn1.DERAbstractStructured
      -1671  * @description
      -1672  * <br/>
      -1673  * As for argument 'params' for constructor, you can specify one of
      -1674  * following properties:
      -1675  * <ul>
      -1676  * <li>array - specify array of ASN1Object to set elements of content</li>
      -1677  * </ul>
      -1678  * NOTE: 'params' can be omitted.
      -1679  */
      -1680 KJUR.asn1.DERSequence = function(params) {
      -1681     KJUR.asn1.DERSequence.superclass.constructor.call(this, params);
      -1682     this.hT = "30";
      -1683     this.getFreshValueHex = function() {
      -1684         var h = '';
      -1685         for (var i = 0; i < this.asn1Array.length; i++) {
      -1686             var asn1Obj = this.asn1Array[i];
      -1687             h += asn1Obj.tohex();
      -1688         }
      -1689         this.hV = h;
      -1690         return this.hV;
      -1691     };
      -1692 };
      -1693 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured);
      -1694 
      -1695 // ********************************************************************
      -1696 /**
      -1697  * class for ASN.1 DER Set
      -1698  * @name KJUR.asn1.DERSet
      -1699  * @class class for ASN.1 DER Set
      -1700  * @extends KJUR.asn1.DERAbstractStructured
      -1701  * @description
      -1702  * <br/>
      -1703  * As for argument 'params' for constructor, you can specify one of
      -1704  * following properties:
      -1705  * <ul>
      -1706  * <li>array - specify array of ASN1Object to set elements of content</li>
      -1707  * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li>
      -1708  * </ul>
      -1709  * NOTE1: 'params' can be omitted.<br/>
      -1710  * NOTE2: sortflag is supported since 1.0.5.
      -1711  */
      -1712 KJUR.asn1.DERSet = function(params) {
      -1713     KJUR.asn1.DERSet.superclass.constructor.call(this, params);
      -1714     this.hT = "31";
      -1715     this.sortFlag = true; // item shall be sorted only in ASN.1 DER
      -1716     this.getFreshValueHex = function() {
      -1717         var a = new Array();
      -1718         for (var i = 0; i < this.asn1Array.length; i++) {
      -1719             var asn1Obj = this.asn1Array[i];
      -1720             a.push(asn1Obj.tohex());
      -1721         }
      -1722         if (this.sortFlag == true) a.sort();
      -1723         this.hV = a.join('');
      -1724         return this.hV;
      -1725     };
      -1726 
      -1727     if (typeof params != "undefined") {
      -1728         if (typeof params.sortflag != "undefined" &&
      -1729             params.sortflag == false)
      -1730             this.sortFlag = false;
      -1731     }
      -1732 };
      -1733 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured);
      -1734 
      -1735 // ********************************************************************
      -1736 /**
      -1737  * class for ASN.1 DER TaggedObject
      -1738  * @name KJUR.asn1.DERTaggedObject
      -1739  * @class class for ASN.1 DER TaggedObject
      -1740  * @extends KJUR.asn1.ASN1Object
      -1741  * @see KJUR_asn1.ASN1Util.newObject
      -1742  *
      -1743  * @description
      -1744  * <br/>
      -1745  * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object.
      -1746  * For example, if you find '[1]' tag in a ASN.1 dump, 
      -1747  * 'tagNoHex' will be 'a1'.
      -1748  * <br/>
      -1749  * As for optional argument 'params' for constructor, you can specify *ANY* of
      -1750  * following properties:
      -1751  * <ul>
      -1752  * <li>tag - specify tag (default is 'a0' which means [0])</li>
      -1753  * <li>explicit - specify true if this is explicit tag otherwise false 
      -1754  *     (default is 'true').</li>
      -1755  * <li>obj - specify ASN1Object or JSON object which will be tagged</li>
      -1756  * <li>tage - specify tag with explicit</li>
      -1757  * <li>tagi - specify tag with implicit</li>
      -1758  * </ul>
      -1759  * As for the member "obj" value of JSON object, 
      -1760  * {@link KJUR_asn1.ASN1Util.newObject} is used to generate.
      -1761  *
      -1762  * @example
      -1763  * // by JSON
      -1764  * new KJUR.asn1.DERTaggedObject({
      -1765  *  tag:'a0', explicit: true, obj: { "prnstr": { "str": "aaa" } }
      -1766  * }).tohex()
      -1767  *
      -1768  * // by ASN1Object object
      -1769  * new KJUR.asn1.DERTaggedObject({
      -1770  *  tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
      -1771  * }) 
      -1772  * new KJUR.asn1.DERTaggedObject({
      -1773  *  tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit
      -1774  * }) 
      -1775  * new KJUR.asn1.DERTaggedObject({
      -1776  *  tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
      -1777  * }) 
      -1778  *
      -1779  * // to hexadecimal
      -1780  * d1 = new KJUR.asn1.DERUTF8String({str':'a'})
      -1781  * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1});
      -1782  * hex = d2.tohex();
      -1783  */
      -1784 KJUR.asn1.DERTaggedObject = function(params) {
      -1785     KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
      -1786 
      -1787     var _KJUR_asn1 = KJUR.asn1,
      -1788 	_ASN1HEX = ASN1HEX,
      -1789 	_getV = _ASN1HEX.getV,
      -1790 	_isASN1HEX = _ASN1HEX.isASN1HEX,
      -1791 	_newObject = _KJUR_asn1.ASN1Util.newObject;
      +1361     this.getFreshValueHex = function() {
      +1362         return this.hV;
      +1363     };
      +1364 
      +1365     if (typeof params != "undefined") {
      +1366         if (typeof params['int'] != "undefined") {
      +1367             this.setByInteger(params['int']);
      +1368         } else if (typeof params == "number") {
      +1369             this.setByInteger(params);
      +1370         } else if (typeof params['hex'] != "undefined") {
      +1371             this.setValueHex(params['hex']);
      +1372         }
      +1373     }
      +1374 };
      +1375 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object);
      +1376 
      +1377 // ********************************************************************
      +1378 /**
      +1379  * class for ASN.1 DER UTF8String
      +1380  * @name KJUR.asn1.DERUTF8String
      +1381  * @class class for ASN.1 DER UTF8String
      +1382  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1383  * @extends KJUR.asn1.DERAbstractString
      +1384  * @description
      +1385  * @see KJUR.asn1.DERAbstractString - superclass
      +1386  */
      +1387 KJUR.asn1.DERUTF8String = function(params) {
      +1388     KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params);
      +1389     this.hT = "0c";
      +1390 };
      +1391 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString);
      +1392 
      +1393 // ********************************************************************
      +1394 /**
      +1395  * class for ASN.1 DER NumericString
      +1396  * @name KJUR.asn1.DERNumericString
      +1397  * @class class for ASN.1 DER NumericString
      +1398  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1399  * @extends KJUR.asn1.DERAbstractString
      +1400  * @description
      +1401  * @see KJUR.asn1.DERAbstractString - superclass
      +1402  */
      +1403 KJUR.asn1.DERNumericString = function(params) {
      +1404     KJUR.asn1.DERNumericString.superclass.constructor.call(this, params);
      +1405     this.hT = "12";
      +1406 };
      +1407 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString);
      +1408 
      +1409 // ********************************************************************
      +1410 /**
      +1411  * class for ASN.1 DER PrintableString
      +1412  * @name KJUR.asn1.DERPrintableString
      +1413  * @class class for ASN.1 DER PrintableString
      +1414  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1415  * @extends KJUR.asn1.DERAbstractString
      +1416  * @description
      +1417  * @see KJUR.asn1.DERAbstractString - superclass
      +1418  */
      +1419 KJUR.asn1.DERPrintableString = function(params) {
      +1420     KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params);
      +1421     this.hT = "13";
      +1422 };
      +1423 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString);
      +1424 
      +1425 // ********************************************************************
      +1426 /**
      +1427  * class for ASN.1 DER TeletexString
      +1428  * @name KJUR.asn1.DERTeletexString
      +1429  * @class class for ASN.1 DER TeletexString
      +1430  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1431  * @extends KJUR.asn1.DERAbstractString
      +1432  * @description
      +1433  * @see KJUR.asn1.DERAbstractString - superclass
      +1434  */
      +1435 KJUR.asn1.DERTeletexString = function(params) {
      +1436     KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params);
      +1437     this.hT = "14";
      +1438 };
      +1439 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString);
      +1440 
      +1441 // ********************************************************************
      +1442 /**
      +1443  * class for ASN.1 DER IA5String
      +1444  * @name KJUR.asn1.DERIA5String
      +1445  * @class class for ASN.1 DER IA5String
      +1446  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1447  * @extends KJUR.asn1.DERAbstractString
      +1448  * @description
      +1449  * @see KJUR.asn1.DERAbstractString - superclass
      +1450  */
      +1451 KJUR.asn1.DERIA5String = function(params) {
      +1452     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
      +1453     this.hT = "16";
      +1454 };
      +1455 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString);
      +1456 
      +1457 // ********************************************************************
      +1458 /**
      +1459  * class for ASN.1 DER VisibleString
      +1460  * @name KJUR.asn1.DERVisibleString
      +1461  * @class class for ASN.1 DER VisibleString
      +1462  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1463  * @extends KJUR.asn1.DERAbstractString
      +1464  * @since jsrsasign 8.0.23 asn1 1.0.15
      +1465  * @description
      +1466  * @see KJUR.asn1.DERAbstractString - superclass
      +1467  */
      +1468 KJUR.asn1.DERVisibleString = function(params) {
      +1469     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
      +1470     this.hT = "1a";
      +1471 };
      +1472 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString);
      +1473 
      +1474 // ********************************************************************
      +1475 /**
      +1476  * class for ASN.1 DER BMPString
      +1477  * @name KJUR.asn1.DERBMPString
      +1478  * @class class for ASN.1 DER BMPString
      +1479  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
      +1480  * @extends KJUR.asn1.DERAbstractString
      +1481  * @since jsrsasign 8.0.23 asn1 1.0.15
      +1482  * @description
      +1483  * @see KJUR.asn1.DERAbstractString - superclass
      +1484  */
      +1485 KJUR.asn1.DERBMPString = function(params) {
      +1486     KJUR.asn1.DERBMPString.superclass.constructor.call(this, params);
      +1487     this.hT = "1e";
      +1488 };
      +1489 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString);
      +1490 
      +1491 // ********************************************************************
      +1492 /**
      +1493  * class for ASN.1 DER UTCTime
      +1494  * @name KJUR.asn1.DERUTCTime
      +1495  * @class class for ASN.1 DER UTCTime
      +1496  * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
      +1497  * @extends KJUR.asn1.DERAbstractTime
      +1498  * @see KJUR.asn1.DERGeneralizedTime
      +1499  * @see KJUR.asn1.x509.Time
      +1500  *
      +1501  * @description
      +1502  * <br/>
      +1503  * As for argument 'params' for constructor, you can specify one of
      +1504  * following properties:
      +1505  * <ul>
      +1506  * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li>
      +1507  * <li>date - specify Date object.</li>
      +1508  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
      +1509  * </ul>
      +1510  * NOTE1: 'params' can be omitted.
      +1511  * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22.
      +1512  *
      +1513  * <h4>EXAMPLES</h4>
      +1514  * @example
      +1515  * new DERUTCTime("20151231235959Z")
      +1516  * new DERUTCTime("20151231235959.123Z")
      +1517  * new DERUTCTime(new Date())
      +1518  * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
      +1519  * new DERUTCTime({str: "20151231235959.123Z"})
      +1520  * new DERUTCTime({date: new Date()})
      +1521  * new DERUTCTime({date: new Date(), millis: true})
      +1522  * new DERUTCTime({millis: true})
      +1523  */
      +1524 KJUR.asn1.DERUTCTime = function(params) {
      +1525     KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params);
      +1526     this.hT = "17";
      +1527     this.params = undefined;
      +1528 
      +1529     this.getFreshValueHex = function() {
      +1530 	var params = this.params;
      +1531 
      +1532 	if (this.params == undefined) params = { date: new Date() };
      +1533 
      +1534 	if (typeof params == "string") {
      +1535 	    if (params.match(/^[0-9]{12}Z$/) ||
      +1536 		params.match(/^[0-9]{12}\.[0-9]+Z$/)) {
      +1537 		this.hV = stohex(params);
      +1538 	    } else {
      +1539 		throw new Error("malformed string for UTCTime: " + params);
      +1540 	    }
      +1541 	} else if (params.str != undefined) {
      +1542 	    this.hV = stohex(params.str);
      +1543 	} else if (params.date == undefined && params.millis == true) {
      +1544 	    var date = new Date();
      +1545 	    this.hV = stohex(this.formatDate(date, 'utc', true));
      +1546 	} else if (params.date != undefined &&
      +1547 		   params.date instanceof Date) {
      +1548 	    var withMillis = (params.millis === true);
      +1549 	    this.hV = stohex(this.formatDate(params.date, 'utc', withMillis));
      +1550 	} else if (params instanceof Date) {
      +1551 	    this.hV = stohex(this.formatDate(params, 'utc'));
      +1552 	}
      +1553 
      +1554 	if (this.hV == undefined) {
      +1555 	    throw new Error("parameter not specified properly for UTCTime");
      +1556 	}
      +1557 	return this.hV;
      +1558     };
      +1559 
      +1560     if (params != undefined) this.setByParam(params);
      +1561 };
      +1562 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime);
      +1563 
      +1564 // ********************************************************************
      +1565 /**
      +1566  * class for ASN.1 DER GeneralizedTime
      +1567  * @name KJUR.asn1.DERGeneralizedTime
      +1568  * @class class for ASN.1 DER GeneralizedTime
      +1569  * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'})
      +1570  * @property {Boolean} withMillis flag to show milliseconds or not
      +1571  * @extends KJUR.asn1.DERAbstractTime
      +1572  * @see KJUR.asn1.DERUTCTime
      +1573  * @see KJUR.asn1.x509.Time
      +1574  *
      +1575  * @description
      +1576  * <br/>
      +1577  * As for argument 'params' for constructor, you can specify one of
      +1578  * following properties:
      +1579  * <ul>
      +1580  * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li>
      +1581  * <li>date - specify Date object.</li>
      +1582  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
      +1583  * </ul>
      +1584  * NOTE1: 'params' can be omitted.
      +1585  * NOTE2: 'millis' property is supported from asn1 1.0.6.
      +1586  *
      +1587  * <h4>EXAMPLES</h4>
      +1588  * @example
      +1589  * new DERGeneralizedTime("20151231235959Z")
      +1590  * new DERGeneralizedTime("20151231235959.123Z")
      +1591  * new DERGeneralizedTime(new Date())
      +1592  * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
      +1593  * new DERGeneralizedTime({str: "20151231235959.123Z"})
      +1594  * new DERGeneralizedTime({date: new Date()})
      +1595  * new DERGeneralizedTime({date: new Date(), millis: true})
      +1596  * new DERGeneralizedTime({millis: true})
      +1597  */
      +1598 KJUR.asn1.DERGeneralizedTime = function(params) {
      +1599     KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params);
      +1600     this.hT = "18";
      +1601     this.params = params;
      +1602 
      +1603     this.getFreshValueHex = function() {
      +1604 	var params = this.params;
      +1605 
      +1606 	if (this.params == undefined) params = { date: new Date() };
      +1607 
      +1608 	if (typeof params == "string") {
      +1609 	    if (params.match(/^[0-9]{14}Z$/) ||
      +1610 		params.match(/^[0-9]{14}\.[0-9]+Z$/)) {
      +1611 		this.hV = stohex(params);
      +1612 	    } else {
      +1613 		throw new Error("malformed string for GeneralizedTime: " + params);
      +1614 	    }
      +1615 	} else if (params.str != undefined) {
      +1616 	    this.hV = stohex(params.str);
      +1617 	} else if (params.date == undefined && params.millis == true) {
      +1618 	    var date = new Date();
      +1619 	    this.hV = stohex(this.formatDate(date, 'gen', true));
      +1620 	} else if (params.date != undefined &&
      +1621 		   params.date instanceof Date) {
      +1622 	    var withMillis = (params.millis === true);
      +1623 	    this.hV = stohex(this.formatDate(params.date, 'gen', withMillis));
      +1624 	} else if (params instanceof Date) {
      +1625 	    this.hV = stohex(this.formatDate(params, 'gen'));
      +1626 	}
      +1627 
      +1628 	if (this.hV == undefined) {
      +1629 	    throw new Error("parameter not specified properly for GeneralizedTime");
      +1630 	}
      +1631 	return this.hV;
      +1632     };
      +1633 
      +1634     if (params != undefined) this.setByParam(params);
      +1635 };
      +1636 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime);
      +1637 
      +1638 // ********************************************************************
      +1639 /**
      +1640  * class for ASN.1 DER Sequence
      +1641  * @name KJUR.asn1.DERSequence
      +1642  * @class class for ASN.1 DER Sequence
      +1643  * @extends KJUR.asn1.DERAbstractStructured
      +1644  * @description
      +1645  * <br/>
      +1646  * As for argument 'params' for constructor, you can specify one of
      +1647  * following properties:
      +1648  * <ul>
      +1649  * <li>array - specify array of ASN1Object to set elements of content</li>
      +1650  * </ul>
      +1651  * NOTE: 'params' can be omitted.
      +1652  */
      +1653 KJUR.asn1.DERSequence = function(params) {
      +1654     KJUR.asn1.DERSequence.superclass.constructor.call(this, params);
      +1655     this.hT = "30";
      +1656     this.getFreshValueHex = function() {
      +1657         var h = '';
      +1658         for (var i = 0; i < this.asn1Array.length; i++) {
      +1659             var asn1Obj = this.asn1Array[i];
      +1660             h += asn1Obj.tohex();
      +1661         }
      +1662         this.hV = h;
      +1663         return this.hV;
      +1664     };
      +1665 };
      +1666 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured);
      +1667 
      +1668 // ********************************************************************
      +1669 /**
      +1670  * class for ASN.1 DER Set
      +1671  * @name KJUR.asn1.DERSet
      +1672  * @class class for ASN.1 DER Set
      +1673  * @extends KJUR.asn1.DERAbstractStructured
      +1674  * @description
      +1675  * <br/>
      +1676  * As for argument 'params' for constructor, you can specify one of
      +1677  * following properties:
      +1678  * <ul>
      +1679  * <li>array - specify array of ASN1Object to set elements of content</li>
      +1680  * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li>
      +1681  * </ul>
      +1682  * NOTE1: 'params' can be omitted.<br/>
      +1683  * NOTE2: sortflag is supported since 1.0.5.
      +1684  */
      +1685 KJUR.asn1.DERSet = function(params) {
      +1686     KJUR.asn1.DERSet.superclass.constructor.call(this, params);
      +1687     this.hT = "31";
      +1688     this.sortFlag = true; // item shall be sorted only in ASN.1 DER
      +1689     this.getFreshValueHex = function() {
      +1690         var a = new Array();
      +1691         for (var i = 0; i < this.asn1Array.length; i++) {
      +1692             var asn1Obj = this.asn1Array[i];
      +1693             a.push(asn1Obj.tohex());
      +1694         }
      +1695         if (this.sortFlag == true) a.sort();
      +1696         this.hV = a.join('');
      +1697         return this.hV;
      +1698     };
      +1699 
      +1700     if (typeof params != "undefined") {
      +1701         if (typeof params.sortflag != "undefined" &&
      +1702             params.sortflag == false)
      +1703             this.sortFlag = false;
      +1704     }
      +1705 };
      +1706 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured);
      +1707 
      +1708 // ********************************************************************
      +1709 /**
      +1710  * class for ASN.1 DER TaggedObject
      +1711  * @name KJUR.asn1.DERTaggedObject
      +1712  * @class class for ASN.1 DER TaggedObject
      +1713  * @extends KJUR.asn1.ASN1Object
      +1714  * @see KJUR_asn1.ASN1Util.newObject
      +1715  *
      +1716  * @description
      +1717  * <br/>
      +1718  * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object.
      +1719  * For example, if you find '[1]' tag in a ASN.1 dump, 
      +1720  * 'tagNoHex' will be 'a1'.
      +1721  * <br/>
      +1722  * As for optional argument 'params' for constructor, you can specify *ANY* of
      +1723  * following properties:
      +1724  * <ul>
      +1725  * <li>tag - specify tag (default is 'a0' which means [0])</li>
      +1726  * <li>explicit - specify true if this is explicit tag otherwise false 
      +1727  *     (default is 'true').</li>
      +1728  * <li>obj - specify ASN1Object or JSON object which will be tagged</li>
      +1729  * <li>tage - specify tag with explicit</li>
      +1730  * <li>tagi - specify tag with implicit</li>
      +1731  * </ul>
      +1732  * As for the member "obj" value of JSON object, 
      +1733  * {@link KJUR_asn1.ASN1Util.newObject} is used to generate.
      +1734  *
      +1735  * @example
      +1736  * // by JSON
      +1737  * new KJUR.asn1.DERTaggedObject({
      +1738  *  tag:'a0', explicit: true, obj: { "prnstr": { "str": "aaa" } }
      +1739  * }).tohex()
      +1740  *
      +1741  * // by ASN1Object object
      +1742  * new KJUR.asn1.DERTaggedObject({
      +1743  *  tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
      +1744  * }) 
      +1745  * new KJUR.asn1.DERTaggedObject({
      +1746  *  tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit
      +1747  * }) 
      +1748  * new KJUR.asn1.DERTaggedObject({
      +1749  *  tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
      +1750  * }) 
      +1751  *
      +1752  * // to hexadecimal
      +1753  * d1 = new KJUR.asn1.DERUTF8String({str':'a'})
      +1754  * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1});
      +1755  * hex = d2.tohex();
      +1756  */
      +1757 KJUR.asn1.DERTaggedObject = function(params) {
      +1758     KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
      +1759 
      +1760     var _KJUR_asn1 = KJUR.asn1,
      +1761 	_ASN1HEX = ASN1HEX,
      +1762 	_getV = _ASN1HEX.getV,
      +1763 	_isASN1HEX = _ASN1HEX.isASN1HEX,
      +1764 	_newObject = _KJUR_asn1.ASN1Util.newObject;
      +1765 
      +1766     this.hT = "a0";
      +1767     this.hV = '';
      +1768     this.isExplicit = true;
      +1769     this.asn1Object = null;
      +1770     this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true};
      +1771 
      +1772     /**
      +1773      * set value by an ASN1Object
      +1774      * @name setString
      +1775      * @memberOf KJUR.asn1.DERTaggedObject#
      +1776      * @function
      +1777      * @param {Boolean} isExplicitFlag flag for explicit/implicit tag
      +1778      * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag
      +1779      * @param {ASN1Object} asn1Object ASN.1 to encapsulate
      +1780      * @deprecated since jsrsasign 10.5.4 please use setByParam instead
      +1781      */
      +1782     this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) {
      +1783 	this.params = {tag: tagNoHex,
      +1784 		       explicit: isExplicitFlag,
      +1785 		       obj: asn1Object};
      +1786     };
      +1787 
      +1788     this.getFreshValueHex = function() {
      +1789 	var params = this.params;
      +1790 
      +1791 	if (params.explicit == undefined) params.explicit = true;
       1792 
      -1793     this.hT = "a0";
      -1794     this.hV = '';
      -1795     this.isExplicit = true;
      -1796     this.asn1Object = null;
      -1797     this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true};
      -1798 
      -1799     /**
      -1800      * set value by an ASN1Object
      -1801      * @name setString
      -1802      * @memberOf KJUR.asn1.DERTaggedObject#
      -1803      * @function
      -1804      * @param {Boolean} isExplicitFlag flag for explicit/implicit tag
      -1805      * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag
      -1806      * @param {ASN1Object} asn1Object ASN.1 to encapsulate
      -1807      * @deprecated since jsrsasign 10.5.4 please use setByParam instead
      -1808      */
      -1809     this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) {
      -1810 	this.params = {tag: tagNoHex,
      -1811 		       explicit: isExplicitFlag,
      -1812 		       obj: asn1Object};
      -1813     };
      -1814 
      -1815     this.getFreshValueHex = function() {
      -1816 	var params = this.params;
      -1817 
      -1818 	if (params.explicit == undefined) params.explicit = true;
      -1819 
      -1820 	if (params.tage != undefined) {
      -1821 	    params.tag = params.tage;
      -1822 	    params.explicit = true;
      -1823 	}
      -1824 	if (params.tagi != undefined) {
      -1825 	    params.tag = params.tagi;
      -1826 	    params.explicit = false;
      -1827 	}
      -1828 
      -1829 	if (params.str != undefined) {
      -1830 	    this.hV = utf8tohex(params.str);
      -1831 	} else if (params.hex != undefined) {
      -1832 	    this.hV = params.hex;
      -1833 	} else if (params.obj != undefined) {
      -1834 	    var hV1;
      -1835 	    if (params.obj instanceof _KJUR_asn1.ASN1Object) {
      -1836 		hV1 = params.obj.tohex();
      -1837 	    } else if (typeof params.obj == "object") {
      -1838 		hV1 = _newObject(params.obj).tohex();
      -1839 	    }
      -1840 	    if (params.explicit) {
      -1841 		this.hV = hV1;
      -1842 	    } else {
      -1843 		this.hV = _getV(hV1, 0);
      -1844 	    }
      -1845 	} else {
      -1846 	    throw new Error("str, hex nor obj not specified");
      -1847 	}
      -1848 
      -1849 	if (params.tag == undefined) params.tag = "a0";
      -1850 	this.hT = params.tag;
      -1851         this.hTLV = null;
      -1852         this.isModified = true;
      -1853 
      -1854         return this.hV;
      -1855     };
      -1856 
      -1857     this.setByParam = function(params) {
      -1858 	this.params = params;
      -1859     };
      -1860 
      -1861     if (params !== undefined) this.setByParam(params);
      -1862 };
      -1863 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);
      -1864 
      \ No newline at end of file +1793
      if (params.tage != undefined) { +1794 params.tag = params.tage; +1795 params.explicit = true; +1796 } +1797 if (params.tagi != undefined) { +1798 params.tag = params.tagi; +1799 params.explicit = false; +1800 } +1801 +1802 if (params.str != undefined) { +1803 this.hV = utf8tohex(params.str); +1804 } else if (params.hex != undefined) { +1805 this.hV = params.hex; +1806 } else if (params.obj != undefined) { +1807 var hV1; +1808 if (params.obj instanceof _KJUR_asn1.ASN1Object) { +1809 hV1 = params.obj.tohex(); +1810 } else if (typeof params.obj == "object") { +1811 hV1 = _newObject(params.obj).tohex(); +1812 } +1813 if (params.explicit) { +1814 this.hV = hV1; +1815 } else { +1816 this.hV = _getV(hV1, 0); +1817 } +1818 } else { +1819 throw new Error("str, hex nor obj not specified"); +1820 } +1821 +1822 if (params.tag == undefined) params.tag = "a0"; +1823 this.hT = params.tag; +1824 this.hTLV = null; +1825 this.isModified = true; +1826 +1827 return this.hV; +1828 }; +1829 +1830 this.setByParam = function(params) { +1831 this.params = params; +1832 }; +1833 +1834 if (params !== undefined) this.setByParam(params); +1835 }; +1836 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); +1837
      \ No newline at end of file diff --git a/api/symbols/src/asn1x509-1.0.js.html b/api/symbols/src/asn1x509-1.0.js.html index 979ee832..4241fd36 100644 --- a/api/symbols/src/asn1x509-1.0.js.html +++ b/api/symbols/src/asn1x509-1.0.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
        1 /* asn1x509-2.1.20.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
      +	
        1 /* asn1x509-2.1.21.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
         2  */
         3 /*
         4  * asn1x509.js - ASN.1 DER encoder classes for X.509 certificate
      @@ -23,7 +23,7 @@
        16  * @fileOverview
        17  * @name asn1x509-1.0.js
        18  * @author Kenji Urushima kenji.urushima@gmail.com
      - 19  * @version jsrsasign 10.8.4 asn1x509 2.1.20 (2023-Apr-26)
      + 19  * @version jsrsasign 10.9.0 asn1x509 2.1.21 (2023-Nov-27)
        20  * @since jsrsasign 2.1
        21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
        22  */
      @@ -4491,487 +4491,496 @@
       4484     var _DERObjectIdentifier = KJUR.asn1.DERObjectIdentifier;
       4485 
       4486     this.name2oidList = {
      -4487         'sha1':                 '1.3.14.3.2.26',
      -4488         'sha256':               '2.16.840.1.101.3.4.2.1',
      -4489         'sha384':               '2.16.840.1.101.3.4.2.2',
      -4490         'sha512':               '2.16.840.1.101.3.4.2.3',
      -4491         'sha224':               '2.16.840.1.101.3.4.2.4',
      -4492         'md5':                  '1.2.840.113549.2.5',
      -4493         'md2':                  '1.3.14.7.2.2.1',
      -4494         'ripemd160':            '1.3.36.3.2.1',
      -4495 
      -4496         'MD2withRSA':           '1.2.840.113549.1.1.2',
      -4497         'MD4withRSA':           '1.2.840.113549.1.1.3',
      -4498         'MD5withRSA':           '1.2.840.113549.1.1.4',
      -4499         'SHA1withRSA':          '1.2.840.113549.1.1.5',
      -4500 	'pkcs1-MGF':		'1.2.840.113549.1.1.8',
      -4501 	'rsaPSS':		'1.2.840.113549.1.1.10',
      -4502         'SHA224withRSA':        '1.2.840.113549.1.1.14',
      -4503         'SHA256withRSA':        '1.2.840.113549.1.1.11',
      -4504         'SHA384withRSA':        '1.2.840.113549.1.1.12',
      -4505         'SHA512withRSA':        '1.2.840.113549.1.1.13',
      -4506 
      -4507         'SHA1withECDSA':        '1.2.840.10045.4.1',
      -4508         'SHA224withECDSA':      '1.2.840.10045.4.3.1',
      -4509         'SHA256withECDSA':      '1.2.840.10045.4.3.2',
      -4510         'SHA384withECDSA':      '1.2.840.10045.4.3.3',
      -4511         'SHA512withECDSA':      '1.2.840.10045.4.3.4',
      -4512 
      -4513         'dsa':                  '1.2.840.10040.4.1',
      -4514         'SHA1withDSA':          '1.2.840.10040.4.3',
      -4515         'SHA224withDSA':        '2.16.840.1.101.3.4.3.1',
      -4516         'SHA256withDSA':        '2.16.840.1.101.3.4.3.2',
      -4517 
      -4518         'rsaEncryption':        '1.2.840.113549.1.1.1',
      -4519 
      -4520 	// X.500 AttributeType defined in RFC 4514
      -4521         'commonName':			'2.5.4.3',
      -4522         'countryName':			'2.5.4.6',
      -4523         'localityName':			'2.5.4.7',
      -4524         'stateOrProvinceName':		'2.5.4.8',
      -4525         'streetAddress':		'2.5.4.9',
      -4526         'organizationName':		'2.5.4.10',
      -4527         'organizationalUnitName':	'2.5.4.11',
      -4528         'domainComponent':		'0.9.2342.19200300.100.1.25',
      -4529         'userId':			'0.9.2342.19200300.100.1.1',
      -4530 	// other AttributeType name string
      -4531 	'surname':			'2.5.4.4',
      -4532         'givenName':                    '2.5.4.42',
      -4533         'title':			'2.5.4.12',
      -4534 	'distinguishedName':		'2.5.4.49',
      -4535 	'emailAddress':			'1.2.840.113549.1.9.1',
      -4536 	// other AttributeType name string (no short name)
      -4537 	'description':			'2.5.4.13',
      -4538 	'businessCategory':		'2.5.4.15',
      -4539 	'postalCode':			'2.5.4.17',
      -4540 	'uniqueIdentifier':		'2.5.4.45',
      -4541 	'organizationIdentifier':	'2.5.4.97',
      -4542 	'jurisdictionOfIncorporationL':	'1.3.6.1.4.1.311.60.2.1.1',
      -4543 	'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2',
      -4544 	'jurisdictionOfIncorporationC':	'1.3.6.1.4.1.311.60.2.1.3',
      -4545 
      -4546         'subjectDirectoryAttributes': '2.5.29.9',
      -4547         'subjectKeyIdentifier': '2.5.29.14',
      -4548         'keyUsage':             '2.5.29.15',
      -4549         'subjectAltName':       '2.5.29.17',
      -4550         'issuerAltName':        '2.5.29.18',
      -4551         'basicConstraints':     '2.5.29.19',
      -4552         'cRLNumber':     	'2.5.29.20',
      -4553         'cRLReason':     	'2.5.29.21',
      -4554         'nameConstraints':      '2.5.29.30',
      -4555         'cRLDistributionPoints':'2.5.29.31',
      -4556         'certificatePolicies':  '2.5.29.32',
      -4557         'anyPolicy':  		'2.5.29.32.0',
      -4558 	'policyMappings':	'2.5.29.33',
      -4559         'authorityKeyIdentifier':'2.5.29.35',
      -4560         'policyConstraints':    '2.5.29.36',
      -4561         'extKeyUsage':          '2.5.29.37',
      -4562 	'inhibitAnyPolicy':	'2.5.29.54',
      -4563         'authorityInfoAccess':  '1.3.6.1.5.5.7.1.1',
      -4564         'ocsp':                 '1.3.6.1.5.5.7.48.1',
      -4565         'ocspBasic':            '1.3.6.1.5.5.7.48.1.1',
      -4566         'ocspNonce':            '1.3.6.1.5.5.7.48.1.2',
      -4567         'ocspNoCheck':          '1.3.6.1.5.5.7.48.1.5',
      -4568         'caIssuers':            '1.3.6.1.5.5.7.48.2',
      -4569 
      -4570         'anyExtendedKeyUsage':  '2.5.29.37.0',
      -4571         'serverAuth':           '1.3.6.1.5.5.7.3.1',
      -4572         'clientAuth':           '1.3.6.1.5.5.7.3.2',
      -4573         'codeSigning':          '1.3.6.1.5.5.7.3.3',
      -4574         'emailProtection':      '1.3.6.1.5.5.7.3.4',
      -4575         'timeStamping':         '1.3.6.1.5.5.7.3.8',
      -4576         'ocspSigning':          '1.3.6.1.5.5.7.3.9',
      -4577 
      -4578 	// 'otherNameForms':	'1.3.6.1.5.5.7.8',
      -4579 	'smtpUTF8Mailbox':	'1.3.6.1.5.5.7.8.9',
      -4580 
      -4581         'dateOfBirth':          '1.3.6.1.5.5.7.9.1',
      -4582         'placeOfBirth':         '1.3.6.1.5.5.7.9.2',
      -4583         'gender':               '1.3.6.1.5.5.7.9.3',
      -4584         'countryOfCitizenship': '1.3.6.1.5.5.7.9.4',
      -4585         'countryOfResidence':   '1.3.6.1.5.5.7.9.5',
      +4487 	'aes128-CBC':		'2.16.840.1.101.3.4.1.2',
      +4488 	'aes256-CBC':		'2.16.840.1.101.3.4.1.42',
      +4489 
      +4490         'sha1':                 '1.3.14.3.2.26',
      +4491         'sha256':               '2.16.840.1.101.3.4.2.1',
      +4492         'sha384':               '2.16.840.1.101.3.4.2.2',
      +4493         'sha512':               '2.16.840.1.101.3.4.2.3',
      +4494         'sha224':               '2.16.840.1.101.3.4.2.4',
      +4495         'md5':                  '1.2.840.113549.2.5',
      +4496         'md2':                  '1.3.14.7.2.2.1',
      +4497         'ripemd160':            '1.3.36.3.2.1',
      +4498 
      +4499 	'hmacWithSHA1':		'1.2.840.113549.2.7',
      +4500 	'hmacWithSHA224':	'1.2.840.113549.2.8',
      +4501 	'hmacWithSHA256':	'1.2.840.113549.2.9',
      +4502 	'hmacWithSHA384':	'1.2.840.113549.2.10',
      +4503 	'hmacWithSHA512':	'1.2.840.113549.2.11',
      +4504 
      +4505         'MD2withRSA':           '1.2.840.113549.1.1.2',
      +4506         'MD4withRSA':           '1.2.840.113549.1.1.3',
      +4507         'MD5withRSA':           '1.2.840.113549.1.1.4',
      +4508         'SHA1withRSA':          '1.2.840.113549.1.1.5',
      +4509 	'pkcs1-MGF':		'1.2.840.113549.1.1.8',
      +4510 	'rsaPSS':		'1.2.840.113549.1.1.10',
      +4511         'SHA224withRSA':        '1.2.840.113549.1.1.14',
      +4512         'SHA256withRSA':        '1.2.840.113549.1.1.11',
      +4513         'SHA384withRSA':        '1.2.840.113549.1.1.12',
      +4514         'SHA512withRSA':        '1.2.840.113549.1.1.13',
      +4515 
      +4516         'SHA1withECDSA':        '1.2.840.10045.4.1',
      +4517         'SHA224withECDSA':      '1.2.840.10045.4.3.1',
      +4518         'SHA256withECDSA':      '1.2.840.10045.4.3.2',
      +4519         'SHA384withECDSA':      '1.2.840.10045.4.3.3',
      +4520         'SHA512withECDSA':      '1.2.840.10045.4.3.4',
      +4521 
      +4522         'dsa':                  '1.2.840.10040.4.1',
      +4523         'SHA1withDSA':          '1.2.840.10040.4.3',
      +4524         'SHA224withDSA':        '2.16.840.1.101.3.4.3.1',
      +4525         'SHA256withDSA':        '2.16.840.1.101.3.4.3.2',
      +4526 
      +4527         'rsaEncryption':        '1.2.840.113549.1.1.1',
      +4528 
      +4529 	// X.500 AttributeType defined in RFC 4514
      +4530         'commonName':			'2.5.4.3',
      +4531         'countryName':			'2.5.4.6',
      +4532         'localityName':			'2.5.4.7',
      +4533         'stateOrProvinceName':		'2.5.4.8',
      +4534         'streetAddress':		'2.5.4.9',
      +4535         'organizationName':		'2.5.4.10',
      +4536         'organizationalUnitName':	'2.5.4.11',
      +4537         'domainComponent':		'0.9.2342.19200300.100.1.25',
      +4538         'userId':			'0.9.2342.19200300.100.1.1',
      +4539 	// other AttributeType name string
      +4540 	'surname':			'2.5.4.4',
      +4541         'givenName':                    '2.5.4.42',
      +4542         'title':			'2.5.4.12',
      +4543 	'distinguishedName':		'2.5.4.49',
      +4544 	'emailAddress':			'1.2.840.113549.1.9.1',
      +4545 	// other AttributeType name string (no short name)
      +4546 	'description':			'2.5.4.13',
      +4547 	'businessCategory':		'2.5.4.15',
      +4548 	'postalCode':			'2.5.4.17',
      +4549 	'uniqueIdentifier':		'2.5.4.45',
      +4550 	'organizationIdentifier':	'2.5.4.97',
      +4551 	'jurisdictionOfIncorporationL':	'1.3.6.1.4.1.311.60.2.1.1',
      +4552 	'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2',
      +4553 	'jurisdictionOfIncorporationC':	'1.3.6.1.4.1.311.60.2.1.3',
      +4554 
      +4555         'subjectDirectoryAttributes': '2.5.29.9',
      +4556         'subjectKeyIdentifier': '2.5.29.14',
      +4557         'keyUsage':             '2.5.29.15',
      +4558         'subjectAltName':       '2.5.29.17',
      +4559         'issuerAltName':        '2.5.29.18',
      +4560         'basicConstraints':     '2.5.29.19',
      +4561         'cRLNumber':     	'2.5.29.20',
      +4562         'cRLReason':     	'2.5.29.21',
      +4563         'nameConstraints':      '2.5.29.30',
      +4564         'cRLDistributionPoints':'2.5.29.31',
      +4565         'certificatePolicies':  '2.5.29.32',
      +4566         'anyPolicy':  		'2.5.29.32.0',
      +4567 	'policyMappings':	'2.5.29.33',
      +4568         'authorityKeyIdentifier':'2.5.29.35',
      +4569         'policyConstraints':    '2.5.29.36',
      +4570         'extKeyUsage':          '2.5.29.37',
      +4571 	'inhibitAnyPolicy':	'2.5.29.54',
      +4572         'authorityInfoAccess':  '1.3.6.1.5.5.7.1.1',
      +4573         'ocsp':                 '1.3.6.1.5.5.7.48.1',
      +4574         'ocspBasic':            '1.3.6.1.5.5.7.48.1.1',
      +4575         'ocspNonce':            '1.3.6.1.5.5.7.48.1.2',
      +4576         'ocspNoCheck':          '1.3.6.1.5.5.7.48.1.5',
      +4577         'caIssuers':            '1.3.6.1.5.5.7.48.2',
      +4578 
      +4579         'anyExtendedKeyUsage':  '2.5.29.37.0',
      +4580         'serverAuth':           '1.3.6.1.5.5.7.3.1',
      +4581         'clientAuth':           '1.3.6.1.5.5.7.3.2',
      +4582         'codeSigning':          '1.3.6.1.5.5.7.3.3',
      +4583         'emailProtection':      '1.3.6.1.5.5.7.3.4',
      +4584         'timeStamping':         '1.3.6.1.5.5.7.3.8',
      +4585         'ocspSigning':          '1.3.6.1.5.5.7.3.9',
       4586 
      -4587         'ecPublicKey':          '1.2.840.10045.2.1',
      -4588         'P-256':                '1.2.840.10045.3.1.7',
      -4589         'secp256r1':            '1.2.840.10045.3.1.7',
      -4590         'secp256k1':            '1.3.132.0.10',
      -4591         'secp384r1':            '1.3.132.0.34',
      -4592         'secp521r1':            '1.3.132.0.35',
      -4593 
      -4594         'pkcs5PBES2':           '1.2.840.113549.1.5.13',
      -4595         'pkcs5PBKDF2':          '1.2.840.113549.1.5.12',
      -4596 
      -4597         'des-EDE3-CBC':         '1.2.840.113549.3.7',
      -4598 
      -4599         'data':                 '1.2.840.113549.1.7.1', // CMS data
      -4600         'signed-data':          '1.2.840.113549.1.7.2', // CMS signed-data
      -4601         'enveloped-data':       '1.2.840.113549.1.7.3', // CMS enveloped-data
      -4602         'digested-data':        '1.2.840.113549.1.7.5', // CMS digested-data
      -4603         'encrypted-data':       '1.2.840.113549.1.7.6', // CMS encrypted-data
      -4604         'authenticated-data':   '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data
      -4605         'tstinfo':              '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo
      -4606 	'signingCertificate':	'1.2.840.113549.1.9.16.2.12',// SMIME
      -4607 	'timeStampToken':	'1.2.840.113549.1.9.16.2.14',// sigTS
      -4608 	'signaturePolicyIdentifier':	'1.2.840.113549.1.9.16.2.15',// cades
      -4609 	'etsArchiveTimeStamp':	'1.2.840.113549.1.9.16.2.27',// SMIME
      -4610 	'signingCertificateV2':	'1.2.840.113549.1.9.16.2.47',// SMIME
      -4611 	'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME
      -4612         'extensionRequest':     '1.2.840.113549.1.9.14',// CSR extensionRequest
      -4613 	'contentType':		'1.2.840.113549.1.9.3',//PKCS#9
      -4614 	'messageDigest':	'1.2.840.113549.1.9.4',//PKCS#9
      -4615 	'signingTime':		'1.2.840.113549.1.9.5',//PKCS#9
      -4616 	'counterSignature':	'1.2.840.113549.1.9.6',//PKCS#9
      -4617 	'archiveTimeStampV3':	'0.4.0.1733.2.4',//ETSI EN29319122/TS101733
      -4618 	'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe
      -4619 	'adobeTimeStamp':	'1.2.840.113583.1.1.9.1', // Adobe
      -4620 	// CABF S/MIME BR
      -4621 	'smimeMailboxLegacy':		'2.23.140.1.5.1.1',
      -4622 	'smimeMailboxMulti':		'2.23.140.1.5.1.2',
      -4623 	'smimeMailboxStrict':		'2.23.140.1.5.1.3',
      -4624 	'smimeOrganizationLegacy':	'2.23.140.1.5.2.1',
      -4625 	'smimeOrganizationMulti':	'2.23.140.1.5.2.2',
      -4626 	'smimeOrganizationStrict':	'2.23.140.1.5.2.3',
      -4627 	'smimeSponsorLegacy':		'2.23.140.1.5.3.1',
      -4628 	'smimeSponsorMulti':		'2.23.140.1.5.3.2',
      -4629 	'smimeSponsorStrict':		'2.23.140.1.5.3.3',
      -4630 	'smimeIndividualLegacy':	'2.23.140.1.5.4.1',
      -4631 	'smimeIndividualMulti':		'2.23.140.1.5.4.2',
      -4632 	'smimeIndividualStrict':	'2.23.140.1.5.4.3',
      -4633     };
      -4634 
      -4635     this.atype2oidList = {
      -4636 	// RFC 4514 AttributeType name string (MUST recognized)
      -4637         'CN':		'2.5.4.3',
      -4638         'L':		'2.5.4.7',
      -4639         'ST':		'2.5.4.8',
      -4640         'O':		'2.5.4.10',
      -4641         'OU':		'2.5.4.11',
      -4642         'C':		'2.5.4.6',
      -4643         'STREET':	'2.5.4.9',
      -4644         'DC':		'0.9.2342.19200300.100.1.25',
      -4645         'UID':		'0.9.2342.19200300.100.1.1',
      -4646 	// other AttributeType name string
      -4647 	// http://blog.livedoor.jp/k_urushima/archives/656114.html
      -4648         'SN':		'2.5.4.4', // surname
      -4649         'T':		'2.5.4.12', // title
      -4650         'GN':		'2.5.4.42', // givenName
      -4651         'DN':		'2.5.4.49', // distinguishedName
      -4652         'E':		'1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy
      -4653 	// other AttributeType name string (no short name)
      -4654 	'description':			'2.5.4.13',
      -4655 	'businessCategory':		'2.5.4.15',
      -4656 	'postalCode':			'2.5.4.17',
      -4657 	'serialNumber':			'2.5.4.5',
      -4658 	'uniqueIdentifier':		'2.5.4.45',
      -4659 	'organizationIdentifier':	'2.5.4.97',
      -4660 	'jurisdictionOfIncorporationL':	'1.3.6.1.4.1.311.60.2.1.1',
      -4661 	'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2',
      -4662 	'jurisdictionOfIncorporationC':	'1.3.6.1.4.1.311.60.2.1.3'
      -4663     };
      -4664     
      -4665     this.objCache = {};
      -4666 
      -4667     /**
      -4668      * get DERObjectIdentifier by registered OID name
      -4669      * @name name2obj
      -4670      * @memberOf KJUR.asn1.x509.OID
      -4671      * @function
      -4672      * @param {String} name OID
      -4673      * @return {Object} DERObjectIdentifier instance
      -4674      * @see KJUR.asn1.DERObjectIdentifier
      -4675      *
      -4676      * @description
      -4677      * This static method returns DERObjectIdentifier object
      -4678      * for the specified OID.
      -4679      *
      -4680      * @example
      -4681      * var asn1ObjOID = KJUR.asn1.x509.OID.name2obj('SHA1withRSA');
      -4682      */
      -4683     this.name2obj = function(name) {
      -4684         if (typeof this.objCache[name] != "undefined")
      -4685             return this.objCache[name];
      -4686         if (typeof this.name2oidList[name] == "undefined")
      -4687             throw "Name of ObjectIdentifier not defined: " + name;
      -4688         var oid = this.name2oidList[name];
      -4689         var obj = new _DERObjectIdentifier({'oid': oid});
      -4690         this.objCache[name] = obj;
      -4691         return obj;
      -4692     };
      -4693 
      -4694     /**
      -4695      * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/>
      -4696      * @name atype2obj
      -4697      * @memberOf KJUR.asn1.x509.OID
      -4698      * @function
      -4699      * @param {String} atype short attribute type name such like 'C', 'CN' or OID
      -4700      * @return KJUR.asn1.DERObjectIdentifier instance
      -4701      * @description
      -4702      * @example
      -4703      * KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3
      -4704      * KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11
      -4705      * KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9
      -4706      * KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9
      -4707      */
      -4708     this.atype2obj = function(atype) {
      -4709         if (this.objCache[atype] !== undefined)
      -4710             return this.objCache[atype];
      -4711 
      -4712 	var oid;
      -4713 
      -4714 	if (atype.match(/^\d+\.\d+\.[0-9.]+$/)) {
      -4715 	    oid = atype;
      -4716 	} else if (this.atype2oidList[atype] !== undefined) {
      -4717 	    oid = this.atype2oidList[atype];
      -4718 	} else if (this.name2oidList[atype] !== undefined) {
      -4719 	    oid = this.name2oidList[atype];
      -4720     	} else {
      -4721             throw new Error("AttributeType name undefined: " + atype);
      -4722 	}
      -4723         var obj = new _DERObjectIdentifier({'oid': oid});
      -4724         this.objCache[atype] = obj;
      -4725         return obj;
      -4726     };
      -4727 
      -4728     /**
      -4729      * register OID list<br/>
      -4730      * @name registerOIDs
      -4731      * @memberOf KJUR.asn1.x509.OID
      -4732      * @function
      -4733      * @param {object} oids associative array of names and oids
      -4734      * @since jsrsasign 10.5.2 asn1x509 2.1.11
      -4735      * @see KJUR.asn1.x509.OID.checkOIDs
      -4736      * 
      -4737      * @description
      -4738      * This static method to register an oids to existing list
      -4739      * additionally.
      -4740      *
      -4741      * @example
      -4742      * KJUR.asn1.x509.OID.checkOIDs({
      -4743      *   "test1": "4.5.7.8"
      -4744      * }) // do nothing for invalid list
      -4745      *
      -4746      * KJUR.asn1.x509.OID.registerOIDs({
      -4747      *   "test1": "1.2.3",
      -4748      *   "test2": "0.2.3.4.23",
      -4749      * }) // successfully registered
      -4750      *
      -4751      * KJUR.asn1.x509.OID.name2oid("test1") → "1.2.3"
      -4752      */
      -4753     this.registerOIDs = function(oids) {
      -4754 	if (! this.checkOIDs(oids)) return;
      -4755 	for (var name in oids) {
      -4756 	    this.name2oidList[name] = oids[name];
      -4757 	}
      -4758     };
      -4759 
      -4760     /**
      -4761      * check validity for OID list<br/>
      -4762      * @name checkOIDs
      -4763      * @memberOf KJUR.asn1.x509.OID
      -4764      * @function
      -4765      * @param {object} oids associative array of names and oids
      -4766      * @return {boolean} return true when valid OID list otherwise false
      -4767      * @since jsrsasign 10.5.2 asn1x509 2.1.11
      -4768      * @see KJUR.asn1.x509.OID.registOIDs
      -4769      * 
      -4770      * @description
      -4771      * This static method validates an associative array
      -4772      * as oid list.
      -4773      *
      -4774      * @example
      -4775      * KJUR.asn1.x509.OID.checkOIDs(*non-assoc-array*) → false
      -4776      * KJUR.asn1.x509.OID.checkOIDs({}) → false
      -4777      * KJUR.asn1.x509.OID.checkOIDs({"test1": "apple"}) → false
      -4778      * KJUR.asn1.x509.OID.checkOIDs({
      -4779      *   "test1": "1.2.3",
      -4780      *   "test2": "0.2.3.4.23",
      -4781      * }) → true // valid oids
      -4782      * KJUR.asn1.x509.OID.checkOIDs({
      -4783      *   "test1": "4.5.7.8"
      -4784      * }) → false // invalid oid
      -4785      */
      -4786     this.checkOIDs = function(oids) {
      -4787 	try {
      -4788 	    var nameList = Object.keys(oids);
      -4789 	    if (nameList.length == 0)
      -4790 		return false;
      -4791 	    nameList.map(function(value, index, array) {
      -4792 		var oid = this[value];
      -4793 		if (! oid.match(/^[0-2]\.[0-9.]+$/))
      -4794 		    throw new Error("value is not OID");
      -4795 	    }, oids);
      -4796 	    return true;
      -4797 	} catch(ex) {
      -4798 	    return false;
      -4799 	}
      -4800     };
      -4801 
      -4802 
      -4803 };
      -4804 
      -4805 /**
      -4806  * convert OID to name<br/>
      -4807  * @name oid2name
      -4808  * @memberOf KJUR.asn1.x509.OID
      -4809  * @function
      -4810  * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4)
      -4811  * @return {String} OID name if registered otherwise empty string
      -4812  * @since asn1x509 1.0.9
      -4813  * @description
      -4814  * This static method converts OID string to its name.
      -4815  * If OID is undefined then it returns empty string (i.e. '').
      -4816  * @example
      -4817  * KJUR.asn1.x509.OID.oid2name("1.3.6.1.5.5.7.1.1") → 'authorityInfoAccess'
      -4818  */
      -4819 KJUR.asn1.x509.OID.oid2name = function(oid) {
      -4820     var list = KJUR.asn1.x509.OID.name2oidList;
      -4821     for (var name in list) {
      -4822         if (list[name] == oid) return name;
      -4823     }
      -4824     return '';
      -4825 };
      -4826 
      -4827 /**
      -4828  * convert OID to AttributeType name<br/>
      -4829  * @name oid2atype
      -4830  * @memberOf KJUR.asn1.x509.OID
      -4831  * @function
      -4832  * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4)
      -4833  * @return {String} OID AttributeType name if registered otherwise oid
      -4834  * @since jsrsasign 6.2.2 asn1x509 1.0.18
      -4835  * @description
      -4836  * This static method converts OID string to its AttributeType name.
      -4837  * If OID is not defined in OID.atype2oidList associative array then it returns OID
      -4838  * specified as argument.
      -4839  * @example
      -4840  * KJUR.asn1.x509.OID.oid2atype("2.5.4.3") → CN
      -4841  * KJUR.asn1.x509.OID.oid2atype("1.3.6.1.4.1.311.60.2.1.3") → jurisdictionOfIncorporationC
      -4842  * KJUR.asn1.x509.OID.oid2atype("0.1.2.3.4") → 0.1.2.3.4 // unregistered OID
      -4843  */
      -4844 KJUR.asn1.x509.OID.oid2atype = function(oid) {
      -4845     var list = KJUR.asn1.x509.OID.atype2oidList;
      -4846     for (var atype in list) {
      -4847         if (list[atype] == oid) return atype;
      -4848     }
      -4849     return oid;
      -4850 };
      -4851 
      -4852 /**
      -4853  * convert OID name to OID value<br/>
      -4854  * @name name2oid
      -4855  * @memberOf KJUR.asn1.x509.OID
      -4856  * @function
      -4857  * @param {String} name OID name or OID (ex. "sha1" or "1.2.3.4")
      -4858  * @return {String} dot noted Object Identifer string (ex. 1.2.3.4)
      -4859  * @since asn1x509 1.0.11
      -4860  * @description
      -4861  * This static method converts from OID name to OID string.
      -4862  * If OID is undefined then it returns empty string (i.e. '').
      -4863  * @example
      -4864  * KJUR.asn1.x509.OID.name2oid("authorityInfoAccess") → "1.3.6.1.5.5.7.1.1"
      -4865  * KJUR.asn1.x509.OID.name2oid("1.2.3.4") → "1.2.3.4"
      -4866  * KJUR.asn1.x509.OID.name2oid("UNKNOWN NAME") → ""
      -4867  */
      -4868 KJUR.asn1.x509.OID.name2oid = function(name) {
      -4869     if (name.match(/^[0-9.]+$/)) return name;
      -4870     var list = KJUR.asn1.x509.OID.name2oidList;
      -4871     if (list[name] === undefined) return '';
      -4872     return list[name];
      -4873 };
      -4874 
      -4875 /**
      -4876  * X.509 certificate and CRL utilities class<br/>
      -4877  * @name KJUR.asn1.x509.X509Util
      -4878  * @class X.509 certificate and CRL utilities class
      -4879  */
      -4880 KJUR.asn1.x509.X509Util = {};
      -4881 
      -4882 /**
      -4883  * issue a certificate in PEM format (DEPRECATED)
      -4884  * @name newCertPEM
      -4885  * @memberOf KJUR.asn1.x509.X509Util
      -4886  * @function
      -4887  * @param {Array} param JSON object of parameter to issue a certificate
      -4888  * @since asn1x509 1.0.6
      -4889  * @deprecated since jsrsasign 9.0.0 asn1x509 2.0.0. please move to {@link KJUR.asn1.x509.Certificate} constructor
      -4890  * @description
      -4891  * This method can issue a certificate by a simple
      -4892  * JSON object.
      -4893  * Signature value will be provided by signing with
      -4894  * private key using 'cakey' parameter or
      -4895  * hexadecimal signature value by 'sighex' parameter.
      -4896  * <br/>
      -4897  * NOTE: Algorithm parameter of AlgorithmIdentifier will
      -4898  * be set automatically by default. 
      -4899  * (see {@link KJUR.asn1.x509.AlgorithmIdentifier})
      -4900  * from jsrsasign 7.1.1 asn1x509 1.0.20.
      -4901  * <br/>
      -4902  * NOTE2: 
      -4903  * RSA-PSS algorithm has been supported from jsrsasign 8.0.21.
      -4904  * As for RSA-PSS signature algorithm names and signing parameters 
      -4905  * such as MGF function and salt length, please see
      -4906  * {@link KJUR.asn1.x509.AlgorithmIdentifier} class.
      -4907  *
      -4908  * @example
      -4909  * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({
      -4910  *   serial: {int: 4},
      -4911  *   sigalg: {name: 'SHA1withECDSA'},
      -4912  *   issuer: {str: '/C=US/O=a'},
      -4913  *   notbefore: {'str': '130504235959Z'},
      -4914  *   notafter: {'str': '140504235959Z'},
      -4915  *   subject: {str: '/C=US/O=b'},
      -4916  *   sbjpubkey: pubKeyObj,
      -4917  *   ext: [
      -4918  *     {basicConstraints: {cA: true, critical: true}},
      -4919  *     {keyUsage: {bin: '11'}},
      -4920  *   ],
      -4921  *   cakey: prvKeyObj
      -4922  * });
      -4923  * // -- or --
      -4924  * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({
      -4925  *   serial: {int: 4},
      -4926  *   sigalg: {name: 'SHA1withECDSA'},
      -4927  *   issuer: {str: '/C=US/O=a'},
      -4928  *   notbefore: {'str': '130504235959Z'},
      -4929  *   notafter: {'str': '140504235959Z'},
      -4930  *   subject: {str: '/C=US/O=b'},
      -4931  *   sbjpubkey: pubKeyPEM,
      -4932  *   ext: [
      -4933  *     {basicConstraints: {cA: true, critical: true}},
      -4934  *     {keyUsage: {bin: '11'}},
      -4935  *   ],
      -4936  *   cakey: [prvkey, pass]}
      -4937  * );
      -4938  * // -- or --
      -4939  * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({
      -4940  *   serial: {int: 1},
      -4941  *   sigalg: {name: 'SHA1withRSA'},
      -4942  *   issuer: {str: '/C=US/O=T1'},
      -4943  *   notbefore: {'str': '130504235959Z'},
      -4944  *   notafter: {'str': '140504235959Z'},
      -4945  *   subject: {str: '/C=US/O=T1'},
      -4946  *   sbjpubkey: pubKeyObj,
      -4947  *   sighex: '0102030405..'
      -4948  * });
      -4949  * // for the issuer and subject field, another
      -4950  * // representation is also available
      -4951  * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({
      -4952  *   serial: {int: 1},
      -4953  *   sigalg: {name: 'SHA256withRSA'},
      -4954  *   issuer: {C: "US", O: "T1"},
      -4955  *   notbefore: {'str': '130504235959Z'},
      -4956  *   notafter: {'str': '140504235959Z'},
      -4957  *   subject: {C: "US", O: "T1", CN: "http://example.com/"},
      -4958  *   sbjpubkey: pubKeyObj,
      -4959  *   sighex: '0102030405..'
      -4960  * });
      -4961  */
      -4962 KJUR.asn1.x509.X509Util.newCertPEM = function(param) {
      -4963     var _KJUR_asn1_x509 = KJUR.asn1.x509,
      -4964 	_TBSCertificate = _KJUR_asn1_x509.TBSCertificate,
      -4965 	_Certificate = _KJUR_asn1_x509.Certificate;
      -4966     var cert = new _Certificate(param);
      -4967     return cert.getPEM();
      -4968 };
      -4969 
      -4970 
      \ No newline at end of file +4587
      // 'otherNameForms': '1.3.6.1.5.5.7.8', +4588 'smtpUTF8Mailbox': '1.3.6.1.5.5.7.8.9', +4589 +4590 'dateOfBirth': '1.3.6.1.5.5.7.9.1', +4591 'placeOfBirth': '1.3.6.1.5.5.7.9.2', +4592 'gender': '1.3.6.1.5.5.7.9.3', +4593 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', +4594 'countryOfResidence': '1.3.6.1.5.5.7.9.5', +4595 +4596 'ecPublicKey': '1.2.840.10045.2.1', +4597 'P-256': '1.2.840.10045.3.1.7', +4598 'secp256r1': '1.2.840.10045.3.1.7', +4599 'secp256k1': '1.3.132.0.10', +4600 'secp384r1': '1.3.132.0.34', +4601 'secp521r1': '1.3.132.0.35', +4602 +4603 'pkcs5PBES2': '1.2.840.113549.1.5.13', +4604 'pkcs5PBKDF2': '1.2.840.113549.1.5.12', +4605 +4606 'des-EDE3-CBC': '1.2.840.113549.3.7', +4607 +4608 'data': '1.2.840.113549.1.7.1', // CMS data +4609 'signed-data': '1.2.840.113549.1.7.2', // CMS signed-data +4610 'enveloped-data': '1.2.840.113549.1.7.3', // CMS enveloped-data +4611 'digested-data': '1.2.840.113549.1.7.5', // CMS digested-data +4612 'encrypted-data': '1.2.840.113549.1.7.6', // CMS encrypted-data +4613 'authenticated-data': '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data +4614 'tstinfo': '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo +4615 'signingCertificate': '1.2.840.113549.1.9.16.2.12',// SMIME +4616 'timeStampToken': '1.2.840.113549.1.9.16.2.14',// sigTS +4617 'signaturePolicyIdentifier': '1.2.840.113549.1.9.16.2.15',// cades +4618 'etsArchiveTimeStamp': '1.2.840.113549.1.9.16.2.27',// SMIME +4619 'signingCertificateV2': '1.2.840.113549.1.9.16.2.47',// SMIME +4620 'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME +4621 'extensionRequest': '1.2.840.113549.1.9.14',// CSR extensionRequest +4622 'contentType': '1.2.840.113549.1.9.3',//PKCS#9 +4623 'messageDigest': '1.2.840.113549.1.9.4',//PKCS#9 +4624 'signingTime': '1.2.840.113549.1.9.5',//PKCS#9 +4625 'counterSignature': '1.2.840.113549.1.9.6',//PKCS#9 +4626 'archiveTimeStampV3': '0.4.0.1733.2.4',//ETSI EN29319122/TS101733 +4627 'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe +4628 'adobeTimeStamp': '1.2.840.113583.1.1.9.1', // Adobe +4629 // CABF S/MIME BR +4630 'smimeMailboxLegacy': '2.23.140.1.5.1.1', +4631 'smimeMailboxMulti': '2.23.140.1.5.1.2', +4632 'smimeMailboxStrict': '2.23.140.1.5.1.3', +4633 'smimeOrganizationLegacy': '2.23.140.1.5.2.1', +4634 'smimeOrganizationMulti': '2.23.140.1.5.2.2', +4635 'smimeOrganizationStrict': '2.23.140.1.5.2.3', +4636 'smimeSponsorLegacy': '2.23.140.1.5.3.1', +4637 'smimeSponsorMulti': '2.23.140.1.5.3.2', +4638 'smimeSponsorStrict': '2.23.140.1.5.3.3', +4639 'smimeIndividualLegacy': '2.23.140.1.5.4.1', +4640 'smimeIndividualMulti': '2.23.140.1.5.4.2', +4641 'smimeIndividualStrict': '2.23.140.1.5.4.3', +4642 }; +4643 +4644 this.atype2oidList = { +4645 // RFC 4514 AttributeType name string (MUST recognized) +4646 'CN': '2.5.4.3', +4647 'L': '2.5.4.7', +4648 'ST': '2.5.4.8', +4649 'O': '2.5.4.10', +4650 'OU': '2.5.4.11', +4651 'C': '2.5.4.6', +4652 'STREET': '2.5.4.9', +4653 'DC': '0.9.2342.19200300.100.1.25', +4654 'UID': '0.9.2342.19200300.100.1.1', +4655 // other AttributeType name string +4656 // http://blog.livedoor.jp/k_urushima/archives/656114.html +4657 'SN': '2.5.4.4', // surname +4658 'T': '2.5.4.12', // title +4659 'GN': '2.5.4.42', // givenName +4660 'DN': '2.5.4.49', // distinguishedName +4661 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy +4662 // other AttributeType name string (no short name) +4663 'description': '2.5.4.13', +4664 'businessCategory': '2.5.4.15', +4665 'postalCode': '2.5.4.17', +4666 'serialNumber': '2.5.4.5', +4667 'uniqueIdentifier': '2.5.4.45', +4668 'organizationIdentifier': '2.5.4.97', +4669 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +4670 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +4671 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' +4672 }; +4673 +4674 this.objCache = {}; +4675 +4676 /** +4677 * get DERObjectIdentifier by registered OID name +4678 * @name name2obj +4679 * @memberOf KJUR.asn1.x509.OID +4680 * @function +4681 * @param {String} name OID +4682 * @return {Object} DERObjectIdentifier instance +4683 * @see KJUR.asn1.DERObjectIdentifier +4684 * +4685 * @description +4686 * This static method returns DERObjectIdentifier object +4687 * for the specified OID. +4688 * +4689 * @example +4690 * var asn1ObjOID = KJUR.asn1.x509.OID.name2obj('SHA1withRSA'); +4691 */ +4692 this.name2obj = function(name) { +4693 if (typeof this.objCache[name] != "undefined") +4694 return this.objCache[name]; +4695 if (typeof this.name2oidList[name] == "undefined") +4696 throw "Name of ObjectIdentifier not defined: " + name; +4697 var oid = this.name2oidList[name]; +4698 var obj = new _DERObjectIdentifier({'oid': oid}); +4699 this.objCache[name] = obj; +4700 return obj; +4701 }; +4702 +4703 /** +4704 * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/> +4705 * @name atype2obj +4706 * @memberOf KJUR.asn1.x509.OID +4707 * @function +4708 * @param {String} atype short attribute type name such like 'C', 'CN' or OID +4709 * @return KJUR.asn1.DERObjectIdentifier instance +4710 * @description +4711 * @example +4712 * KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3 +4713 * KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11 +4714 * KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9 +4715 * KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9 +4716 */ +4717 this.atype2obj = function(atype) { +4718 if (this.objCache[atype] !== undefined) +4719 return this.objCache[atype]; +4720 +4721 var oid; +4722 +4723 if (atype.match(/^\d+\.\d+\.[0-9.]+$/)) { +4724 oid = atype; +4725 } else if (this.atype2oidList[atype] !== undefined) { +4726 oid = this.atype2oidList[atype]; +4727 } else if (this.name2oidList[atype] !== undefined) { +4728 oid = this.name2oidList[atype]; +4729 } else { +4730 throw new Error("AttributeType name undefined: " + atype); +4731 } +4732 var obj = new _DERObjectIdentifier({'oid': oid}); +4733 this.objCache[atype] = obj; +4734 return obj; +4735 }; +4736 +4737 /** +4738 * register OID list<br/> +4739 * @name registerOIDs +4740 * @memberOf KJUR.asn1.x509.OID +4741 * @function +4742 * @param {object} oids associative array of names and oids +4743 * @since jsrsasign 10.5.2 asn1x509 2.1.11 +4744 * @see KJUR.asn1.x509.OID.checkOIDs +4745 * +4746 * @description +4747 * This static method to register an oids to existing list +4748 * additionally. +4749 * +4750 * @example +4751 * KJUR.asn1.x509.OID.checkOIDs({ +4752 * "test1": "4.5.7.8" +4753 * }) // do nothing for invalid list +4754 * +4755 * KJUR.asn1.x509.OID.registerOIDs({ +4756 * "test1": "1.2.3", +4757 * "test2": "0.2.3.4.23", +4758 * }) // successfully registered +4759 * +4760 * KJUR.asn1.x509.OID.name2oid("test1") → "1.2.3" +4761 */ +4762 this.registerOIDs = function(oids) { +4763 if (! this.checkOIDs(oids)) return; +4764 for (var name in oids) { +4765 this.name2oidList[name] = oids[name]; +4766 } +4767 }; +4768 +4769 /** +4770 * check validity for OID list<br/> +4771 * @name checkOIDs +4772 * @memberOf KJUR.asn1.x509.OID +4773 * @function +4774 * @param {object} oids associative array of names and oids +4775 * @return {boolean} return true when valid OID list otherwise false +4776 * @since jsrsasign 10.5.2 asn1x509 2.1.11 +4777 * @see KJUR.asn1.x509.OID.registOIDs +4778 * +4779 * @description +4780 * This static method validates an associative array +4781 * as oid list. +4782 * +4783 * @example +4784 * KJUR.asn1.x509.OID.checkOIDs(*non-assoc-array*) → false +4785 * KJUR.asn1.x509.OID.checkOIDs({}) → false +4786 * KJUR.asn1.x509.OID.checkOIDs({"test1": "apple"}) → false +4787 * KJUR.asn1.x509.OID.checkOIDs({ +4788 * "test1": "1.2.3", +4789 * "test2": "0.2.3.4.23", +4790 * }) → true // valid oids +4791 * KJUR.asn1.x509.OID.checkOIDs({ +4792 * "test1": "4.5.7.8" +4793 * }) → false // invalid oid +4794 */ +4795 this.checkOIDs = function(oids) { +4796 try { +4797 var nameList = Object.keys(oids); +4798 if (nameList.length == 0) +4799 return false; +4800 nameList.map(function(value, index, array) { +4801 var oid = this[value]; +4802 if (! oid.match(/^[0-2]\.[0-9.]+$/)) +4803 throw new Error("value is not OID"); +4804 }, oids); +4805 return true; +4806 } catch(ex) { +4807 return false; +4808 } +4809 }; +4810 +4811 +4812 }; +4813 +4814 /** +4815 * convert OID to name<br/> +4816 * @name oid2name +4817 * @memberOf KJUR.asn1.x509.OID +4818 * @function +4819 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) +4820 * @return {String} OID name if registered otherwise empty string +4821 * @since asn1x509 1.0.9 +4822 * @description +4823 * This static method converts OID string to its name. +4824 * If OID is undefined then it returns empty string (i.e. ''). +4825 * @example +4826 * KJUR.asn1.x509.OID.oid2name("1.3.6.1.5.5.7.1.1") → 'authorityInfoAccess' +4827 */ +4828 KJUR.asn1.x509.OID.oid2name = function(oid) { +4829 var list = KJUR.asn1.x509.OID.name2oidList; +4830 for (var name in list) { +4831 if (list[name] == oid) return name; +4832 } +4833 return ''; +4834 }; +4835 +4836 /** +4837 * convert OID to AttributeType name<br/> +4838 * @name oid2atype +4839 * @memberOf KJUR.asn1.x509.OID +4840 * @function +4841 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) +4842 * @return {String} OID AttributeType name if registered otherwise oid +4843 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +4844 * @description +4845 * This static method converts OID string to its AttributeType name. +4846 * If OID is not defined in OID.atype2oidList associative array then it returns OID +4847 * specified as argument. +4848 * @example +4849 * KJUR.asn1.x509.OID.oid2atype("2.5.4.3") → CN +4850 * KJUR.asn1.x509.OID.oid2atype("1.3.6.1.4.1.311.60.2.1.3") → jurisdictionOfIncorporationC +4851 * KJUR.asn1.x509.OID.oid2atype("0.1.2.3.4") → 0.1.2.3.4 // unregistered OID +4852 */ +4853 KJUR.asn1.x509.OID.oid2atype = function(oid) { +4854 var list = KJUR.asn1.x509.OID.atype2oidList; +4855 for (var atype in list) { +4856 if (list[atype] == oid) return atype; +4857 } +4858 return oid; +4859 }; +4860 +4861 /** +4862 * convert OID name to OID value<br/> +4863 * @name name2oid +4864 * @memberOf KJUR.asn1.x509.OID +4865 * @function +4866 * @param {String} name OID name or OID (ex. "sha1" or "1.2.3.4") +4867 * @return {String} dot noted Object Identifer string (ex. 1.2.3.4) +4868 * @since asn1x509 1.0.11 +4869 * @description +4870 * This static method converts from OID name to OID string. +4871 * If OID is undefined then it returns empty string (i.e. ''). +4872 * @example +4873 * KJUR.asn1.x509.OID.name2oid("authorityInfoAccess") → "1.3.6.1.5.5.7.1.1" +4874 * KJUR.asn1.x509.OID.name2oid("1.2.3.4") → "1.2.3.4" +4875 * KJUR.asn1.x509.OID.name2oid("UNKNOWN NAME") → "" +4876 */ +4877 KJUR.asn1.x509.OID.name2oid = function(name) { +4878 if (name.match(/^[0-9.]+$/)) return name; +4879 var list = KJUR.asn1.x509.OID.name2oidList; +4880 if (list[name] === undefined) return ''; +4881 return list[name]; +4882 }; +4883 +4884 /** +4885 * X.509 certificate and CRL utilities class<br/> +4886 * @name KJUR.asn1.x509.X509Util +4887 * @class X.509 certificate and CRL utilities class +4888 */ +4889 KJUR.asn1.x509.X509Util = {}; +4890 +4891 /** +4892 * issue a certificate in PEM format (DEPRECATED) +4893 * @name newCertPEM +4894 * @memberOf KJUR.asn1.x509.X509Util +4895 * @function +4896 * @param {Array} param JSON object of parameter to issue a certificate +4897 * @since asn1x509 1.0.6 +4898 * @deprecated since jsrsasign 9.0.0 asn1x509 2.0.0. please move to {@link KJUR.asn1.x509.Certificate} constructor +4899 * @description +4900 * This method can issue a certificate by a simple +4901 * JSON object. +4902 * Signature value will be provided by signing with +4903 * private key using 'cakey' parameter or +4904 * hexadecimal signature value by 'sighex' parameter. +4905 * <br/> +4906 * NOTE: Algorithm parameter of AlgorithmIdentifier will +4907 * be set automatically by default. +4908 * (see {@link KJUR.asn1.x509.AlgorithmIdentifier}) +4909 * from jsrsasign 7.1.1 asn1x509 1.0.20. +4910 * <br/> +4911 * NOTE2: +4912 * RSA-PSS algorithm has been supported from jsrsasign 8.0.21. +4913 * As for RSA-PSS signature algorithm names and signing parameters +4914 * such as MGF function and salt length, please see +4915 * {@link KJUR.asn1.x509.AlgorithmIdentifier} class. +4916 * +4917 * @example +4918 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4919 * serial: {int: 4}, +4920 * sigalg: {name: 'SHA1withECDSA'}, +4921 * issuer: {str: '/C=US/O=a'}, +4922 * notbefore: {'str': '130504235959Z'}, +4923 * notafter: {'str': '140504235959Z'}, +4924 * subject: {str: '/C=US/O=b'}, +4925 * sbjpubkey: pubKeyObj, +4926 * ext: [ +4927 * {basicConstraints: {cA: true, critical: true}}, +4928 * {keyUsage: {bin: '11'}}, +4929 * ], +4930 * cakey: prvKeyObj +4931 * }); +4932 * // -- or -- +4933 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4934 * serial: {int: 4}, +4935 * sigalg: {name: 'SHA1withECDSA'}, +4936 * issuer: {str: '/C=US/O=a'}, +4937 * notbefore: {'str': '130504235959Z'}, +4938 * notafter: {'str': '140504235959Z'}, +4939 * subject: {str: '/C=US/O=b'}, +4940 * sbjpubkey: pubKeyPEM, +4941 * ext: [ +4942 * {basicConstraints: {cA: true, critical: true}}, +4943 * {keyUsage: {bin: '11'}}, +4944 * ], +4945 * cakey: [prvkey, pass]} +4946 * ); +4947 * // -- or -- +4948 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4949 * serial: {int: 1}, +4950 * sigalg: {name: 'SHA1withRSA'}, +4951 * issuer: {str: '/C=US/O=T1'}, +4952 * notbefore: {'str': '130504235959Z'}, +4953 * notafter: {'str': '140504235959Z'}, +4954 * subject: {str: '/C=US/O=T1'}, +4955 * sbjpubkey: pubKeyObj, +4956 * sighex: '0102030405..' +4957 * }); +4958 * // for the issuer and subject field, another +4959 * // representation is also available +4960 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4961 * serial: {int: 1}, +4962 * sigalg: {name: 'SHA256withRSA'}, +4963 * issuer: {C: "US", O: "T1"}, +4964 * notbefore: {'str': '130504235959Z'}, +4965 * notafter: {'str': '140504235959Z'}, +4966 * subject: {C: "US", O: "T1", CN: "http://example.com/"}, +4967 * sbjpubkey: pubKeyObj, +4968 * sighex: '0102030405..' +4969 * }); +4970 */ +4971 KJUR.asn1.x509.X509Util.newCertPEM = function(param) { +4972 var _KJUR_asn1_x509 = KJUR.asn1.x509, +4973 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, +4974 _Certificate = _KJUR_asn1_x509.Certificate; +4975 var cert = new _Certificate(param); +4976 return cert.getPEM(); +4977 }; +4978 +4979
      \ No newline at end of file diff --git a/api/symbols/src/base64x-1.1.js.html b/api/symbols/src/base64x-1.1.js.html index f822b015..0974b5b9 100644 --- a/api/symbols/src/base64x-1.1.js.html +++ b/api/symbols/src/base64x-1.1.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
        1 /* base64x-1.1.33 (c) 2012-2023 Kenji Urushima | kjur.github.io/jsrsasign/license
      +	
        1 /* base64x-1.1.34 (c) 2012-2023 Kenji Urushima | kjur.github.io/jsrsasign/license
         2  */
         3 /*
         4  * base64x.js - Base64url and supplementary functions for Tom Wu's base64.js library
      @@ -23,7 +23,7 @@
        16  * @fileOverview
        17  * @name base64x-1.1.js
        18  * @author Kenji Urushima kenji.urushima@gmail.com
      - 19  * @version jsrsasign 10.8.4 base64x 1.1.33 (2023-Apr-26)
      + 19  * @version jsrsasign 10.9.0 base64x 1.1.34 (2023-Nov-27)
        20  * @since jsrsasign 2.1
        21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
        22  */
      @@ -1752,315 +1752,394 @@
       1745     }
       1746 };
       1747 
      -1748 /**
      -1749  * string padding<br/>
      -1750  * @name strpad
      -1751  * @function
      -1752  * @param {String} s input string
      -1753  * @param {Number} len output string length
      -1754  * @param {String} padchar padding character (default is "0")
      -1755  * @return {String} padded string
      -1756  * @since jsrsasign 10.1.0 base64x 1.1.18
      -1757  * @example
      -1758  * strpad("1234", 10, "0") → "0000001234"
      -1759  * strpad("1234", 10, " ") → "      1234"
      -1760  * strpad("1234", 10)      → "0000001234"
      -1761  */
      -1762 var strpad = function(s, len, padchar) {
      -1763     if (padchar == undefined) padchar = "0";
      -1764     if (s.length >= len) return s;
      -1765     return new Array(len - s.length + 1).join(padchar) + s;
      -1766 };
      -1767 
      -1768 // ==== bitstr hex / int =================================
      -1769 
      -1770 /**
      -1771  * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/>
      -1772  * @name bitstrtoint
      -1773  * @function
      -1774  * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit
      -1775  * @return {Number} positive integer value of the BitString
      -1776  * @since jsrsasign 10.1.3 base64x 1.1.19
      -1777  * @see inttobitstr
      -1778  * @see KJUR.asn1.DERBitString
      -1779  * @see ASN1HEX.getInt
      -1780  * 
      -1781  * @description
      -1782  * This function converts from hexadecimal string of ASN.1 BitString
      -1783  * value with unused bit to its integer value. <br/>
      -1784  * When an improper hexadecimal string of BitString value
      -1785  * is applied, this returns -1.
      -1786  * 
      -1787  * @example
      -1788  * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25
      -1789  * bitstrtoint("03c8") → 25
      -1790  * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02
      -1791  * //   11111111111110b → 16382
      -1792  * bitstrtoint("02fff8") → 16382
      -1793  * bitstrtoint("05a0") → 5 (=101b)
      -1794  * bitstrtoint("ff00") → -1 // for improper BitString value
      -1795  * bitstrtoint("05a0").toString(2) → "101"
      -1796  * bitstrtoint("07a080").toString(2) → "101000001"
      -1797  */
      -1798 function bitstrtoint(h) {
      -1799     if (h.length % 2 != 0) return -1; 
      -1800     h = h.toLowerCase();
      -1801     if (h.match(/^[0-9a-f]+$/) == null) return -1;
      -1802     try {
      -1803 	var hUnusedbit = h.substr(0, 2);
      -1804 	if (hUnusedbit == "00")
      -1805 	    return parseInt(h.substr(2), 16);
      -1806 	var iUnusedbit = parseInt(hUnusedbit, 16);
      -1807 	if (iUnusedbit > 7) return -1;
      -1808 	var hValue = h.substr(2);
      -1809 	var bValue = parseInt(hValue, 16).toString(2);
      -1810 	if (bValue == "0") bValue = "00000000";
      -1811 	bValue = bValue.slice(0, 0 - iUnusedbit);
      -1812 	var iValue = parseInt(bValue, 2);
      -1813 	if (iValue == NaN) return -1;
      -1814 	return iValue;
      -1815     } catch(ex) {
      -1816 	return -1;
      -1817     }
      -1818 };
      -1819 
      -1820 /**
      -1821  * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/>
      -1822  * @name inttobitstr
      -1823  * @function
      -1824  * @param {Number} n integer value of ASN.1 BitString
      -1825  * @return {String} hexadecimal string of ASN.1 BitString value with unused bit
      -1826  * @since jsrsasign 10.1.3 base64x 1.1.19
      -1827  * @see bitstrtoint
      -1828  * @see KJUR.asn1.DERBitString
      -1829  * @see ASN1HEX.getInt
      -1830  * 
      -1831  * @description
      -1832  * This function converts from an integer value to 
      -1833  * hexadecimal string of ASN.1 BitString value
      -1834  * with unused bit. <br/>
      -1835  * When "n" is not non-negative number, this returns null
      -1836  * 
      -1837  * @example
      -1838  * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8"
      -1839  * inttobitstr(25) → "03c8"
      -1840  * inttobitstr(-3) → null
      -1841  * inttobitstr("abc") → null
      -1842  * inttobitstr(parseInt("11001", 2)) → "03c8"
      -1843  * inttobitstr(parseInt("101", 2)) → "05a0"
      -1844  * inttobitstr(parseInt("101000001", 2)) → "07a080"
      -1845  */
      -1846 function inttobitstr(n) {
      -1847     if (typeof n != "number") return null;
      -1848     if (n < 0) return null;
      -1849     var bValue = Number(n).toString(2);
      -1850     var iUnusedbit = 8 - bValue.length % 8;
      -1851     if (iUnusedbit == 8) iUnusedbit = 0;
      -1852     bValue = bValue + strpad("", iUnusedbit, "0");
      -1853     var hValue = parseInt(bValue, 2).toString(16);
      -1854     if (hValue.length % 2 == 1) hValue = "0" + hValue;
      -1855     var hUnusedbit = "0" + iUnusedbit;
      -1856     return hUnusedbit + hValue;
      -1857 };
      -1858 
      -1859 // ==== bitstr hex / binary string =======================
      -1860 
      -1861 /**
      -1862  * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string<br/>
      -1863  * @name bitstrtobinstr
      -1864  * @function
      -1865  * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit
      -1866  * @return {string} binary string
      -1867  * @since jsrsasign 10.5.4 base64x 1.1.21
      -1868  * @see binstrtobitstr
      -1869  * @see inttobitstr
      -1870  * 
      -1871  * @description
      -1872  * This function converts from hexadecimal string of ASN.1 BitString
      -1873  * value with unused bit to its integer value. <br/>
      -1874  * When an improper hexadecimal string of BitString value
      -1875  * is applied, this returns null.
      -1876  * 
      -1877  * @example
      -1878  * bitstrtobinstr("05a0") → "101"
      -1879  * bitstrtobinstr("0520") → "001"
      -1880  * bitstrtobinstr("07a080") → "101000001"
      -1881  * bitstrtobinstr(502) → null // non ASN.1 BitString value
      -1882  * bitstrtobinstr("ff00") → null // for improper BitString value
      -1883  */
      -1884 function bitstrtobinstr(h) {
      -1885     if (typeof h != "string") return null;
      -1886     if (h.length % 2 != 0) return null;
      -1887     if (! h.match(/^[0-9a-f]+$/)) return null;
      -1888     try {
      -1889 	var unusedBits = parseInt(h.substr(0, 2), 16);
      -1890 	if (unusedBits < 0 || 7 < unusedBits) return null
      -1891 
      -1892 	var value = h.substr(2);
      -1893 	var bin = "";
      -1894 	for (var i = 0; i < value.length; i += 2) {
      -1895 	    var hi = value.substr(i, 2);
      -1896 	    var bi = parseInt(hi, 16).toString(2);
      -1897 	    bi = ("0000000" + bi).slice(-8);
      -1898 	    bin += bi;
      -1899 	}
      -1900 	return  bin.substr(0, bin.length - unusedBits);
      -1901     } catch(ex) {
      -1902 	return null;
      -1903     }
      -1904 }
      -1905 
      -1906 /**
      -1907  * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit<br/>
      -1908  * @name binstrtobitstr
      -1909  * @function
      -1910  * @param {string} s binary string (ex. "101")
      -1911  * @return {string} hexadecimal string of ASN.1 BitString value with unused bit
      -1912  * @since jsrsasign 10.5.4 base64x 1.1.21
      -1913  * @see bitstrtobinstr
      -1914  * @see inttobitstr
      -1915  * @see KJUR.asn1.DERBitString
      -1916  * 
      -1917  * @description
      -1918  * This function converts from an binary string (ex. "101") to 
      -1919  * hexadecimal string of ASN.1 BitString value
      -1920  * with unused bit (ex. "05a0"). <br/>
      -1921  * When "s" is not binary string, this returns null.
      -1922  * 
      -1923  * @example
      -1924  * binstrtobitstr("101") → "05a0"
      -1925  * binstrtobitstr("001") → "0520"
      -1926  * binstrtobitstr("11001") → "03c8"
      -1927  * binstrtobitstr("101000001") → "07a080"
      -1928  * binstrtobitstr(101) → null // not number
      -1929  * binstrtobitstr("xyz") → null // not binary string
      -1930  */
      -1931 function binstrtobitstr(s) {
      -1932     if (typeof s != "string") return null;
      -1933     if (s.match(/^[01]+$/) == null) return null;
      -1934     try {
      -1935 	var n = parseInt(s, 2);
      -1936 	return inttobitstr(n);
      -1937     } catch(ex) {
      -1938 	return null;
      -1939     }
      -1940 }
      -1941 
      -1942 // =======================================================
      -1943 /**
      -1944  * convert array of names to bit string<br/>
      -1945  * @name namearraytobinstr
      -1946  * @function
      -1947  * @param {array} namearray array of name string
      -1948  * @param {object} namedb associative array of name and value
      -1949  * @return {string} binary string (ex. "110001")
      -1950  * @since jsrsasign 10.5.21 base64x 1.1.27
      -1951  * @see KJUR.asn1.x509.KeyUsage
      -1952  * @see KJUR.asn1.tsp.PKIFailureInfo
      -1953  * 
      -1954  * @description
      -1955  * This function converts from an array of names to
      -1956  * a binary string. DB value bit will be set.
      -1957  * Note that ordering of namearray items
      -1958  * will be ignored.
      -1959  *
      -1960  * @example
      -1961  * db = { a: 0, b: 3, c: 8, d: 9, e: 17, f: 19 };
      -1962  * namearraytobinstr(['a', 'c', 'd'], db) &rarr: '1000000011'
      -1963  * namearraytobinstr(['c', 'b'], db) &rarr: '000100001'
      -1964  */
      -1965 function namearraytobinstr (namearray, namedb) {
      -1966     var d = 0;
      -1967     for (var i = 0; i < namearray.length; i++) {
      -1968 	d |= 1 << namedb[namearray[i]];
      -1969     }
      +1748 // ==== int / hex =================================
      +1749 /**
      +1750  * get hexadecimal string of minimum two's complement of integer<br/>
      +1751  * @name inttohex
      +1752  * @function
      +1753  * @param {number} i integer value
      +1754  * @return {string} hexadecimal string of two's complement of the integer
      +1755  * @since jsrsasign 10.9.0 base64x 1.1.34
      +1756  * @see twoscompl
      +1757  * @see DERInteger
      +1758  *
      +1759  * @description
      +1760  * This static method converts from integer value to a minimum length 
      +1761  * hexadecimal string of two's complement of the integer.
      +1762  * This method is useful for {@link DERInteger}.
      +1763  *
      +1764  * @example
      +1765  * inttohex(1) → "01"
      +1766  * inttohex(-1) → "ff"
      +1767  * inttohex(2048) → "0800"
      +1768  * inttohex(-2048) → "f800"
      +1769  */
      +1770 function inttohex(i) {
      +1771     var bi = new BigInteger(String(i), 10);
      +1772     return twoscompl(bi);
      +1773 }
      +1774 
      +1775 /**
      +1776  * get hexadecimal string of minimum two's complement of BigInteger<br/>
      +1777  * @name twoscompl
      +1778  * @function
      +1779  * @param {BigInteger} bi BigInteger object
      +1780  * @return {string} hexadecimal string of two's complement of the integer
      +1781  * @since jsrsasign 10.9.0 base64x 1.1.34
      +1782  * @see inttohex
      +1783  *
      +1784  * @description
      +1785  * This static method converts from a BigInteger object to a minimum length
      +1786  * hexadecimal string of two's complement of the integer.
      +1787  * <br/>
      +1788  * NOTE: This function is a replacement of deprecated ASN1Util.bigIntToMinTwosComplementsHex method.
      +1789  *
      +1790  * @example
      +1791  * twoscompl(new BigInteger("1", 10)) → "01"
      +1792  * twoscompl(new BigInteger("-1", 10)) → "ff"
      +1793  */
      +1794 function twoscompl(bi) {
      +1795     var h = bi.toString(16);
      +1796     // positive
      +1797     if (h.substr(0, 1) != '-') {
      +1798 	if (h.length % 2 == 1) {
      +1799 	    h = '0' + h;
      +1800 	} else {
      +1801 	    if (! h.match(/^[0-7]/)) {
      +1802 		h = '00' + h;
      +1803 	    }
      +1804 	}
      +1805 	return h;
      +1806     }
      +1807     // negative
      +1808     var hPos = h.substr(1);
      +1809     var xorLen = hPos.length;
      +1810     if (xorLen % 2 == 1) {
      +1811         xorLen += 1;
      +1812     } else {
      +1813         if (! h.match(/^[0-7]/)) {
      +1814             xorLen += 2;
      +1815         }
      +1816     }
      +1817     var hMask = '';
      +1818     for (var i = 0; i < xorLen; i++) {
      +1819         hMask += 'f';
      +1820     }
      +1821     var biMask = new BigInteger(hMask, 16);
      +1822     var biNeg = biMask.xor(bi).add(BigInteger.ONE);
      +1823     h = biNeg.toString(16).replace(/^-/, '');
      +1824     return h;
      +1825 }
      +1826 
      +1827 /**
      +1828  * string padding<br/>
      +1829  * @name strpad
      +1830  * @function
      +1831  * @param {String} s input string
      +1832  * @param {Number} len output string length
      +1833  * @param {String} padchar padding character (default is "0")
      +1834  * @return {String} padded string
      +1835  * @since jsrsasign 10.1.0 base64x 1.1.18
      +1836  * @example
      +1837  * strpad("1234", 10, "0") → "0000001234"
      +1838  * strpad("1234", 10, " ") → "      1234"
      +1839  * strpad("1234", 10)      → "0000001234"
      +1840  */
      +1841 var strpad = function(s, len, padchar) {
      +1842     if (padchar == undefined) padchar = "0";
      +1843     if (s.length >= len) return s;
      +1844     return new Array(len - s.length + 1).join(padchar) + s;
      +1845 };
      +1846 
      +1847 // ==== bitstr hex / int =================================
      +1848 
      +1849 /**
      +1850  * convert from hexadecimal string of ASN.1 BitString value with unused bit to integer value<br/>
      +1851  * @name bitstrtoint
      +1852  * @function
      +1853  * @param {String} h hexadecimal string of ASN.1 BitString value with unused bit
      +1854  * @return {Number} positive integer value of the BitString
      +1855  * @since jsrsasign 10.1.3 base64x 1.1.19
      +1856  * @see inttobitstr
      +1857  * @see KJUR.asn1.DERBitString
      +1858  * @see ASN1HEX.getInt
      +1859  * 
      +1860  * @description
      +1861  * This function converts from hexadecimal string of ASN.1 BitString
      +1862  * value with unused bit to its integer value. <br/>
      +1863  * When an improper hexadecimal string of BitString value
      +1864  * is applied, this returns -1.
      +1865  * 
      +1866  * @example
      +1867  * // "03c8" → 0xc8 unusedbit=03 → 11001000b unusedbit=03 → 11001b → 25
      +1868  * bitstrtoint("03c8") → 25
      +1869  * // "02fff8" → 0xfff8 unusedbit=02 → 1111111111111000b unusedbit=02
      +1870  * //   11111111111110b → 16382
      +1871  * bitstrtoint("02fff8") → 16382
      +1872  * bitstrtoint("05a0") → 5 (=101b)
      +1873  * bitstrtoint("ff00") → -1 // for improper BitString value
      +1874  * bitstrtoint("05a0").toString(2) → "101"
      +1875  * bitstrtoint("07a080").toString(2) → "101000001"
      +1876  */
      +1877 function bitstrtoint(h) {
      +1878     if (h.length % 2 != 0) return -1; 
      +1879     h = h.toLowerCase();
      +1880     if (h.match(/^[0-9a-f]+$/) == null) return -1;
      +1881     try {
      +1882 	var hUnusedbit = h.substr(0, 2);
      +1883 	if (hUnusedbit == "00")
      +1884 	    return parseInt(h.substr(2), 16);
      +1885 	var iUnusedbit = parseInt(hUnusedbit, 16);
      +1886 	if (iUnusedbit > 7) return -1;
      +1887 	var hValue = h.substr(2);
      +1888 	var bValue = parseInt(hValue, 16).toString(2);
      +1889 	if (bValue == "0") bValue = "00000000";
      +1890 	bValue = bValue.slice(0, 0 - iUnusedbit);
      +1891 	var iValue = parseInt(bValue, 2);
      +1892 	if (iValue == NaN) return -1;
      +1893 	return iValue;
      +1894     } catch(ex) {
      +1895 	return -1;
      +1896     }
      +1897 };
      +1898 
      +1899 /**
      +1900  * convert from integer value to hexadecimal string of ASN.1 BitString value with unused bit<br/>
      +1901  * @name inttobitstr
      +1902  * @function
      +1903  * @param {Number} n integer value of ASN.1 BitString
      +1904  * @return {String} hexadecimal string of ASN.1 BitString value with unused bit
      +1905  * @since jsrsasign 10.1.3 base64x 1.1.19
      +1906  * @see bitstrtoint
      +1907  * @see KJUR.asn1.DERBitString
      +1908  * @see ASN1HEX.getInt
      +1909  * 
      +1910  * @description
      +1911  * This function converts from an integer value to 
      +1912  * hexadecimal string of ASN.1 BitString value
      +1913  * with unused bit. <br/>
      +1914  * When "n" is not non-negative number, this returns null
      +1915  * 
      +1916  * @example
      +1917  * // 25 → 11001b → 11001000b unusedbit=03 → 0xc8 unusedbit=03 → "03c8"
      +1918  * inttobitstr(25) → "03c8"
      +1919  * inttobitstr(-3) → null
      +1920  * inttobitstr("abc") → null
      +1921  * inttobitstr(parseInt("11001", 2)) → "03c8"
      +1922  * inttobitstr(parseInt("101", 2)) → "05a0"
      +1923  * inttobitstr(parseInt("101000001", 2)) → "07a080"
      +1924  */
      +1925 function inttobitstr(n) {
      +1926     if (typeof n != "number") return null;
      +1927     if (n < 0) return null;
      +1928     var bValue = Number(n).toString(2);
      +1929     var iUnusedbit = 8 - bValue.length % 8;
      +1930     if (iUnusedbit == 8) iUnusedbit = 0;
      +1931     bValue = bValue + strpad("", iUnusedbit, "0");
      +1932     var hValue = parseInt(bValue, 2).toString(16);
      +1933     if (hValue.length % 2 == 1) hValue = "0" + hValue;
      +1934     var hUnusedbit = "0" + iUnusedbit;
      +1935     return hUnusedbit + hValue;
      +1936 };
      +1937 
      +1938 // ==== bitstr hex / binary string =======================
      +1939 
      +1940 /**
      +1941  * convert from hexadecimal string of ASN.1 BitString value with unused bit to binary string<br/>
      +1942  * @name bitstrtobinstr
      +1943  * @function
      +1944  * @param {string} h hexadecimal string of ASN.1 BitString value with unused bit
      +1945  * @return {string} binary string
      +1946  * @since jsrsasign 10.5.4 base64x 1.1.21
      +1947  * @see binstrtobitstr
      +1948  * @see inttobitstr
      +1949  * 
      +1950  * @description
      +1951  * This function converts from hexadecimal string of ASN.1 BitString
      +1952  * value with unused bit to its integer value. <br/>
      +1953  * When an improper hexadecimal string of BitString value
      +1954  * is applied, this returns null.
      +1955  * 
      +1956  * @example
      +1957  * bitstrtobinstr("05a0") → "101"
      +1958  * bitstrtobinstr("0520") → "001"
      +1959  * bitstrtobinstr("07a080") → "101000001"
      +1960  * bitstrtobinstr(502) → null // non ASN.1 BitString value
      +1961  * bitstrtobinstr("ff00") → null // for improper BitString value
      +1962  */
      +1963 function bitstrtobinstr(h) {
      +1964     if (typeof h != "string") return null;
      +1965     if (h.length % 2 != 0) return null;
      +1966     if (! h.match(/^[0-9a-f]+$/)) return null;
      +1967     try {
      +1968 	var unusedBits = parseInt(h.substr(0, 2), 16);
      +1969 	if (unusedBits < 0 || 7 < unusedBits) return null
       1970 
      -1971     var s = d.toString(2);
      -1972     var r = "";
      -1973     for (var i = s.length - 1; i >=0; i--) {
      -1974 	r += s[i];
      -1975     }
      -1976     return r;
      -1977 }
      -1978 
      -1979 /**
      -1980  * get value of array by key name list<br/>
      -1981  * @function
      -1982  * @param {object} val array of associative array
      -1983  * @param {string} keys concatinated key list with dot (ex. 'type.name.0.info')
      -1984  * @param {object} def default value if value is not found (OPTIONAL)
      -1985  * @return {object} value if found otherwise returns def
      -1986  * @since jsrsasign 10.8.0 base64x 1.1.32
      -1987  *
      -1988  * @description
      -1989  * This function returns the value of an array or associative array 
      -1990  * which referred by a concatinated key list string.
      -1991  * If a value for key is not defined, it returns 'undefined' by default.
      -1992  * When an optional argument 'def' is specified and a value for key is
      -1993  * not defined, it returns a value of 'def'.
      -1994  * 
      -1995  * @example
      -1996  * let p = {
      -1997  *   fruit: apple,
      -1998  *   info: [
      -1999  *     { toy: 4 },
      -2000  *     { pen: 6 }
      -2001  *   ]
      -2002  * };
      -2003  * aryval(p, 'fruit') &rarr "apple"
      -2004  * aryval(p, 'info') &rarr [{toy: 4},{pen: 6}]
      -2005  * aryval(p, 'info.1') &rarr {pen: 6}
      -2006  * aryval(p, 'info.1.pen') &rarr 6
      -2007  * aryval(p, 'money.amount') &rarr undefined
      -2008  * aryval(p, 'money.amount', null) &rarr null
      +1971 	var value = h.substr(2);
      +1972 	var bin = "";
      +1973 	for (var i = 0; i < value.length; i += 2) {
      +1974 	    var hi = value.substr(i, 2);
      +1975 	    var bi = parseInt(hi, 16).toString(2);
      +1976 	    bi = ("0000000" + bi).slice(-8);
      +1977 	    bin += bi;
      +1978 	}
      +1979 	return  bin.substr(0, bin.length - unusedBits);
      +1980     } catch(ex) {
      +1981 	return null;
      +1982     }
      +1983 }
      +1984 
      +1985 /**
      +1986  * convert from binary string to hexadecimal string of ASN.1 BitString value with unused bit<br/>
      +1987  * @name binstrtobitstr
      +1988  * @function
      +1989  * @param {string} s binary string (ex. "101")
      +1990  * @return {string} hexadecimal string of ASN.1 BitString value with unused bit
      +1991  * @since jsrsasign 10.5.4 base64x 1.1.21
      +1992  * @see bitstrtobinstr
      +1993  * @see inttobitstr
      +1994  * @see KJUR.asn1.DERBitString
      +1995  * 
      +1996  * @description
      +1997  * This function converts from an binary string (ex. "101") to 
      +1998  * hexadecimal string of ASN.1 BitString value
      +1999  * with unused bit (ex. "05a0"). <br/>
      +2000  * When "s" is not binary string, this returns null.
      +2001  * 
      +2002  * @example
      +2003  * binstrtobitstr("101") → "05a0"
      +2004  * binstrtobitstr("001") → "0520"
      +2005  * binstrtobitstr("11001") → "03c8"
      +2006  * binstrtobitstr("101000001") → "07a080"
      +2007  * binstrtobitstr(101) → null // not number
      +2008  * binstrtobitstr("xyz") → null // not binary string
       2009  */
      -2010 function aryval(val, keys, def) {
      -2011     if (typeof val != "object") return undefined
      -2012     var keys = String(keys).split('.');
      -2013     for (var i = 0; i < keys.length && val; i++) {
      -2014 	var key = keys[i];
      -2015 	if (key.match(/^[0-9]+$/)) key = parseInt(key);
      -2016         val = val[key];
      -2017     }
      -2018     return val || val === false ? val : def;
      +2010 function binstrtobitstr(s) {
      +2011     if (typeof s != "string") return null;
      +2012     if (s.match(/^[01]+$/) == null) return null;
      +2013     try {
      +2014 	var n = parseInt(s, 2);
      +2015 	return inttobitstr(n);
      +2016     } catch(ex) {
      +2017 	return null;
      +2018     }
       2019 }
       2020 
      -2021 
      -2022 // =======================================================
      -2023 /**
      -2024  * set class inheritance<br/>
      -2025  * @name extendClass
      -2026  * @function
      -2027  * @param {Function} subClass sub class to set inheritance
      -2028  * @param {Function} superClass super class to inherit
      -2029  * @since jsrsasign 10.3.0 base64x 1.1.21
      -2030  *
      -2031  * @description
      -2032  * This function extends a class and set an inheritance
      -2033  * for member variables and methods.
      -2034  *
      -2035  * @example
      -2036  * var Animal = function() {
      -2037  *   this.hello = function(){console.log("Hello")};
      -2038  *   this.name="Ani";
      -2039  * };
      -2040  * var Dog = function() {
      -2041  *   Dog.superclass.constructor.call(this);
      -2042  *   this.vow = function(){console.log("Vow wow")};
      -2043  *   this.tail=true;
      -2044  * };
      -2045  * extendClass(Dog, Animal);
      -2046  */
      -2047 function extendClass(subClass, superClass) {
      -2048     var F = function() {};
      -2049     F.prototype = superClass.prototype;
      -2050     subClass.prototype = new F();
      -2051     subClass.prototype.constructor = subClass;
      -2052     subClass.superclass = superClass.prototype;
      -2053      
      -2054     if (superClass.prototype.constructor == Object.prototype.constructor) {
      -2055         superClass.prototype.constructor = superClass;
      -2056     }
      -2057 };
      -2058 
      -2059 
      \ No newline at end of file +2021
      // ======================================================= +2022 /** +2023 * convert array of names to bit string<br/> +2024 * @name namearraytobinstr +2025 * @function +2026 * @param {array} namearray array of name string +2027 * @param {object} namedb associative array of name and value +2028 * @return {string} binary string (ex. "110001") +2029 * @since jsrsasign 10.5.21 base64x 1.1.27 +2030 * @see KJUR.asn1.x509.KeyUsage +2031 * @see KJUR.asn1.tsp.PKIFailureInfo +2032 * +2033 * @description +2034 * This function converts from an array of names to +2035 * a binary string. DB value bit will be set. +2036 * Note that ordering of namearray items +2037 * will be ignored. +2038 * +2039 * @example +2040 * db = { a: 0, b: 3, c: 8, d: 9, e: 17, f: 19 }; +2041 * namearraytobinstr(['a', 'c', 'd'], db) &rarr: '1000000011' +2042 * namearraytobinstr(['c', 'b'], db) &rarr: '000100001' +2043 */ +2044 function namearraytobinstr (namearray, namedb) { +2045 var d = 0; +2046 for (var i = 0; i < namearray.length; i++) { +2047 d |= 1 << namedb[namearray[i]]; +2048 } +2049 +2050 var s = d.toString(2); +2051 var r = ""; +2052 for (var i = s.length - 1; i >=0; i--) { +2053 r += s[i]; +2054 } +2055 return r; +2056 } +2057 +2058 /** +2059 * get value of array by key name list<br/> +2060 * @function +2061 * @param {object} val array of associative array +2062 * @param {string} keys concatinated key list with dot (ex. 'type.name.0.info') +2063 * @param {object} def default value if value is not found (OPTIONAL) +2064 * @return {object} value if found otherwise returns def +2065 * @since jsrsasign 10.8.0 base64x 1.1.32 +2066 * +2067 * @description +2068 * This function returns the value of an array or associative array +2069 * which referred by a concatinated key list string. +2070 * If a value for key is not defined, it returns 'undefined' by default. +2071 * When an optional argument 'def' is specified and a value for key is +2072 * not defined, it returns a value of 'def'. +2073 * +2074 * @example +2075 * let p = { +2076 * fruit: apple, +2077 * info: [ +2078 * { toy: 4 }, +2079 * { pen: 6 } +2080 * ] +2081 * }; +2082 * aryval(p, 'fruit') &rarr "apple" +2083 * aryval(p, 'info') &rarr [{toy: 4},{pen: 6}] +2084 * aryval(p, 'info.1') &rarr {pen: 6} +2085 * aryval(p, 'info.1.pen') &rarr 6 +2086 * aryval(p, 'money.amount') &rarr undefined +2087 * aryval(p, 'money.amount', null) &rarr null +2088 */ +2089 function aryval(val, keys, def) { +2090 if (typeof val != "object") return undefined +2091 var keys = String(keys).split('.'); +2092 for (var i = 0; i < keys.length && val; i++) { +2093 var key = keys[i]; +2094 if (key.match(/^[0-9]+$/)) key = parseInt(key); +2095 val = val[key]; +2096 } +2097 return val || val === false ? val : def; +2098 } +2099 +2100 +2101 // ======================================================= +2102 /** +2103 * set class inheritance<br/> +2104 * @name extendClass +2105 * @function +2106 * @param {Function} subClass sub class to set inheritance +2107 * @param {Function} superClass super class to inherit +2108 * @since jsrsasign 10.3.0 base64x 1.1.21 +2109 * +2110 * @description +2111 * This function extends a class and set an inheritance +2112 * for member variables and methods. +2113 * +2114 * @example +2115 * var Animal = function() { +2116 * this.hello = function(){console.log("Hello")}; +2117 * this.name="Ani"; +2118 * }; +2119 * var Dog = function() { +2120 * Dog.superclass.constructor.call(this); +2121 * this.vow = function(){console.log("Vow wow")}; +2122 * this.tail=true; +2123 * }; +2124 * extendClass(Dog, Animal); +2125 */ +2126 function extendClass(subClass, superClass) { +2127 var F = function() {}; +2128 F.prototype = superClass.prototype; +2129 subClass.prototype = new F(); +2130 subClass.prototype.constructor = subClass; +2131 subClass.superclass = superClass.prototype; +2132 +2133 if (superClass.prototype.constructor == Object.prototype.constructor) { +2134 superClass.prototype.constructor = superClass; +2135 } +2136 }; +2137 +2138
      \ No newline at end of file diff --git a/api/symbols/src/crypto-1.1.js.html b/api/symbols/src/crypto-1.1.js.html index f4f8ceb4..33b1d672 100644 --- a/api/symbols/src/crypto-1.1.js.html +++ b/api/symbols/src/crypto-1.1.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
        1 /* crypto-1.2.6.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license
      +	
        1 /* crypto-1.3.0.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license
         2  */
         3 /*
         4  * crypto.js - Cryptographic Algorithm Provider class
      @@ -23,7 +23,7 @@
        16  * @fileOverview
        17  * @name crypto-1.1.js
        18  * @author Kenji Urushima kenji.urushima@gmail.com
      - 19  * @version jsrsasign 10.5.0 crypto 1.2.6 (2021-Nov-21)
      + 19  * @version jsrsasign 10.9.0 crypto 1.3.0 (2023-Nov-27)
        20  * @since jsrsasign 2.2
        21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
        22  */
      @@ -1411,120 +1411,180 @@
       1404  * @function
       1405  * @param {String} s input string to encrypt
       1406  * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key
      -1407  * @param {String} algName short/long algorithm name for encryption/decryption 
      -1408  * @return {String} hexadecimal encrypted string
      -1409  * @since jsrsasign 6.2.0 crypto 1.1.10
      -1410  * @description
      -1411  * This static method encrypts raw string with specified key and algorithm.
      -1412  * @example 
      -1413  * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj) → "1abc2d..."
      -1414  * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj, "RSAOAEP") → "23ab02..."
      -1415  */
      -1416 KJUR.crypto.Cipher.encrypt = function(s, keyObj, algName) {
      -1417     if (keyObj instanceof RSAKey && keyObj.isPublic) {
      -1418 	var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName);
      -1419 	if (algName2 === "RSA") return keyObj.encrypt(s);
      -1420 	if (algName2 === "RSAOAEP") return keyObj.encryptOAEP(s, "sha1");
      -1421 
      -1422 	var a = algName2.match(/^RSAOAEP(\d+)$/);
      -1423 	if (a !== null) return keyObj.encryptOAEP(s, "sha" + a[1]);
      -1424 
      -1425 	throw "Cipher.encrypt: unsupported algorithm for RSAKey: " + algName;
      -1426     } else {
      -1427 	throw "Cipher.encrypt: unsupported key or algorithm";
      -1428     }
      -1429 };
      -1430 
      -1431 /**
      -1432  * decrypt encrypted hexadecimal string with specified key and algorithm<br/>
      -1433  * @name decrypt
      -1434  * @memberOf KJUR.crypto.Cipher
      -1435  * @function
      -1436  * @param {String} hex hexadecial string of encrypted message
      -1437  * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key
      -1438  * @param {String} algName short/long algorithm name for encryption/decryption
      -1439  * @return {String} decrypted raw string
      -1440  * @since jsrsasign 6.2.0 crypto 1.1.10
      -1441  * @description
      -1442  * This static method decrypts encrypted hexadecimal string with specified key and algorithm.
      -1443  * @example 
      -1444  * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj) → "1abc2d..."
      -1445  * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj, "RSAOAEP) → "23ab02..."
      -1446  */
      -1447 KJUR.crypto.Cipher.decrypt = function(hex, keyObj, algName) {
      -1448     if (keyObj instanceof RSAKey && keyObj.isPrivate) {
      -1449 	var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName);
      -1450 	if (algName2 === "RSA") return keyObj.decrypt(hex);
      -1451 	if (algName2 === "RSAOAEP") return keyObj.decryptOAEP(hex, "sha1");
      -1452 
      -1453 	var a = algName2.match(/^RSAOAEP(\d+)$/);
      -1454 	if (a !== null) return keyObj.decryptOAEP(hex, "sha" + a[1]);
      -1455 
      -1456 	throw "Cipher.decrypt: unsupported algorithm for RSAKey: " + algName;
      -1457     } else {
      -1458 	throw "Cipher.decrypt: unsupported key or algorithm";
      -1459     }
      -1460 };
      -1461 
      -1462 /**
      -1463  * get canonicalized encrypt/decrypt algorithm name by key and short/long algorithm name<br/>
      -1464  * @name getAlgByKeyAndName
      -1465  * @memberOf KJUR.crypto.Cipher
      -1466  * @function
      -1467  * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key
      -1468  * @param {String} algName short/long algorithm name for encryption/decryption
      -1469  * @return {String} canonicalized algorithm name for encryption/decryption
      -1470  * @since jsrsasign 6.2.0 crypto 1.1.10
      -1471  * @description
      -1472  * Here is supported canonicalized cipher algorithm names and its standard names:
      -1473  * <ul>
      -1474  * <li>RSA - RSA/ECB/PKCS1Padding (default for RSAKey)</li>
      -1475  * <li>RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding</li>
      -1476  * <li>RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)</li>
      -1477  * <li>RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding</li>
      -1478  * <li>RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)</li>
      -1479  * <li>RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)</li>
      -1480  * </ul>
      -1481  * NOTE: (*) is not supported in Java JCE.
      -1482  * @example 
      -1483  * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey) → "RSA"
      -1484  * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey, "RSAOAEP") → "RSAOAEP"
      -1485  */
      -1486 KJUR.crypto.Cipher.getAlgByKeyAndName = function(keyObj, algName) {
      -1487     if (keyObj instanceof RSAKey) {
      -1488 	if (":RSA:RSAOAEP:RSAOAEP224:RSAOAEP256:RSAOAEP384:RSAOAEP512:".indexOf(algName) != -1)
      -1489 	    return algName;
      -1490 	if (algName === null || algName === undefined) return "RSA";
      -1491 	throw "getAlgByKeyAndName: not supported algorithm name for RSAKey: " + algName;
      -1492     }
      -1493     throw "getAlgByKeyAndName: not supported algorithm name: " + algName;
      -1494 }
      -1495 
      -1496 // ====== Other Utility class =====================================================
      -1497 
      -1498 /**
      -1499  * static object for cryptographic function utilities
      -1500  * @name KJUR.crypto.OID
      -1501  * @class static object for cryptography related OIDs
      -1502  * @property {Array} oidhex2name key value of hexadecimal OID and its name
      -1503  *           (ex. '2a8648ce3d030107' and 'secp256r1')
      -1504  * @since crypto 1.1.3
      -1505  * @description
      -1506  */
      -1507 KJUR.crypto.OID = new function() {
      -1508     this.oidhex2name = {
      -1509 	'2a864886f70d010101': 'rsaEncryption',
      -1510 	'2a8648ce3d0201': 'ecPublicKey',
      -1511 	'2a8648ce380401': 'dsa',
      -1512 	'2a8648ce3d030107': 'secp256r1',
      -1513 	'2b8104001f': 'secp192k1',
      -1514 	'2b81040021': 'secp224r1',
      -1515 	'2b8104000a': 'secp256k1',
      -1516 	'2b81040022': 'secp384r1',
      -1517 	'2b81040023': 'secp521r1',
      -1518 	'2a8648ce380403': 'SHA1withDSA', // 1.2.840.10040.4.3
      -1519 	'608648016503040301': 'SHA224withDSA', // 2.16.840.1.101.3.4.3.1
      -1520 	'608648016503040302': 'SHA256withDSA', // 2.16.840.1.101.3.4.3.2
      -1521     };
      -1522 };
      -1523 
      \ No newline at end of file +1407 * @param {String} algName short/long algorithm name for encryption/decryption (OPTION) +1408 * @param {object} param parameters for synchronous cipher such as initial vector (OPTION) +1409 * @return {String} hexadecimal encrypted string +1410 * @since jsrsasign 6.2.0 crypto 1.1.10 +1411 * +1412 * @description +1413 * This static method encrypts raw string with specified key and algorithm. +1414 * <br/> +1415 * NOTE: From jsrsasign 10.9.0, asymmetric cipher ({des-EDE3,aes{128,256}}-CBC) is also supported. +1416 * +1417 * @example +1418 * // asynchronous cipher +1419 * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj) → "1abc2d..." +1420 * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj, "RSAOAEP") → "23ab02..." +1421 * // synchronous cipher +1422 * KJUR.crypto.Cipher.encrypt("12abcd...", "5a7d...", "aes256-CBC", { iv: "1b3c..." }) +1423 * KJUR.crypto.Cipher.encrypt("12abcd...", "5a7d...", any, { encalg: "aes128-CBC", iv: "1b3c..." }) +1424 * KJUR.crypto.Cipher.encrypt("12abcd...", any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41..." }) +1425 * KJUR.crypto.Cipher.encrypt(any, any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41...", enc: "12abcd..." }) +1426 */
      +1427 KJUR.crypto.Cipher.encrypt = function(s, keyObj, algName, param) { +1428 if (aryval(param, "enclag") != undefined) algName = param.encalg; +1429 +1430 if (typeof algName == "string" && algName.substr(-4) == "-CBC") { +1431 var hKey = keyObj; +1432 var hPlain = s; +1433 if (aryval(param, "key") != undefined) hKey = param.key; +1434 if (aryval(param, "enc") != undefined) hEnc = param.enc; +1435 var wKey = CryptoJS.enc.Hex.parse(hKey); +1436 var wPlain = CryptoJS.enc.Hex.parse(hPlain); +1437 var wIV = CryptoJS.enc.Hex.parse(param.iv); +1438 var wEnc; +1439 if (algName == "des-EDE3-CBC") { +1440 wEnc = CryptoJS.TripleDES.encrypt(wPlain, wKey, { iv: wIV }); +1441 } else if (algName == "aes128-CBC" || algName == "aes256-CBC") { +1442 wEnc = CryptoJS.AES.encrypt(wPlain, wKey, { iv: wIV }); +1443 } else { +1444 throw new Error("unsupported algorithm: " + algName); +1445 } +1446 return wEnc + ""; +1447 } else if (keyObj instanceof RSAKey && keyObj.isPublic) { +1448 var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName); +1449 if (algName2 === "RSA") return keyObj.encrypt(s); +1450 if (algName2 === "RSAOAEP") return keyObj.encryptOAEP(s, "sha1"); +1451 +1452 var a = algName2.match(/^RSAOAEP(\d+)$/); +1453 if (a !== null) return keyObj.encryptOAEP(s, "sha" + a[1]); +1454 +1455 throw "Cipher.encrypt: unsupported algorithm for RSAKey: " + algName; +1456 } else { +1457 throw "Cipher.encrypt: unsupported key or algorithm"; +1458 } +1459 }; +1460 +1461 /** +1462 * decrypt encrypted hexadecimal string with specified key and algorithm<br/> +1463 * @name decrypt +1464 * @memberOf KJUR.crypto.Cipher +1465 * @function +1466 * @param {string} hex hexadecimal string of encrypted message +1467 * @param {object} keyObj RSAKey object or hexadecimal string of symmetric cipher key +1468 * @param {string} algName short/long algorithm name for encryption/decryption (OPTION) +1469 * @param {object} param parameters for synchronous cipher such as initial vector (OPTION) +1470 * @return {String} decrypted raw string +1471 * @since jsrsasign 6.2.0 crypto 1.1.10 +1472 * +1473 * @description +1474 * This static method decrypts encrypted hexadecimal string with specified key and algorithm. +1475 * <br/> +1476 * NOTE: From jsrsasign 10.9.0, asymmetric cipher ({des-EDE3,aes{128,256}}-CBCis also supported. +1477 * +1478 * @example +1479 * // asynchronous cipher +1480 * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj) → "1abc2d..." +1481 * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj, "RSAOAEP) → "23ab02..." +1482 * // synchronous cipher +1483 * KJUR.crypto.Cipher.decrypt("12abcd...", "5a7d...", "aes256-CBC", { iv: "1b3c..." }) +1484 * KJUR.crypto.Cipher.decrypt("12abcd...", "5a7d...", any, { encalg: "aes128-CBC", iv: "1b3c..." }) +1485 * KJUR.crypto.Cipher.decrypt("12abcd...", any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41..." }) +1486 * KJUR.crypto.Cipher.decrypt(any, any, any, { encalg: "des-EDE3-CBC", iv: "1b3c...", key: "3d41...", enc: "12abcd..." }) +1487 */ +1488 KJUR.crypto.Cipher.decrypt = function(hex, keyObj, algName, param) { +1489 if (aryval(param, "enclag") != undefined) algName = param.encalg; +1490 +1491 if (typeof algName == "string" && algName.substr(-4) == "-CBC") { +1492 var hKey = keyObj; +1493 var hEnc = hex; +1494 if (aryval(param, "key") != undefined) hKey = param.key; +1495 if (aryval(param, "enc") != undefined) hEnc = param.enc; +1496 var wKey = CryptoJS.enc.Hex.parse(hKey); +1497 var wEnc = CryptoJS.enc.Hex.parse(hEnc); +1498 var wIV = CryptoJS.enc.Hex.parse(param.iv); +1499 var wDec; +1500 if (algName == "des-EDE3-CBC") { +1501 wDec = CryptoJS.TripleDES.decrypt({ ciphertext: wEnc }, wKey, { iv: wIV }); +1502 } else if (algName == "aes128-CBC" || algName == "aes256-CBC") { +1503 wDec = CryptoJS.AES.decrypt({ ciphertext: wEnc }, wKey, { iv: wIV }); +1504 } else { +1505 throw new Error("unsupported algorithm: " + algName); +1506 } +1507 return CryptoJS.enc.Hex.stringify(wDec); +1508 } else if (keyObj instanceof RSAKey && keyObj.isPrivate) { +1509 var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName); +1510 if (algName2 === "RSA") return keyObj.decrypt(hex); +1511 if (algName2 === "RSAOAEP") return keyObj.decryptOAEP(hex, "sha1"); +1512 +1513 var a = algName2.match(/^RSAOAEP(\d+)$/); +1514 if (a !== null) return keyObj.decryptOAEP(hex, "sha" + a[1]); +1515 +1516 throw "Cipher.decrypt: unsupported algorithm for RSAKey: " + algName; +1517 } else { +1518 throw "Cipher.decrypt: unsupported key or algorithm"; +1519 } +1520 }; +1521 +1522 /** +1523 * get canonicalized encrypt/decrypt algorithm name by key and short/long algorithm name<br/> +1524 * @name getAlgByKeyAndName +1525 * @memberOf KJUR.crypto.Cipher +1526 * @function +1527 * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key +1528 * @param {String} algName short/long algorithm name for encryption/decryption +1529 * @return {String} canonicalized algorithm name for encryption/decryption +1530 * @since jsrsasign 6.2.0 crypto 1.1.10 +1531 * @description +1532 * Here is supported canonicalized cipher algorithm names and its standard names: +1533 * <ul> +1534 * <li>RSA - RSA/ECB/PKCS1Padding (default for RSAKey)</li> +1535 * <li>RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding</li> +1536 * <li>RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)</li> +1537 * <li>RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding</li> +1538 * <li>RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)</li> +1539 * <li>RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)</li> +1540 * </ul> +1541 * NOTE: (*) is not supported in Java JCE. +1542 * @example +1543 * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey) → "RSA" +1544 * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey, "RSAOAEP") → "RSAOAEP" +1545 */ +1546 KJUR.crypto.Cipher.getAlgByKeyAndName = function(keyObj, algName) { +1547 if (keyObj instanceof RSAKey) { +1548 if (":RSA:RSAOAEP:RSAOAEP224:RSAOAEP256:RSAOAEP384:RSAOAEP512:".indexOf(algName) != -1) +1549 return algName; +1550 if (algName === null || algName === undefined) return "RSA"; +1551 throw "getAlgByKeyAndName: not supported algorithm name for RSAKey: " + algName; +1552 } +1553 throw "getAlgByKeyAndName: not supported algorithm name: " + algName; +1554 } +1555 +1556 // ====== Other Utility class ===================================================== +1557 +1558 /** +1559 * static object for cryptographic function utilities +1560 * @name KJUR.crypto.OID +1561 * @class static object for cryptography related OIDs +1562 * @property {Array} oidhex2name key value of hexadecimal OID and its name +1563 * (ex. '2a8648ce3d030107' and 'secp256r1') +1564 * @since crypto 1.1.3 +1565 * @description +1566 */ +1567 KJUR.crypto.OID = new function() { +1568 this.oidhex2name = { +1569 '2a864886f70d010101': 'rsaEncryption', +1570 '2a8648ce3d0201': 'ecPublicKey', +1571 '2a8648ce380401': 'dsa', +1572 '2a8648ce3d030107': 'secp256r1', +1573 '2b8104001f': 'secp192k1', +1574 '2b81040021': 'secp224r1', +1575 '2b8104000a': 'secp256k1', +1576 '2b81040022': 'secp384r1', +1577 '2b81040023': 'secp521r1', +1578 '2a8648ce380403': 'SHA1withDSA', // 1.2.840.10040.4.3 +1579 '608648016503040301': 'SHA224withDSA', // 2.16.840.1.101.3.4.3.1 +1580 '608648016503040302': 'SHA256withDSA', // 2.16.840.1.101.3.4.3.2 +1581 }; +1582 }; +1583
      \ No newline at end of file diff --git a/api/symbols/src/keyutil-1.0.js.html b/api/symbols/src/keyutil-1.0.js.html index 096c2c5d..7c84f4f2 100644 --- a/api/symbols/src/keyutil-1.0.js.html +++ b/api/symbols/src/keyutil-1.0.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
        1 /* keyutil-1.2.7.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
      +	
        1 /* keyutil-1.3.0.js (c) 2013-2023 Kenji Urushima | kjur.github.io/jsrsasign/license
         2  */
         3 /*
         4  * keyutil.js - key utility for PKCS#1/5/8 PEM, RSA/DSA/ECDSA key object
         5  *
      -  6  * Copyright (c) 2013-2022 Kenji Urushima (kenji.urushima@gmail.com)
      +  6  * Copyright (c) 2013-2023 Kenji Urushima (kenji.urushima@gmail.com)
         7  *
         8  * This software is licensed under the terms of the MIT License.
         9  * https://kjur.github.io/jsrsasign/license
      @@ -22,7 +22,7 @@
        15  * @fileOverview
        16  * @name keyutil-1.0.js
        17  * @author Kenji Urushima kenji.urushima@gmail.com
      - 18  * @version jsrsasign 10.5.16 keyutil 1.2.7 (2022-Apr-08)
      + 18  * @version jsrsasign 10.9.0 keyutil 1.3.0 (2023-Nov-25)
        19  * @since jsrsasign 4.1.4
        20  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
        21  */
      @@ -399,1544 +399,1893 @@
       392             return sPEM;
       393         },
       394 
      -395         // === PKCS8 ===============================================================
      -396 
      -397         /**
      -398          * generate PBKDF2 key hexstring with specified passcode and information
      -399          * @name parseHexOfEncryptedPKCS8
      -400          * @memberOf KEYUTIL
      -401          * @function
      -402          * @param {String} passcode passcode to decrypto private key
      -403          * @return {Array} info associative array of PKCS#8 parameters
      -404          * @since pkcs5pkey 1.0.3
      -405          * @description
      -406          * The associative array which is returned by this method has following properties:
      -407          * <ul>
      -408          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
      -409          * <li>info.pkbdf2Iter - iteration count</li>
      -410          * <li>info.ciphertext - hexadecimal string of encrypted private key</li>
      -411          * <li>info.encryptionSchemeAlg - encryption algorithm name (currently TripleDES only)</li>
      -412          * <li>info.encryptionSchemeIV - initial vector for encryption algorithm</li>
      -413          * </ul>
      -414          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
      -415          * <ul>
      -416          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
      -417          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
      -418          * </ul>
      -419          * @example
      -420          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      -421          * // key with PBKDF2 with TripleDES
      -422          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
      -423          */
      -424         parseHexOfEncryptedPKCS8: function(sHEX) {
      -425 	    var _ASN1HEX = ASN1HEX;
      -426 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      -427 	    var _getV = _ASN1HEX.getV;
      -428             var info = {};
      -429             
      -430             var a0 = _getChildIdx(sHEX, 0);
      -431             if (a0.length != 2)
      -432                 throw new Error("malformed format: SEQUENCE(0).items != 2: " +
      -433 				a0.length);
      -434 
      -435             // 1. ciphertext
      -436             info.ciphertext = _getV(sHEX, a0[1]);
      +395         // === NEW ENCRYPTED PKCS8 GENERATOR =======================================
      +396         /*
      +397          * get Encrypted PKCS8 PEM private key by PEM string of plain priavte key
      +398          * @name getEncryptedPKCS8PEM
      +399          * @memberOf KEYUTIL
      +400          * @function
      +401          * @param {string} hPlainPKCS8Prv hexadecimal string of plain PKCS#8 private key
      +402          * @param {string} passcode password string for encrytion
      +403          * @param {object} param associative array object of parameters for encrypted PKCS#8 (OPITON)
      +404          * @return {string} PEM string of encrypted PKCS#8 private key
      +405          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +406          * @see KEYUTIL.getEncryptedPKCS8Hex
      +407          *
      +408          * @description
      +409          * <br/>
      +410          * generate hexadecimal string of encrypted PKCS#8 private key by a hexadecimal string of 
      +411 	 * plain PKCS#8 private key with encryption parameters.
      +412 	 * <pre>
      +413 	 * { // (OPTION) encryption algorithm (ex. des-EDE3-CBC,aes128-CBC) DEFAULT:aes256-CBC
      +414          *   encalg: "aes128-CBC", 
      +415 	 *   // (OPTION) iteration count, DEFAULT:2048,
      +416 	 *   iter: 1024, 
      +417 	 *   // (OPTION) psudorandom function (ex. hmacWithSHA{1,224,256,384,512}) DEFAULT: hmacWithSHA256
      +418 	 *   prf: "hmacWithSHA512", 
      +419 	 *   // (OPTION) explicitly specifed 8 bytes hexadecimal salt string.
      +420 	 *   salt: "12ab...", 
      +421 	 *   // (OPTION) explicitly specified hexadecimal IV string.
      +422 	 *   enciv: "257c..." 
      +423 	 * </pre>
      +424 	 *
      +425          * @example
      +426 	 * // generate with default parameters
      +427 	 * KEYUTIL.getEncryptedPKCS8PEM("3082...", "password")
      +428 	 *   → "-----BEGIN ENCRYPTED PRIVATE KEY..."
      +429 	 * // des-EDE3-CBC with 4096 iteration
      +430 	 * KEYUTIL.getEncryptedPKCS8PEM("3082...", "password", { encalg: "des-EDE3-CBC", iter: 4096 })
      +431 	 *   → "-----BEGIN ENCRYPTED PRIVATE KEY..."
      +432          */
      +433 	getEncryptedPKCS8PEM: function(hPlainPKCS8Prv, passcode, param) {
      +434 	    var hP8E = this.getEncryptedPKCS8Hex(hPlainPKCS8Prv, passcode, param);
      +435 	    return hextopem(hP8E, "ENCRYPTED PRIVATE KEY");
      +436 	},
       437 
      -438             // 2. pkcs5PBES2
      -439             var a0_0 = _getChildIdx(sHEX, a0[0]); 
      -440             if (a0_0.length != 2)
      -441                 throw new Error("malformed format: SEQUENCE(0.0).items != 2: "
      -442 				+ a0_0.length);
      -443 
      -444             // 2.1 check if pkcs5PBES2(1 2 840 113549 1 5 13)
      -445             if (_getV(sHEX, a0_0[0]) != "2a864886f70d01050d")
      -446                 throw new Error("this only supports pkcs5PBES2");
      -447 
      -448             // 2.2 pkcs5PBES2 param
      -449             var a0_0_1 = _getChildIdx(sHEX, a0_0[1]); 
      -450             if (a0_0.length != 2)
      -451                 throw new Error("malformed format: SEQUENCE(0.0.1).items != 2: "
      -452 				+ a0_0_1.length);
      -453 
      -454             // 2.2.1 encryptionScheme
      -455             var a0_0_1_1 = _getChildIdx(sHEX, a0_0_1[1]); 
      -456             if (a0_0_1_1.length != 2)
      -457                 throw new Error("malformed format: " + 
      -458 				"SEQUENCE(0.0.1.1).items != 2: " +
      -459 				a0_0_1_1.length);
      -460             if (_getV(sHEX, a0_0_1_1[0]) != "2a864886f70d0307")
      -461                 throw "this only supports TripleDES";
      -462             info.encryptionSchemeAlg = "TripleDES";
      -463 
      -464             // 2.2.1.1 IV of encryptionScheme
      -465             info.encryptionSchemeIV = _getV(sHEX, a0_0_1_1[1]);
      -466 
      -467             // 2.2.2 keyDerivationFunc
      -468             var a0_0_1_0 = _getChildIdx(sHEX, a0_0_1[0]); 
      -469             if (a0_0_1_0.length != 2)
      -470                 throw new Error("malformed format: " +
      -471 				"SEQUENCE(0.0.1.0).items != 2: "
      -472 				+ a0_0_1_0.length);
      -473             if (_getV(sHEX, a0_0_1_0[0]) != "2a864886f70d01050c")
      -474                 throw new Error("this only supports pkcs5PBKDF2");
      -475 
      -476             // 2.2.2.1 pkcs5PBKDF2 param
      -477             var a0_0_1_0_1 = _getChildIdx(sHEX, a0_0_1_0[1]); 
      -478             if (a0_0_1_0_1.length < 2)
      -479                 throw new Error("malformed format: " +
      -480 				"SEQUENCE(0.0.1.0.1).items < 2: " + 
      -481 				a0_0_1_0_1.length);
      -482 
      -483             // 2.2.2.1.1 PBKDF2 salt
      -484             info.pbkdf2Salt = _getV(sHEX, a0_0_1_0_1[0]);
      -485 
      -486             // 2.2.2.1.2 PBKDF2 iter
      -487             var iterNumHex = _getV(sHEX, a0_0_1_0_1[1]);
      -488             try {
      -489                 info.pbkdf2Iter = parseInt(iterNumHex, 16);
      -490             } catch(ex) {
      -491                 throw new Error("malformed format pbkdf2Iter: " + iterNumHex);
      -492             }
      -493 
      -494             return info;
      -495         },
      -496 
      -497         /**
      -498          * generate PBKDF2 key hexstring with specified passcode and information
      -499          * @name getPBKDF2KeyHexFromParam
      -500          * @memberOf KEYUTIL
      -501          * @function
      -502          * @param {Array} info result of {@link parseHexOfEncryptedPKCS8} which has preference of PKCS#8 file
      -503          * @param {String} passcode passcode to decrypto private key
      -504          * @return {String} hexadecimal string of PBKDF2 key
      -505          * @since pkcs5pkey 1.0.3
      -506          * @description
      -507          * As for info, this uses following properties:
      -508          * <ul>
      -509          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
      -510          * <li>info.pkbdf2Iter - iteration count</li>
      -511          * </ul>
      -512          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
      -513          * <ul>
      -514          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
      -515          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
      -516          * </ul>
      -517          * @example
      -518          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      -519          * // key with PBKDF2 with TripleDES
      -520          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
      -521          */
      -522         getPBKDF2KeyHexFromParam: function(info, passcode) {
      -523             var pbkdf2SaltWS = CryptoJS.enc.Hex.parse(info.pbkdf2Salt);
      -524             var pbkdf2Iter = info.pbkdf2Iter;
      -525             var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
      -526                                               pbkdf2SaltWS, 
      -527                                               { keySize: 192/32, iterations: pbkdf2Iter });
      -528             var pbkdf2KeyHex = CryptoJS.enc.Hex.stringify(pbkdf2KeyWS);
      -529             return pbkdf2KeyHex;
      -530         },
      -531 
      -532         /*
      -533          * read PEM formatted encrypted PKCS#8 private key and returns hexadecimal string of plain PKCS#8 private key
      -534          * @name getPlainPKCS8HexFromEncryptedPKCS8PEM
      -535          * @memberOf KEYUTIL
      -536          * @function
      -537          * @param {String} pkcs8PEM PEM formatted encrypted PKCS#8 private key
      -538          * @param {String} passcode passcode to decrypto private key
      -539          * @return {String} hexadecimal string of plain PKCS#8 private key
      -540          * @since pkcs5pkey 1.0.3
      -541          * @description
      -542          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
      -543          * <ul>
      -544          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
      -545          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
      -546          * </ul>
      -547          * @example
      -548          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      -549          * // key with PBKDF2 with TripleDES
      -550          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
      -551          */
      -552         _getPlainPKCS8HexFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
      -553             // 1. derHex - PKCS#8 private key encrypted by PBKDF2
      -554             var derHex = pemtohex(pkcs8PEM, "ENCRYPTED PRIVATE KEY");
      -555             // 2. info - PKCS#5 PBES info
      -556             var info = this.parseHexOfEncryptedPKCS8(derHex);
      -557             // 3. hKey - PBKDF2 key
      -558             var pbkdf2KeyHex = KEYUTIL.getPBKDF2KeyHexFromParam(info, passcode);
      -559             // 4. decrypt ciphertext by PBKDF2 key
      -560             var encrypted = {};
      -561             encrypted.ciphertext = CryptoJS.enc.Hex.parse(info.ciphertext);
      -562             var pbkdf2KeyWS = CryptoJS.enc.Hex.parse(pbkdf2KeyHex);
      -563             var des3IVWS = CryptoJS.enc.Hex.parse(info.encryptionSchemeIV);
      -564             var decWS = CryptoJS.TripleDES.decrypt(encrypted, pbkdf2KeyWS, { iv: des3IVWS });
      -565             var decHex = CryptoJS.enc.Hex.stringify(decWS);
      -566             return decHex;
      -567         },
      -568 
      -569         /**
      -570          * get RSAKey/ECDSA private key object from encrypted PEM PKCS#8 private key
      -571          * @name getKeyFromEncryptedPKCS8PEM
      -572          * @memberOf KEYUTIL
      -573          * @function
      -574          * @param {String} pkcs8PEM string of PEM formatted PKCS#8 private key
      -575          * @param {String} passcode passcode string to decrypt key
      -576          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
      -577          * @since pkcs5pkey 1.0.5
      -578          */
      -579         getKeyFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
      -580             var prvKeyHex = this._getPlainPKCS8HexFromEncryptedPKCS8PEM(pkcs8PEM, passcode);
      -581             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
      -582             return key;
      -583         },
      -584 
      -585         /**
      -586          * parse hexadecimal string of plain PKCS#8 private key
      -587          * @name parsePlainPrivatePKCS8Hex
      -588          * @memberOf KEYUTIL
      -589          * @function
      -590          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 plain private key
      -591          * @return {Array} associative array of parsed key
      -592          * @since pkcs5pkey 1.0.5
      -593          * @description
      -594          * Resulted associative array has following properties:
      -595          * <ul>
      -596          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
      -597          * <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
      -598          * <li>keyidx - string starting index of key in pkcs8PrvHex</li>
      -599          * </ul>
      -600          */
      -601         parsePlainPrivatePKCS8Hex: function(pkcs8PrvHex) {
      -602 	    var _ASN1HEX = ASN1HEX;
      -603 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      -604 	    var _getV = _ASN1HEX.getV;
      -605             var result = {};
      -606             result.algparam = null;
      -607 
      -608             // 1. sequence
      -609             if (pkcs8PrvHex.substr(0, 2) != "30")
      -610                 throw new Error("malformed plain PKCS8 private key(code:001)");
      -611 	        // not sequence
      -612 
      -613             var a1 = _getChildIdx(pkcs8PrvHex, 0);
      -614             if (a1.length < 3)
      -615                 throw new Error("malformed plain PKCS8 private key(code:002)");
      -616                 // less elements
      -617 
      -618             // 2. AlgID
      -619             if (pkcs8PrvHex.substr(a1[1], 2) != "30")
      -620                 throw new Error("malformed PKCS8 private key(code:003)");
      -621                 // AlgId not sequence
      -622 
      -623             var a2 = _getChildIdx(pkcs8PrvHex, a1[1]);
      -624             if (a2.length != 2)
      -625                 throw new Error("malformed PKCS8 private key(code:004)");
      -626                 // AlgId not have two elements
      -627 
      -628             // 2.1. AlgID OID
      -629             if (pkcs8PrvHex.substr(a2[0], 2) != "06")
      -630                 throw new Error("malformed PKCS8 private key(code:005)");
      -631                 // AlgId.oid is not OID
      -632 
      -633             result.algoid = _getV(pkcs8PrvHex, a2[0]);
      -634 
      -635             // 2.2. AlgID param
      -636             if (pkcs8PrvHex.substr(a2[1], 2) == "06") {
      -637                 result.algparam = _getV(pkcs8PrvHex, a2[1]);
      -638             }
      -639 
      -640             // 3. Key index
      -641             if (pkcs8PrvHex.substr(a1[2], 2) != "04")
      -642                 throw new Error("malformed PKCS8 private key(code:006)");
      -643                 // not octet string
      +438         /*
      +439          * get Encrypted PKCS8 private key by PEM string of plain priavte key
      +440          * @name 
      +441          * @memberOf KEYUTIL
      +442          * @function getEncryptedPKCS8Hex
      +443          * @param {string} hPlainPKCS8Prv hexadecimal string of plain PKCS#8 private key
      +444 	 * @param {string} passcode password string for encrytion
      +445 	 * @param {object} param associative array object of parameters for encrypted PKCS#8 (OPTION)
      +446          * @return {string} PEM string of encrypted PKCS#8 private key
      +447          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +448 	 * @see KEYUTIL.getEncryptedPKCS8PEM
      +449 	 *
      +450          * @description
      +451          * <br/>
      +452          * generate PEM formatted encrypted PKCS#8 private key by a hexadecimal string of 
      +453 	 * plain PKCS#8 private key with encryption parameters.
      +454 	 * Regarding to "param", see {@link KEYUTIL.getEncryptedPKCS8PEM}.
      +455 	 *
      +456          * @example
      +457 	 * // generate with default parameters
      +458 	 * KEYUTIL.getEncryptedPKCS8Hex("3082...", "password") → "3082..."
      +459 	 * // des-EDE3-CBC with 4096 iteration
      +460 	 * KEYUTIL.getEncryptedPKCS8PEM("3082...", "password", { encalg: "des-EDE3-CBC", iter: 4096 })  → "3082..."
      +461          */
      +462 	getEncryptedPKCS8Hex: function(hPlainPKCS8Prv, passcode, param) {
      +463 	    var pParam2;
      +464 	    if (param == undefined || param == null) {
      +465 		pParam2 = {};
      +466 	    } else {
      +467 		pParam2 = JSON.parse(JSON.stringify(param));
      +468 	    }
      +469 	    pParam2.plain = hPlainPKCS8Prv;
      +470 	    
      +471 	    this.initPBES2Param(pParam2);
      +472 	    this.encryptPBES2Param(pParam2, passcode);
      +473 	    var pASN = this.generatePBES2ASN1Param(pParam2);
      +474 	    return KJUR.asn1.ASN1Util.newObject(pASN).tohex();
      +475 	},
      +476 
      +477         /*
      +478          * set default PBES2 parameters if not specified
      +479          * @name 
      +480          * @memberOf KEYUTIL
      +481          * @function initPBES2Param
      +482 	 * @param {object} param associative array object of parameters for encrypted PKCS#8
      +483          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +484 	 * @see KEYUTIL.getEncryptedPKCS8PEM
      +485 	 * @see KEYUTIL.getEncryptedPKCS8Hex
      +486 	 *
      +487          * @description
      +488          * <br/>
      +489          * set default PBES2 parameters if not specified in the "param" associative array.
      +490 	 * Here is members:
      +491 	 * <ul>
      +492 	 * <li>encalg - set "aes256-CBC" encryption algorithm if not specified</li>
      +493 	 * <li>iter - set 2048 iteration count if not specified</li>
      +494 	 * <li>prf - set "hmacWithSHA256" psudorandom function if not specified</li>
      +495 	 * <li>salt - set 8 bytes random number hexadecimal string if not specified</li>
      +496 	 * <li>enciv - set random number hexadecimal string of initial vector if not specified.
      +497 	 * The length depends on encryption algorithm.</li>
      +498 	 * </ul>
      +499          */
      +500 	initPBES2Param: function(pPBES2) {
      +501 	    if (aryval(pPBES2, "encalg") == undefined) pPBES2.encalg = "aes256-CBC";
      +502 	    if (aryval(pPBES2, "iter") == undefined) pPBES2.iter = 2048;
      +503 	    if (aryval(pPBES2, "prf") == undefined) pPBES2.prf = "hmacWithSHA256";
      +504 	    if (aryval(pPBES2, "salt") == undefined) pPBES2.salt = CryptoJS.enc.Hex.stringify(CryptoJS.lib.WordArray.random(8));
      +505 	    if (aryval(pPBES2, "enciv") == undefined) {
      +506 		var nbytes;
      +507 		if (pPBES2.encalg == "des-EDE3-CBC") nbytes = 8;
      +508 		if (pPBES2.encalg == "aes128-CBC") nbytes = 16;
      +509 		if (pPBES2.encalg == "aes256-CBC") nbytes = 16;
      +510 		pPBES2.enciv = CryptoJS.enc.Hex.stringify(CryptoJS.lib.WordArray.random(nbytes));
      +511 	    }
      +512 	},
      +513 
      +514         /*
      +515          * encrypt plain private key with PBES2 paramters
      +516          * @name 
      +517          * @memberOf KEYUTIL
      +518          * @function encryptPBES2Param
      +519 	 * @param {object} param associative array object of parameters for encrypted PKCS#8 private key
      +520 	 * @param {string} passcode password string for encrypted PKCS#8 private key.
      +521          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +522 	 * @see KEYUTIL.getEncryptedPKCS8PEM
      +523 	 * @see KEYUTIL.getEncryptedPKCS8Hex
      +524 	 *
      +525          * @description
      +526          * <br/>
      +527          * encrypt plain private key with PBES2 parameters.
      +528 	 * Here is input members in PBES2 paramters.
      +529 	 * <ul>
      +530 	 * <li>plain - hexadecimal string of messages (i.e. plain private key) which will be encrypted</li>
      +531 	 * <li>encalg - encryption algorithm</li>
      +532 	 * <li>iter - iteration count</li>
      +533 	 * <li>prf - psudorandom function</li>
      +534 	 * <li>salt - salt</li>
      +535 	 * <li>enciv - initial vector</li>
      +536 	 * </ul>
      +537 	 * Encrypted result will be set as a new "enc" member of hexadecimal string in PBES2 parameters.
      +538          */
      +539 	encryptPBES2Param: function(pPBES2, passcode) {
      +540 	    var hKey = KEYUTIL.getDKFromPBES2Param(pPBES2, passcode);
      +541 	    try {
      +542 		var hEnc = KJUR.crypto.Cipher.encrypt(pPBES2.plain, hKey, pPBES2.encalg, { iv: pPBES2.enciv });
      +543 	    } catch(ex) {
      +544 		throw new Error("encrypt error: " + pPBES2.plain + " " + hKey + " " + pPBES2.encalg + " " + pPBES2.enciv);
      +545 	    }
      +546 	    pPBES2.enc = hEnc;
      +547 	},
      +548 
      +549         /*
      +550          * convert from PBES2 parameters to PKCS#8 encrypted private key ASN1 object
      +551          * @name 
      +552          * @memberOf KEYUTIL
      +553          * @function generatePBES2ASN1Param
      +554 	 * @param {object} param associative array object of parameters for encrypted PKCS#8 private key
      +555 	 * @param {object} associative array object of ASN1 object
      +556          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +557 	 * @see KEYUTIL.getEncryptedPKCS8PEM
      +558 	 * @see KEYUTIL.getEncryptedPKCS8Hex
      +559 	 * @see KJUR.asn1.ASN1Util.newObject
      +560 	 *
      +561          * @description
      +562          * <br/>
      +563 	 * convert from PBES2 paramters to ASN1 object which can be
      +564 	 * passwd to {@link KJUR.asn1.ASN1Util.newObject}.
      +565 	 * Here is input members in PBES2 paramters.
      +566 	 * <ul>
      +567 	 * <li>encalg - encryption algorithm</li>
      +568 	 * <li>iter - iteration count</li>
      +569 	 * <li>prf - psudorandom function</li>
      +570 	 * <li>salt - salt</li>
      +571 	 * <li>enciv - initial vector</li>
      +572 	 * <li>enc - encrypted private key</li>
      +573 	 * </ul>
      +574 	 * Note that prf will be omitted when prf is a default "hmacWithSHA1".
      +575          */
      +576 	generatePBES2ASN1Param: function(pPBES2) {
      +577 	    var pASN = 
      +578 		{ seq: [
      +579 		    { seq: [
      +580 			{ oid: "pkcs5PBES2" },
      +581 			{ seq: [
      +582 			    { seq: [
      +583 				{ oid: "pkcs5PBKDF2" },
      +584 				{ seq: [
      +585 				    { octstr: { hex: pPBES2.salt } },
      +586 				    { "int": { hex: inttohex(pPBES2.iter) } }
      +587 				] }
      +588 			    ] },
      +589 			    { seq: [
      +590 				{ oid: pPBES2.encalg },
      +591 				{ octstr: { hex: pPBES2.enciv } }
      +592 			    ] }
      +593 			] }
      +594 		    ] },
      +595 		    { octstr: { hex: pPBES2.enc } }
      +596 		] };
      +597 	    if (pPBES2.prf != "hmacWithSHA1") {
      +598 		pASN.seq[0].seq[1].seq[0].seq[1].seq.push({seq:[{oid:pPBES2.prf},{"null":""}]});
      +599 	    }
      +600 	    return pASN;
      +601 	},
      +602 
      +603         // === PKCS8 ===============================================================
      +604 
      +605         /**
      +606          * generate PBKDF2 key hexstring with specified passcode and information (DEPRECATED)
      +607          * @name parseHexOfEncryptedPKCS8
      +608          * @memberOf KEYUTIL
      +609          * @function
      +610          * @param {String} passcode passcode to decrypto private key
      +611          * @return {Array} info associative array of PKCS#8 parameters
      +612          * @since pkcs5pkey 1.0.3
      +613 	 * @deprecated since jsrsasign 10.9.0 keyutil 1.3.0. Use {@link KEYUTIL.parsePBES2} instead.
      +614 	 *
      +615          * @description
      +616          * The associative array which is returned by this method has following properties:
      +617          * <ul>
      +618          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
      +619          * <li>info.pkbdf2Iter - iteration count</li>
      +620          * <li>info.ciphertext - hexadecimal string of encrypted private key</li>
      +621          * <li>info.encryptionSchemeAlg - encryption algorithm name (currently TripleDES only)</li>
      +622          * <li>info.encryptionSchemeIV - initial vector for encryption algorithm</li>
      +623          * </ul>
      +624          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
      +625          * <ul>
      +626          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
      +627          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
      +628          * </ul>
      +629          * @example
      +630          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      +631          * // key with PBKDF2 with TripleDES
      +632          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
      +633          */
      +634         parseHexOfEncryptedPKCS8: function(sHEX) {
      +635 	    var _ASN1HEX = ASN1HEX;
      +636 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      +637 	    var _getV = _ASN1HEX.getV;
      +638             var info = {};
      +639             
      +640             var a0 = _getChildIdx(sHEX, 0);
      +641             if (a0.length != 2)
      +642                 throw new Error("malformed format: SEQUENCE(0).items != 2: " +
      +643 				a0.length);
       644 
      -645             result.keyidx = _ASN1HEX.getVidx(pkcs8PrvHex, a1[2]);
      -646 
      -647             return result;
      -648         },
      -649 
      -650         /**
      -651          * get RSAKey/ECDSA private key object from PEM plain PEM PKCS#8 private key
      -652          * @name getKeyFromPlainPrivatePKCS8PEM
      -653          * @memberOf KEYUTIL
      -654          * @function
      -655          * @param {String} pkcs8PEM string of plain PEM formatted PKCS#8 private key
      -656          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
      -657          * @since pkcs5pkey 1.0.5
      -658          */
      -659         getKeyFromPlainPrivatePKCS8PEM: function(prvKeyPEM) {
      -660             var prvKeyHex = pemtohex(prvKeyPEM, "PRIVATE KEY");
      -661             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
      -662             return key;
      -663         },
      -664 
      -665         /**
      -666          * get RSAKey/DSA/ECDSA private key object from HEX plain PEM PKCS#8 private key
      -667          * @name getKeyFromPlainPrivatePKCS8Hex
      -668          * @memberOf KEYUTIL
      -669          * @function
      -670          * @param {String} prvKeyHex hexadecimal string of plain PKCS#8 private key
      -671          * @return {Object} RSAKey or KJUR.crypto.{DSA,ECDSA} private key object
      -672          * @since pkcs5pkey 1.0.5
      -673          */
      -674         getKeyFromPlainPrivatePKCS8Hex: function(prvKeyHex) {
      -675             var p8 = this.parsePlainPrivatePKCS8Hex(prvKeyHex);
      -676 	    var key;
      -677             
      -678             if (p8.algoid == "2a864886f70d010101") { // RSA
      -679 		key = new RSAKey();
      -680 	    } else if (p8.algoid == "2a8648ce380401") { // DSA
      -681 		key = new KJUR.crypto.DSA();
      -682             } else if (p8.algoid == "2a8648ce3d0201") { // ECC
      -683                 key = new KJUR.crypto.ECDSA();
      -684             } else {
      -685                 throw new Error("unsupported private key algorithm");
      -686             }
      -687 
      -688 	    key.readPKCS8PrvKeyHex(prvKeyHex);
      -689 	    return key;
      -690         },
      -691 
      -692         // === PKCS8 RSA Public Key ================================================
      -693 
      -694         /*
      -695          * get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#8 public key
      -696          * @name _getKeyFromPublicPKCS8Hex
      -697          * @memberOf KEYUTIL
      -698          * @function
      -699          * @param {String} pkcsPub8Hex hexadecimal string of PKCS#8 public key
      -700          * @return {Object} RSAKey or KJUR.crypto.{ECDSA,DSA} private key object
      -701          * @since pkcs5pkey 1.0.5
      -702          */
      -703         _getKeyFromPublicPKCS8Hex: function(h) {
      -704 	    var key;
      -705 	    var hOID = ASN1HEX.getVbyList(h, 0, [0, 0], "06");
      +645             // 1. ciphertext
      +646             info.ciphertext = _getV(sHEX, a0[1]);
      +647 
      +648             // 2. pkcs5PBES2
      +649             var a0_0 = _getChildIdx(sHEX, a0[0]); 
      +650             if (a0_0.length != 2)
      +651                 throw new Error("malformed format: SEQUENCE(0.0).items != 2: "
      +652 				+ a0_0.length);
      +653 
      +654             // 2.1 check if pkcs5PBES2(1 2 840 113549 1 5 13)
      +655             if (_getV(sHEX, a0_0[0]) != "2a864886f70d01050d")
      +656                 throw new Error("this only supports pkcs5PBES2");
      +657 
      +658             // 2.2 pkcs5PBES2 param
      +659             var a0_0_1 = _getChildIdx(sHEX, a0_0[1]); 
      +660             if (a0_0.length != 2)
      +661                 throw new Error("malformed format: SEQUENCE(0.0.1).items != 2: "
      +662 				+ a0_0_1.length);
      +663 
      +664             // 2.2.1 encryptionScheme
      +665             var a0_0_1_1 = _getChildIdx(sHEX, a0_0_1[1]); 
      +666             if (a0_0_1_1.length != 2)
      +667                 throw new Error("malformed format: " + 
      +668 				"SEQUENCE(0.0.1.1).items != 2: " +
      +669 				a0_0_1_1.length);
      +670             if (_getV(sHEX, a0_0_1_1[0]) != "2a864886f70d0307")
      +671                 throw "this only supports TripleDES";
      +672             info.encryptionSchemeAlg = "TripleDES";
      +673 
      +674             // 2.2.1.1 IV of encryptionScheme
      +675             info.encryptionSchemeIV = _getV(sHEX, a0_0_1_1[1]);
      +676 
      +677             // 2.2.2 keyDerivationFunc
      +678             var a0_0_1_0 = _getChildIdx(sHEX, a0_0_1[0]); 
      +679             if (a0_0_1_0.length != 2)
      +680                 throw new Error("malformed format: " +
      +681 				"SEQUENCE(0.0.1.0).items != 2: "
      +682 				+ a0_0_1_0.length);
      +683             if (_getV(sHEX, a0_0_1_0[0]) != "2a864886f70d01050c")
      +684                 throw new Error("this only supports pkcs5PBKDF2");
      +685 
      +686             // 2.2.2.1 pkcs5PBKDF2 param
      +687             var a0_0_1_0_1 = _getChildIdx(sHEX, a0_0_1_0[1]); 
      +688             if (a0_0_1_0_1.length < 2)
      +689                 throw new Error("malformed format: " +
      +690 				"SEQUENCE(0.0.1.0.1).items < 2: " + 
      +691 				a0_0_1_0_1.length);
      +692 
      +693             // 2.2.2.1.1 PBKDF2 salt
      +694             info.pbkdf2Salt = _getV(sHEX, a0_0_1_0_1[0]);
      +695 
      +696             // 2.2.2.1.2 PBKDF2 iter
      +697             var iterNumHex = _getV(sHEX, a0_0_1_0_1[1]);
      +698             try {
      +699                 info.pbkdf2Iter = parseInt(iterNumHex, 16);
      +700             } catch(ex) {
      +701                 throw new Error("malformed format pbkdf2Iter: " + iterNumHex);
      +702             }
      +703 
      +704             return info;
      +705         },
       706 
      -707 	    if (hOID === "2a864886f70d010101") {    // oid=RSA
      -708 		key = new RSAKey();
      -709 	    } else if (hOID === "2a8648ce380401") { // oid=DSA
      -710 		key = new KJUR.crypto.DSA();
      -711 	    } else if (hOID === "2a8648ce3d0201") { // oid=ECPUB
      -712 		key = new KJUR.crypto.ECDSA();
      -713 	    } else {
      -714 		throw new Error("unsupported PKCS#8 public key hex");
      -715 	    }
      -716 	    key.readPKCS8PubKeyHex(h);
      -717 	    return key;
      -718 	},
      -719 
      -720         /**
      -721          * parse hexadecimal string of plain PKCS#8 private key
      -722          * @name parsePublicRawRSAKeyHex
      -723          * @memberOf KEYUTIL
      -724          * @function
      -725          * @param {String} pubRawRSAHex hexadecimal string of ASN.1 encoded PKCS#8 public key
      -726          * @return {Array} associative array of parsed key
      -727          * @since pkcs5pkey 1.0.5
      -728          * @description
      -729          * Resulted associative array has following properties:
      -730          * <ul>
      -731          * <li>n - hexadecimal string of public key
      -732          * <li>e - hexadecimal string of public exponent
      -733          * </ul>
      -734          */
      -735         parsePublicRawRSAKeyHex: function(pubRawRSAHex) {
      -736 	    var _ASN1HEX = ASN1HEX;
      -737 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      -738 	    var _getV = _ASN1HEX.getV;
      -739             var result = {};
      -740             
      -741             // 1. Sequence
      -742             if (pubRawRSAHex.substr(0, 2) != "30")
      -743                 throw new Error("malformed RSA key(code:001)"); // not sequence
      -744             
      -745             var a1 = _getChildIdx(pubRawRSAHex, 0);
      -746             if (a1.length != 2)
      -747                 throw new Error("malformed RSA key(code:002)"); // not 2 items in seq
      -748 
      -749             // 2. public key "N"
      -750             if (pubRawRSAHex.substr(a1[0], 2) != "02")
      -751                 throw new Error("malformed RSA key(code:003)"); // 1st item is not integer
      -752 
      -753             result.n = _getV(pubRawRSAHex, a1[0]);
      -754 
      -755             // 3. public key "E"
      -756             if (pubRawRSAHex.substr(a1[1], 2) != "02")
      -757                 throw new Error("malformed RSA key(code:004)"); // 2nd item is not integer
      -758 
      -759             result.e = _getV(pubRawRSAHex, a1[1]);
      -760 
      -761             return result;
      -762         },
      -763 
      -764         /**
      -765          * parse hexadecimal string of PKCS#8 RSA/EC/DSA public key
      -766          * @name parsePublicPKCS8Hex
      -767          * @memberOf KEYUTIL
      -768          * @function
      -769          * @param {String} pkcs8PubHex hexadecimal string of PKCS#8 public key
      -770          * @return {Hash} hash of key information
      -771          * @description
      -772          * Resulted hash has following attributes.
      -773          * <ul>
      -774          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
      -775          * <li>algparam - hexadecimal string of OID of ECC curve name, parameter SEQUENCE of DSA or null</li>
      -776          * <li>key - hexadecimal string of public key</li>
      -777          * </ul>
      -778          */
      -779         parsePublicPKCS8Hex: function(pkcs8PubHex) {
      -780 	    var _ASN1HEX = ASN1HEX;
      -781 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      -782 	    var _getV = _ASN1HEX.getV;
      -783             var result = {};
      -784             result.algparam = null;
      -785 
      -786             // 1. AlgID and Key bit string
      -787             var a1 = _getChildIdx(pkcs8PubHex, 0);
      -788             if (a1.length != 2)
      -789                 throw new Error("outer DERSequence shall have 2 elements: " + a1.length);
      -790 
      -791             // 2. AlgID
      -792             var idxAlgIdTLV = a1[0];
      -793             if (pkcs8PubHex.substr(idxAlgIdTLV, 2) != "30")
      -794                 throw new Error("malformed PKCS8 public key(code:001)"); // AlgId not sequence
      -795 
      -796             var a2 = _getChildIdx(pkcs8PubHex, idxAlgIdTLV);
      -797             if (a2.length != 2)
      -798                 throw new Error("malformed PKCS8 public key(code:002)"); // AlgId not have two elements
      -799 
      -800             // 2.1. AlgID OID
      -801             if (pkcs8PubHex.substr(a2[0], 2) != "06")
      -802                 throw new Error("malformed PKCS8 public key(code:003)"); // AlgId.oid is not OID
      -803 
      -804             result.algoid = _getV(pkcs8PubHex, a2[0]);
      -805 
      -806             // 2.2. AlgID param
      -807             if (pkcs8PubHex.substr(a2[1], 2) == "06") { // OID for EC
      -808                 result.algparam = _getV(pkcs8PubHex, a2[1]);
      -809             } else if (pkcs8PubHex.substr(a2[1], 2) == "30") { // SEQ for DSA
      -810                 result.algparam = {};
      -811                 result.algparam.p = _ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [0], "02");
      -812                 result.algparam.q = _ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [1], "02");
      -813                 result.algparam.g = _ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [2], "02");
      -814             }
      -815 
      -816             // 3. Key
      -817             if (pkcs8PubHex.substr(a1[1], 2) != "03")
      -818                 throw new Error("malformed PKCS8 public key(code:004)"); // Key is not bit string
      -819 
      -820             result.key = _getV(pkcs8PubHex, a1[1]).substr(2);
      -821             
      -822             // 4. return result assoc array
      -823             return result;
      -824         },
      -825     };
      -826 }();
      -827 
      -828 // -- MAJOR PUBLIC METHODS ----------------------------------------------------
      -829 /**
      -830  * get private or public key object from any arguments
      -831  * @name getKey
      -832  * @memberOf KEYUTIL
      -833  * @function
      -834  * @static
      -835  * @param {Object} param parameter to get key object. see description in detail.
      -836  * @param {String} passcode (OPTION) parameter to get key object. see description in detail.
      -837  * @param {String} hextype (OPTOIN) parameter to get key object. see description in detail.
      -838  * @return {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.ECDSA} object
      -839  * @since keyutil 1.0.0
      -840  * @description
      -841  * This method gets private or public key object({@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA})
      -842  * for RSA, DSA and ECC.
      -843  * Arguments for this methods depends on a key format you specify.
      -844  * Following key representations are supported.
      -845  * <ul>
      -846  * <li>ECC private/public key object(as is): param=KJUR.crypto.ECDSA</li>
      -847  * <li>DSA private/public key object(as is): param=KJUR.crypto.DSA</li>
      -848  * <li>RSA private/public key object(as is): param=RSAKey </li>
      -849  * <li>ECC private key parameters: param={d: d, curve: curveName}</li>
      -850  * <li>RSA private key parameters: param={n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq, co: co}<br/>
      -851  * NOTE: Each value shall be hexadecimal string of key spec.</li>
      -852  * <li>DSA private key parameters: param={p: p, q: q, g: g, y: y, x: x}<br/>
      -853  * NOTE: Each value shall be hexadecimal string of key spec.</li>
      -854  * <li>ECC public key parameters: param={xy: xy, curve: curveName}<br/>
      -855  * NOTE: ECC public key 'xy' shall be concatination of "04", x-bytes-hex and y-bytes-hex.</li>
      -856  * <li>DSA public key parameters: param={p: p, q: q, g: g, y: y}<br/>
      -857  * NOTE: Each value shall be hexadecimal string of key spec.</li>
      -858  * <li>RSA public key parameters: param={n: n, e: e} </li>
      -859  * <li>X.509v1/v3 PEM certificate (RSA/DSA/ECC): param=pemString</li>
      -860  * <li>PKCS#8 hexadecimal RSA/ECC public key: param=pemString, null, "pkcs8pub"</li>
      -861  * <li>PKCS#8 PEM RSA/DSA/ECC public key: param=pemString</li>
      -862  * <li>PKCS#5 plain hexadecimal RSA private key: param=hexString, null, "pkcs5prv"</li>
      -863  * <li>PKCS#5 plain PEM RSA/DSA/EC private key: param=pemString</li>
      -864  * <li>PKCS#8 plain PEM RSA/EC private key: param=pemString</li>
      -865  * <li>PKCS#5 encrypted PEM RSA/DSA/EC private key: param=pemString, passcode</li>
      -866  * <li>PKCS#8 encrypted PEM RSA/EC private key: param=pemString, passcode</li>
      -867  * </ul>
      -868  * Please note following limitation on encrypted keys:
      -869  * <ul>
      -870  * <li>Encrypted PKCS#8 only supports PBKDF2/HmacSHA1/3DES</li>
      -871  * <li>Encrypted PKCS#5 supports DES-CBC, DES-EDE3-CBC, AES-{128,192.256}-CBC</li>
      -872  * <li>JWT plain ECC private/public key</li>
      -873  * <li>JWT plain RSA public key</li>
      -874  * <li>JWT plain RSA private key with P/Q/DP/DQ/COEFF</li>
      -875  * <li>JWT plain RSA private key without P/Q/DP/DQ/COEFF (since jsrsasign 5.0.0)</li>
      -876  * </ul>
      -877  * NOTE1: <a href="https://tools.ietf.org/html/rfc7517">RFC 7517 JSON Web Key(JWK)</a> support for RSA/ECC private/public key from jsrsasign 4.8.1.<br/>
      -878  * NOTE2: X509v1 support is added since jsrsasign 5.0.11.
      -879  * 
      -880  * <h5>EXAMPLE</h5>
      -881  * @example
      -882  * // 1. loading private key from PEM string
      -883  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY...");
      -884  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY..., "passcode");
      -885  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
      -886  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...", "passcode");
      -887  * keyObj = KEYUTIL.getKey("-----BEGIN EC PARAMETERS...-----BEGIN EC PRIVATE KEY...");
      -888  * // 2. loading public key from PEM string
      -889  * keyObj = KEYUTIL.getKey("-----BEGIN PUBLIC KEY...");
      -890  * keyObj = KEYUTIL.getKey("-----BEGIN X509 CERTIFICATE...");
      -891  * // 3. loading hexadecimal PKCS#5/PKCS#8 key
      -892  * keyObj = KEYUTIL.getKey("308205c1...", null, "pkcs8pub");
      -893  * keyObj = KEYUTIL.getKey("3082048b...", null, "pkcs5prv");
      -894  * // 4. loading JSON Web Key(JWK)
      -895  * keyObj = KEYUTIL.getKey({kty: "RSA", n: "0vx7...", e: "AQAB"});
      -896  * keyObj = KEYUTIL.getKey({kty: "EC", crv: "P-256", 
      -897  *                          x: "MKBC...", y: "4Etl6...", d: "870Mb..."});
      -898  * // 5. bare hexadecimal key
      -899  * keyObj = KEYUTIL.getKey({n: "75ab..", e: "010001"});
      -900  */
      -901 KEYUTIL.getKey = function(param, passcode, hextype) {
      -902     var _ASN1HEX = ASN1HEX,
      -903 	_getChildIdx = _ASN1HEX.getChildIdx,
      -904 	_getV = _ASN1HEX.getV,
      -905 	_getVbyList = _ASN1HEX.getVbyList,
      -906 	_KJUR_crypto = KJUR.crypto,
      -907 	_KJUR_crypto_ECDSA = _KJUR_crypto.ECDSA,
      -908 	_KJUR_crypto_DSA = _KJUR_crypto.DSA,
      -909 	_RSAKey = RSAKey,
      -910 	_pemtohex = pemtohex,
      -911 	_KEYUTIL = KEYUTIL;
      -912 
      -913     // 1. by key RSAKey/KJUR.crypto.ECDSA/KJUR.crypto.DSA object
      -914     if (typeof _RSAKey != 'undefined' && param instanceof _RSAKey)
      -915         return param;
      -916     if (typeof _KJUR_crypto_ECDSA != 'undefined' && param instanceof _KJUR_crypto_ECDSA)
      -917         return param;
      -918     if (typeof _KJUR_crypto_DSA != 'undefined' && param instanceof _KJUR_crypto_DSA)
      -919         return param;
      -920 
      -921     // 2. by parameters of key
      -922 
      -923     // 2.1. bare ECC
      -924     // 2.1.1. bare ECC public key by hex values
      -925     if (param.curve !== undefined &&
      -926 	param.xy !== undefined && param.d === undefined) {
      -927         return new _KJUR_crypto_ECDSA({pub: param.xy, curve: param.curve});
      -928     }
      -929 
      -930     // 2.1.2. bare ECC private key by hex values
      -931     if (param.curve !== undefined && param.d !== undefined) {
      -932         return new _KJUR_crypto_ECDSA({prv: param.d, curve: param.curve});
      -933     }
      -934 
      -935     // 2.2. bare RSA
      -936     // 2.2.1. bare RSA public key by hex values
      -937     if (param.kty === undefined &&
      -938 	param.n !== undefined && param.e !== undefined &&
      -939         param.d === undefined) {
      -940         var key = new _RSAKey();
      -941         key.setPublic(param.n, param.e);
      -942         return key;
      -943     }
      -944 
      -945     // 2.2.2. bare RSA private key with P/Q/DP/DQ/COEFF by hex values
      -946     if (param.kty === undefined &&
      -947 	param.n !== undefined &&
      -948 	param.e !== undefined &&
      -949 	param.d !== undefined &&
      -950         param.p !== undefined &&
      -951 	param.q !== undefined &&
      -952         param.dp !== undefined &&
      -953 	param.dq !== undefined &&
      -954 	param.co !== undefined &&
      -955         param.qi === undefined) {
      -956         var key = new _RSAKey();
      -957         key.setPrivateEx(param.n, param.e, param.d, param.p, param.q,
      -958                          param.dp, param.dq, param.co);
      -959         return key;
      -960     }
      -961 
      -962     // 2.2.3. bare RSA public key without P/Q/DP/DQ/COEFF by hex values
      -963     if (param.kty === undefined &&
      -964 	param.n !== undefined &&
      -965 	param.e !== undefined &&
      -966 	param.d !== undefined &&
      -967         param.p === undefined) {
      -968         var key = new _RSAKey();
      -969         key.setPrivate(param.n, param.e, param.d);
      -970         return key;
      -971     }
      -972 
      -973     // 2.3. bare DSA
      -974     // 2.3.1. bare DSA public key by hex values
      -975     if (param.p !== undefined && param.q !== undefined &&
      -976 	param.g !== undefined &&
      -977         param.y !== undefined && param.x === undefined) {
      -978         var key = new _KJUR_crypto_DSA();
      -979         key.setPublic(param.p, param.q, param.g, param.y);
      -980         return key;
      -981     }
      -982 
      -983     // 2.3.2. bare DSA private key by hex values
      -984     if (param.p !== undefined && param.q !== undefined &&
      -985 	param.g !== undefined &&
      -986         param.y !== undefined && param.x !== undefined) {
      -987         var key = new _KJUR_crypto_DSA();
      -988         key.setPrivate(param.p, param.q, param.g, param.y, param.x);
      -989         return key;
      -990     }
      -991 
      -992     // 3. JWK
      -993     // 3.1. JWK RSA
      -994     // 3.1.1. JWK RSA public key by b64u values
      -995     if (param.kty === "RSA" &&
      -996 	param.n !== undefined &&
      -997 	param.e !== undefined &&
      -998 	param.d === undefined) {
      -999 	var key = new _RSAKey();
      -1000 	key.setPublic(b64utohex(param.n), b64utohex(param.e));
      -1001 	return key;
      -1002     }
      +707         /**
      +708          * generate PBKDF2 key hexstring with specified passcode and information (DEPRECATED)
      +709          * @name getPBKDF2KeyHexFromParam
      +710          * @memberOf KEYUTIL
      +711          * @function
      +712          * @param {Array} info result of {@link parseHexOfEncryptedPKCS8} which has preference of PKCS#8 file
      +713          * @param {String} passcode passcode to decrypto private key
      +714          * @return {String} hexadecimal string of PBKDF2 key
      +715          * @since pkcs5pkey 1.0.3
      +716 	 * @deprecated since jsrsasign 10.9.0 keyutil 1.3.0. Use {@link KEYUTIL.getDKFromPBES2Param} instead.
      +717 	 *
      +718          * @description
      +719          * As for info, this uses following properties:
      +720          * <ul>
      +721          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
      +722          * <li>info.pkbdf2Iter - iteration count</li>
      +723          * </ul>
      +724          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
      +725          * <ul>
      +726          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
      +727          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
      +728          * </ul>
      +729          * @example
      +730          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      +731          * // key with PBKDF2 with TripleDES
      +732          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 des3 -out encrypted_p8.pem
      +733          */
      +734         getPBKDF2KeyHexFromParam: function(info, passcode) {
      +735             var pbkdf2SaltWS = CryptoJS.enc.Hex.parse(info.pbkdf2Salt);
      +736             var pbkdf2Iter = info.pbkdf2Iter;
      +737             var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
      +738                                               pbkdf2SaltWS, 
      +739                                               { keySize: 192/32, iterations: pbkdf2Iter });
      +740             var pbkdf2KeyHex = CryptoJS.enc.Hex.stringify(pbkdf2KeyWS);
      +741             return pbkdf2KeyHex;
      +742         },
      +743 
      +744         /*
      +745          * read PEM formatted encrypted PKCS#8 private key and returns hexadecimal string of plain PKCS#8 private key (DEPRECATED)
      +746          * @name getPlainPKCS8HexFromEncryptedPKCS8PEM
      +747          * @memberOf KEYUTIL
      +748          * @function
      +749          * @param {String} pkcs8PEM PEM formatted encrypted PKCS#8 private key
      +750          * @param {String} passcode passcode to decrypto private key
      +751          * @return {String} hexadecimal string of plain PKCS#8 private key
      +752          * @since pkcs5pkey 1.0.3
      +753 	 * @deprecated since jsrsasign 10.9.0 keyutil 1.3.0. Use {@link KEYUTIL.getPlainHexFromEncryptedPKCS8PEM} instead.
      +754 	 * 
      +755          * @description
      +756          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
      +757          * <ul>
      +758          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
      +759          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
      +760          * </ul>
      +761          * @example
      +762          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      +763          * // key with PBKDF2 with TripleDES
      +764          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
      +765          */
      +766         _getPlainPKCS8HexFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
      +767             // 1. derHex - PKCS#8 private key encrypted by PBKDF2
      +768             var derHex = pemtohex(pkcs8PEM, "ENCRYPTED PRIVATE KEY");
      +769             // 2. info - PKCS#5 PBES info
      +770             var info = this.parseHexOfEncryptedPKCS8(derHex);
      +771             // 3. hKey - PBKDF2 key
      +772             var pbkdf2KeyHex = KEYUTIL.getPBKDF2KeyHexFromParam(info, passcode);
      +773             // 4. decrypt ciphertext by PBKDF2 key
      +774             var encrypted = {};
      +775             encrypted.ciphertext = CryptoJS.enc.Hex.parse(info.ciphertext);
      +776             var pbkdf2KeyWS = CryptoJS.enc.Hex.parse(pbkdf2KeyHex);
      +777             var des3IVWS = CryptoJS.enc.Hex.parse(info.encryptionSchemeIV);
      +778             var decWS = CryptoJS.TripleDES.decrypt(encrypted, pbkdf2KeyWS, { iv: des3IVWS });
      +779             var decHex = CryptoJS.enc.Hex.stringify(decWS);
      +780             return decHex;
      +781         },
      +782 
      +783 	/**
      +784          * parse ASN.1 hexadecimal encrypted PKCS#8 private key and return as JSON
      +785          * @name parsePBES2
      +786          * @memberOf KEYUTIL
      +787          * @function
      +788          * @param {string} hP8Prv hexadecimal encrypted PKCS#8 private key
      +789 	 * @return {object} parsed PBES2 parameters JSON object
      +790          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +791          * @description
      +792 	 * This method parses ASN.1 hexadecimal encrypted PKCS#8 private key and returns as 
      +793 	 * JSON object based on 
      +794 	 * <a href="https://datatracker.ietf.org/doc/html/rfc8018" target="_blank">RFC 8018</a>.
      +795 	 * Currently following algorithms are supported:
      +796 	 * <ul>
      +797 	 * <li>prf(psudorandom function) - hmacWithSHA1,SHA224,SHA256,SHA384,SHA512</li>
      +798 	 * <li>encryptionScheme - des-EDE3-CBC,aes128-CBC,aes256-CBC</li>
      +799 	 * </ul>
      +800 	 * @see KEYUTIL.getDKFromPBES2Param
      +801 	 *
      +802          * @example
      +803 	 * KEYUTIL.parsePBES2("3082...") →
      +804 	 * {
      +805 	 *   "prf": "hmacWithSHA256",
      +806 	 *   "salt": "1234567890abcdef",
      +807 	 *   "iter": 2048,
      +808 	 *   "encalg": "aes256-CBC",
      +809 	 *   "enciv": "12ab...",
      +810 	 *   "enc": "34cd..."
      +811 	 * }
      +812 	 *
      +813          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
      +814          * // key with PBKDF2 with TripleDES
      +815          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 des3 -out encrypted_p8.pem
      +816 	 */
      +817 	parsePBES2: function(hP8Prv) {
      +818 	    var pASN = ASN1HEX.parse(hP8Prv);
      +819 	    if (aryval(pASN, "seq.0.seq.0.oid") != "pkcs5PBES2" ||
      +820 		aryval(pASN, "seq.0.seq.1.seq.0.seq.0.oid") != "pkcs5PBKDF2") {
      +821 		throw new Error("not pkcs5PBES2 and pkcs5PBKDF2 used");
      +822 	    }
      +823 	    var pASNKDF = aryval(pASN, "seq.0.seq.1.seq.0.seq.1.seq");
      +824 	    if (pASNKDF == undefined) {
      +825 		throw new Error("PBKDF2 parameter not found");
      +826 	    }
      +827 	    var salt = aryval(pASNKDF, "0.octstr.hex");
      +828 	    var hIter = aryval(pASNKDF, "1.int.hex");
      +829 	    var prf = aryval(pASNKDF, "2.seq.0.oid", "hmacWithSHA1");
      +830 		
      +831 	    var iter = -1;
      +832 	    try {
      +833 		iter = parseInt(hIter, 16);
      +834 	    } catch(ex) {
      +835 		throw new Error("iter not proper value");
      +836 	    };
      +837 
      +838 	    var encalg = aryval(pASN, "seq.0.seq.1.seq.1.seq.0.oid");
      +839 	    var enciv = aryval(pASN, "seq.0.seq.1.seq.1.seq.1.octstr.hex");
      +840 	    var enc = aryval(pASN, "seq.1.octstr.hex");
      +841 	    if (encalg == undefined || enciv == undefined || enc == undefined)
      +842 		throw new Error("encalg, enciv or enc is undefined");
      +843 
      +844 	    var result = {
      +845 		salt: salt,
      +846 		iter: iter,
      +847 		prf: prf,
      +848 		encalg: encalg,
      +849 		enciv: enciv,
      +850 		enc: enc
      +851 	    };
      +852 	    return result;
      +853 	},
      +854 
      +855 	/**
      +856          * get derived key from PBES2 parameters and passcode
      +857          * @name getDKFromPBES2Param
      +858          * @memberOf KEYUTIL
      +859          * @function
      +860          * @param {object} pPBES2 parsed PBES2 parameter by {@link KEYUTIL.parsePBES2} method
      +861 	 * @param {string} passcode password to derive the key
      +862 	 * @return {string} hexadecimal string of derived key
      +863          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +864 	 * @see KEYUTIL.parsePBES2
      +865 	 *
      +866          * @description
      +867 	 * This method derives a key from a passcode and a PBES2 parameter by 
      +868 	 * {@link KEYUTIL.parsePBES2}.
      +869 	 * Currently following algorithms are supported:
      +870 	 * <ul>
      +871 	 * <li>prf(psudorandom function) - hmacWithSHA1,SHA224,SHA256,SHA384,SHA512</li>
      +872 	 * <li>encryptionScheme - des-EDE3-CBC,aes128-CBC,aes256-CBC</li>
      +873 	 * </ul>
      +874 	 *
      +875          * @example
      +876 	 * pPBES2 = {
      +877 	 *   "prf": "hmacWithSHA256",
      +878 	 *   "salt": "1234567890abcdef",
      +879 	 *   "iter": 2048,
      +880 	 *   "encalg": "aes256-CBC",
      +881 	 *   "enciv": "12ab...",
      +882 	 *   "enc": "34cd..."
      +883 	 * }
      +884 	 * KEYUTIL.getDKFromPBES2Param(pPBES2, "passwd") → "3ab10fd..."
      +885 	 */
      +886 	getDKFromPBES2Param: function(pPBES2, passcode) {
      +887 	    var pHasher = {
      +888 		"hmacWithSHA1":   CryptoJS.algo.SHA1,
      +889 		"hmacWithSHA224": CryptoJS.algo.SHA224,
      +890 		"hmacWithSHA256": CryptoJS.algo.SHA256,
      +891 		"hmacWithSHA384": CryptoJS.algo.SHA384,
      +892 		"hmacWithSHA512": CryptoJS.algo.SHA512
      +893 	    };
      +894 	    var pKeySize = {
      +895 		"des-EDE3-CBC": 192/32,
      +896 		"aes128-CBC": 128/32,
      +897 		"aes256-CBC": 256/32,
      +898 	    };
      +899 
      +900 	    var hasher = pHasher[pPBES2.prf];
      +901 	    if (hasher == undefined)
      +902 		throw new Error("unsupported prf");
      +903 
      +904 	    var keysize = pKeySize[pPBES2.encalg];
      +905 	    if (keysize == undefined)
      +906 		throw new Error("unsupported encalg");
      +907 
      +908 	    var wSalt = CryptoJS.enc.Hex.parse(pPBES2.salt);
      +909 	    var iter = pPBES2.iter;
      +910 	    try {
      +911 		var wKey = CryptoJS.PBKDF2(passcode,
      +912 					   wSalt,
      +913 					   { keySize: keysize,
      +914 					     iterations: iter,
      +915 					     hasher: hasher }); 
      +916 		return CryptoJS.enc.Hex.stringify(wKey);
      +917 	    } catch(ex) {
      +918 		throw new Error("PBKDF2 error: " + ex + " " + JSON.stringify(pPBES2) + " " + passcode);
      +919 	    }
      +920 	},
      +921 
      +922 	/**
      +923          * get plaintext hexadecimal PKCS#8 private key from encrypted PKCS#8 PEM private key 
      +924          * @name getPlainHexFromEncryptedPKCS8PEM
      +925          * @memberOf KEYUTIL
      +926          * @function
      +927          * @param {string} pkcs8PEM PEM string of encrypted PKCS#8 private key
      +928 	 * @param {string} passcode passcode to decrypt the private key
      +929 	 * @return {string} hexadecimal string of decrypted plaintext PKCS#8 private key
      +930          * @since jsrsasign 10.9.0 keyutil 1.3.0
      +931 	 * @see KEYUTIL.parsePBES2
      +932 	 *
      +933          * @description
      +934 	 * This will get a plaintext hexadecimal PKCS#8 private key from a
      +935 	 * encrypted PKCS#8 PEM private key.
      +936 	 * Currently following algorithms are supported:
      +937 	 * <ul>
      +938 	 * <li>prf(psudorandom function) - hmacWithSHA1,SHA224,SHA256,SHA384,SHA512</li>
      +939 	 * <li>encryptionScheme - des-EDE3-CBC,aes128-CBC,aes256-CBC</li>
      +940 	 * </ul>
      +941 	 *
      +942          * @example
      +943 	 * pem = "-----BEGIN ENCRYPTED PRIVATE KEY...";
      +944 	 * KEYUTIL.getPlainHexFromEncryptedPKCS8PEM(pem, "passwd") → "3082..."
      +945 	 */
      +946 	getPlainHexFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
      +947 	    if (pkcs8PEM.indexOf("BEGIN ENCRYPTED PRIVATE KEY") == -1)
      +948 		throw new Error("not Encrypted PKCS#8 PEM string");
      +949 	    var hPBES2 = pemtohex(pkcs8PEM);
      +950 	    var pPBES2;
      +951 	    try {
      +952 		pPBES2 = KEYUTIL.parsePBES2(hPBES2);
      +953 	    } catch(ex) {
      +954 		throw new Error("malformed PBES2 format: " + ex.message);
      +955 	    }
      +956 	    var hKey = KEYUTIL.getDKFromPBES2Param(pPBES2, passcode);
      +957 	    return KJUR.crypto.Cipher.decrypt(pPBES2.enc, hKey, pPBES2.encalg, { iv: pPBES2.enciv });
      +958 	},
      +959 
      +960         /**
      +961          * get RSAKey/ECDSA private key object from encrypted PEM PKCS#8 private key
      +962          * @name getKeyFromEncryptedPKCS8PEM
      +963          * @memberOf KEYUTIL
      +964          * @function
      +965          * @param {String} pkcs8PEM string of PEM formatted PKCS#8 private key
      +966          * @param {String} passcode passcode string to decrypt key
      +967          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
      +968          * @since pkcs5pkey 1.0.5
      +969          */
      +970         getKeyFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
      +971 	    var prvKeyHex = this.getPlainHexFromEncryptedPKCS8PEM(pkcs8PEM, passcode);
      +972             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
      +973             return key;
      +974         },
      +975 
      +976         /**
      +977          * parse hexadecimal string of plain PKCS#8 private key
      +978          * @name parsePlainPrivatePKCS8Hex
      +979          * @memberOf KEYUTIL
      +980          * @function
      +981          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 plain private key
      +982          * @return {Array} associative array of parsed key
      +983          * @since pkcs5pkey 1.0.5
      +984          * @description
      +985          * Resulted associative array has following properties:
      +986          * <ul>
      +987          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
      +988          * <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
      +989          * <li>keyidx - string starting index of key in pkcs8PrvHex</li>
      +990          * </ul>
      +991          */
      +992         parsePlainPrivatePKCS8Hex: function(pkcs8PrvHex) {
      +993 	    var _ASN1HEX = ASN1HEX;
      +994 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      +995 	    var _getV = _ASN1HEX.getV;
      +996             var result = {};
      +997             result.algparam = null;
      +998 
      +999             // 1. sequence
      +1000             if (pkcs8PrvHex.substr(0, 2) != "30")
      +1001                 throw new Error("malformed plain PKCS8 private key(code:001)");
      +1002 	        // not sequence
       1003 
      -1004     // 3.1.2. JWK RSA private key with p/q/dp/dq/coeff by b64u values
      -1005     if (param.kty === "RSA" &&
      -1006 	param.n !== undefined &&
      -1007 	param.e !== undefined &&
      -1008 	param.d !== undefined &&
      -1009 	param.p !== undefined &&
      -1010 	param.q !== undefined &&
      -1011 	param.dp !== undefined &&
      -1012 	param.dq !== undefined &&
      -1013 	param.qi !== undefined) {
      -1014 	var key = new _RSAKey();
      -1015         key.setPrivateEx(b64utohex(param.n),
      -1016 			 b64utohex(param.e),
      -1017 			 b64utohex(param.d),
      -1018 			 b64utohex(param.p),
      -1019 			 b64utohex(param.q),
      -1020                          b64utohex(param.dp),
      -1021 			 b64utohex(param.dq),
      -1022 			 b64utohex(param.qi));
      -1023 	return key;
      -1024     }
      +1004             var a1 = _getChildIdx(pkcs8PrvHex, 0);
      +1005             if (a1.length < 3)
      +1006                 throw new Error("malformed plain PKCS8 private key(code:002)");
      +1007                 // less elements
      +1008 
      +1009             // 2. AlgID
      +1010             if (pkcs8PrvHex.substr(a1[1], 2) != "30")
      +1011                 throw new Error("malformed PKCS8 private key(code:003)");
      +1012                 // AlgId not sequence
      +1013 
      +1014             var a2 = _getChildIdx(pkcs8PrvHex, a1[1]);
      +1015             if (a2.length != 2)
      +1016                 throw new Error("malformed PKCS8 private key(code:004)");
      +1017                 // AlgId not have two elements
      +1018 
      +1019             // 2.1. AlgID OID
      +1020             if (pkcs8PrvHex.substr(a2[0], 2) != "06")
      +1021                 throw new Error("malformed PKCS8 private key(code:005)");
      +1022                 // AlgId.oid is not OID
      +1023 
      +1024             result.algoid = _getV(pkcs8PrvHex, a2[0]);
       1025 
      -1026     // 3.1.3. JWK RSA private key without p/q/dp/dq/coeff by b64u
      -1027     //        since jsrsasign 5.0.0 keyutil 1.0.11
      -1028     if (param.kty === "RSA" &&
      -1029 	param.n !== undefined &&
      -1030 	param.e !== undefined &&
      -1031 	param.d !== undefined) {
      -1032 	var key = new _RSAKey();
      -1033         key.setPrivate(b64utohex(param.n),
      -1034 		       b64utohex(param.e),
      -1035 		       b64utohex(param.d));
      -1036 	return key;
      -1037     }
      -1038 
      -1039     // 3.2. JWK ECC
      -1040     // 3.2.1. JWK ECC public key by b64u values
      -1041     if (param.kty === "EC" &&
      -1042 	param.crv !== undefined &&
      -1043 	param.x !== undefined &&
      -1044 	param.y !== undefined &&
      -1045         param.d === undefined) {
      -1046 	var ec = new _KJUR_crypto_ECDSA({"curve": param.crv});
      -1047 	var charlen = ec.ecparams.keycharlen;
      -1048         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
      -1049         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
      -1050         var hPub = "04" + hX + hY;
      -1051 	ec.setPublicKeyHex(hPub);
      -1052 	return ec;
      -1053     }
      -1054 
      -1055     // 3.2.2. JWK ECC private key by b64u values
      -1056     if (param.kty === "EC" &&
      -1057 	param.crv !== undefined &&
      -1058 	param.x !== undefined &&
      -1059 	param.y !== undefined &&
      -1060         param.d !== undefined) {
      -1061 	var ec = new _KJUR_crypto_ECDSA({"curve": param.crv});
      -1062 	var charlen = ec.ecparams.keycharlen;
      -1063         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
      -1064         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
      -1065         var hPub = "04" + hX + hY;
      -1066         var hPrv = ("0000000000" + b64utohex(param.d)).slice(- charlen);
      -1067 	ec.setPublicKeyHex(hPub);
      -1068 	ec.setPrivateKeyHex(hPrv);
      -1069 	return ec;
      -1070     }
      -1071     
      -1072     // 4. (plain) hexadecimal data
      -1073     // 4.1. get private key by PKCS#5 plain RSA/DSA/ECDSA hexadecimal string
      -1074     if (hextype === "pkcs5prv") {
      -1075 	var h = param, _ASN1HEX = ASN1HEX, a, key;
      -1076 	a = _getChildIdx(h, 0);
      -1077 	if (a.length === 9) {        // RSA (INT x 9)
      -1078 	    key = new _RSAKey();
      -1079             key.readPKCS5PrvKeyHex(h);
      -1080 	} else if (a.length === 6) { // DSA (INT x 6)
      -1081 	    key = new _KJUR_crypto_DSA();
      -1082 	    key.readPKCS5PrvKeyHex(h);
      -1083 	} else if (a.length > 2 &&   // ECDSA (INT, OCT prv, [0] curve, [1] pub)
      -1084 		   h.substr(a[1], 2) === "04") {
      -1085 	    key = new _KJUR_crypto_ECDSA();
      -1086 	    key.readPKCS5PrvKeyHex(h);
      -1087 	} else {
      -1088 	    throw new Error("unsupported PKCS#1/5 hexadecimal key");
      -1089 	}
      -1090 
      -1091         return key;
      -1092     }
      -1093 
      -1094     // 4.2. get private key by PKCS#8 plain RSA/DSA/ECDSA hexadecimal string
      -1095     if (hextype === "pkcs8prv") {
      -1096 	var key = _KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(param);
      -1097         return key;
      -1098     }
      -1099 
      -1100     // 4.3. get public key by PKCS#8 RSA/DSA/ECDSA hexadecimal string
      -1101     if (hextype === "pkcs8pub") {
      -1102         return _KEYUTIL._getKeyFromPublicPKCS8Hex(param);
      -1103     }
      -1104 
      -1105     // 4.4. get public key by X.509 hexadecimal string for RSA/DSA/ECDSA
      -1106     if (hextype === "x509pub") {
      -1107         return X509.getPublicKeyFromCertHex(param);
      -1108     }
      -1109 
      -1110     // 5. by PEM certificate (-----BEGIN ... CERTIFICATE----)
      -1111     if (param.indexOf("-END CERTIFICATE-", 0) != -1 ||
      -1112         param.indexOf("-END X509 CERTIFICATE-", 0) != -1 ||
      -1113         param.indexOf("-END TRUSTED CERTIFICATE-", 0) != -1) {
      -1114         return X509.getPublicKeyFromCertPEM(param);
      -1115     }
      -1116 
      -1117     // 6. public key by PKCS#8 PEM string
      -1118     if (param.indexOf("-END PUBLIC KEY-") != -1) {
      -1119         var pubKeyHex = pemtohex(param, "PUBLIC KEY");
      -1120         return _KEYUTIL._getKeyFromPublicPKCS8Hex(pubKeyHex);
      -1121     }
      -1122     
      -1123     // 8.1 private key by plain PKCS#5 PEM RSA string 
      -1124     //    getKey("-----BEGIN RSA PRIVATE KEY-...")
      -1125     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
      -1126         param.indexOf("4,ENCRYPTED") == -1) {
      -1127         var hex = _pemtohex(param, "RSA PRIVATE KEY");
      -1128         return _KEYUTIL.getKey(hex, null, "pkcs5prv");
      -1129     }
      -1130 
      -1131     // 8.2. private key by plain PKCS#5 PEM DSA string
      -1132     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
      -1133         param.indexOf("4,ENCRYPTED") == -1) {
      -1134 
      -1135         var hKey = _pemtohex(param, "DSA PRIVATE KEY");
      -1136         var p = _getVbyList(hKey, 0, [1], "02");
      -1137         var q = _getVbyList(hKey, 0, [2], "02");
      -1138         var g = _getVbyList(hKey, 0, [3], "02");
      -1139         var y = _getVbyList(hKey, 0, [4], "02");
      -1140         var x = _getVbyList(hKey, 0, [5], "02");
      -1141         var key = new _KJUR_crypto_DSA();
      -1142         key.setPrivate(new BigInteger(p, 16),
      -1143                        new BigInteger(q, 16),
      -1144                        new BigInteger(g, 16),
      -1145                        new BigInteger(y, 16),
      -1146                        new BigInteger(x, 16));
      -1147         return key;
      -1148     }
      +1026             // 2.2. AlgID param
      +1027             if (pkcs8PrvHex.substr(a2[1], 2) == "06") {
      +1028                 result.algparam = _getV(pkcs8PrvHex, a2[1]);
      +1029             }
      +1030 
      +1031             // 3. Key index
      +1032             if (pkcs8PrvHex.substr(a1[2], 2) != "04")
      +1033                 throw new Error("malformed PKCS8 private key(code:006)");
      +1034                 // not octet string
      +1035 
      +1036             result.keyidx = _ASN1HEX.getVidx(pkcs8PrvHex, a1[2]);
      +1037 
      +1038             return result;
      +1039         },
      +1040 
      +1041         /**
      +1042          * get RSAKey/ECDSA private key object from PEM plain PEM PKCS#8 private key
      +1043          * @name getKeyFromPlainPrivatePKCS8PEM
      +1044          * @memberOf KEYUTIL
      +1045          * @function
      +1046          * @param {String} pkcs8PEM string of plain PEM formatted PKCS#8 private key
      +1047          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
      +1048          * @since pkcs5pkey 1.0.5
      +1049          */
      +1050         getKeyFromPlainPrivatePKCS8PEM: function(prvKeyPEM) {
      +1051             var prvKeyHex = pemtohex(prvKeyPEM, "PRIVATE KEY");
      +1052             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
      +1053             return key;
      +1054         },
      +1055 
      +1056         /**
      +1057          * get RSAKey/DSA/ECDSA private key object from HEX plain PEM PKCS#8 private key
      +1058          * @name getKeyFromPlainPrivatePKCS8Hex
      +1059          * @memberOf KEYUTIL
      +1060          * @function
      +1061          * @param {String} prvKeyHex hexadecimal string of plain PKCS#8 private key
      +1062          * @return {Object} RSAKey or KJUR.crypto.{DSA,ECDSA} private key object
      +1063          * @since pkcs5pkey 1.0.5
      +1064          */
      +1065         getKeyFromPlainPrivatePKCS8Hex: function(prvKeyHex) {
      +1066             var p8 = this.parsePlainPrivatePKCS8Hex(prvKeyHex);
      +1067 	    var key;
      +1068             
      +1069             if (p8.algoid == "2a864886f70d010101") { // RSA
      +1070 		key = new RSAKey();
      +1071 	    } else if (p8.algoid == "2a8648ce380401") { // DSA
      +1072 		key = new KJUR.crypto.DSA();
      +1073             } else if (p8.algoid == "2a8648ce3d0201") { // ECC
      +1074                 key = new KJUR.crypto.ECDSA();
      +1075             } else {
      +1076                 throw new Error("unsupported private key algorithm");
      +1077             }
      +1078 
      +1079 	    key.readPKCS8PrvKeyHex(prvKeyHex);
      +1080 	    return key;
      +1081         },
      +1082 
      +1083         // === PKCS8 RSA Public Key ================================================
      +1084 
      +1085         /*
      +1086          * get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#8 public key
      +1087          * @name _getKeyFromPublicPKCS8Hex
      +1088          * @memberOf KEYUTIL
      +1089          * @function
      +1090          * @param {String} pkcsPub8Hex hexadecimal string of PKCS#8 public key
      +1091          * @return {Object} RSAKey or KJUR.crypto.{ECDSA,DSA} private key object
      +1092          * @since pkcs5pkey 1.0.5
      +1093          */
      +1094         _getKeyFromPublicPKCS8Hex: function(h) {
      +1095 	    var key;
      +1096 	    var hOID = ASN1HEX.getVbyList(h, 0, [0, 0], "06");
      +1097 
      +1098 	    if (hOID === "2a864886f70d010101") {    // oid=RSA
      +1099 		key = new RSAKey();
      +1100 	    } else if (hOID === "2a8648ce380401") { // oid=DSA
      +1101 		key = new KJUR.crypto.DSA();
      +1102 	    } else if (hOID === "2a8648ce3d0201") { // oid=ECPUB
      +1103 		key = new KJUR.crypto.ECDSA();
      +1104 	    } else {
      +1105 		throw new Error("unsupported PKCS#8 public key hex");
      +1106 	    }
      +1107 	    key.readPKCS8PubKeyHex(h);
      +1108 	    return key;
      +1109 	},
      +1110 
      +1111         /**
      +1112          * parse hexadecimal string of plain PKCS#8 private key
      +1113          * @name parsePublicRawRSAKeyHex
      +1114          * @memberOf KEYUTIL
      +1115          * @function
      +1116          * @param {String} pubRawRSAHex hexadecimal string of ASN.1 encoded PKCS#8 public key
      +1117          * @return {Array} associative array of parsed key
      +1118          * @since pkcs5pkey 1.0.5
      +1119          * @description
      +1120          * Resulted associative array has following properties:
      +1121          * <ul>
      +1122          * <li>n - hexadecimal string of public key
      +1123          * <li>e - hexadecimal string of public exponent
      +1124          * </ul>
      +1125          */
      +1126         parsePublicRawRSAKeyHex: function(pubRawRSAHex) {
      +1127 	    var _ASN1HEX = ASN1HEX;
      +1128 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      +1129 	    var _getV = _ASN1HEX.getV;
      +1130             var result = {};
      +1131             
      +1132             // 1. Sequence
      +1133             if (pubRawRSAHex.substr(0, 2) != "30")
      +1134                 throw new Error("malformed RSA key(code:001)"); // not sequence
      +1135             
      +1136             var a1 = _getChildIdx(pubRawRSAHex, 0);
      +1137             if (a1.length != 2)
      +1138                 throw new Error("malformed RSA key(code:002)"); // not 2 items in seq
      +1139 
      +1140             // 2. public key "N"
      +1141             if (pubRawRSAHex.substr(a1[0], 2) != "02")
      +1142                 throw new Error("malformed RSA key(code:003)"); // 1st item is not integer
      +1143 
      +1144             result.n = _getV(pubRawRSAHex, a1[0]);
      +1145 
      +1146             // 3. public key "E"
      +1147             if (pubRawRSAHex.substr(a1[1], 2) != "02")
      +1148                 throw new Error("malformed RSA key(code:004)"); // 2nd item is not integer
       1149 
      -1150     // 8.3. private key by plain PKCS#5 PEM EC string
      -1151     if (param.indexOf("-END EC PRIVATE KEY-") != -1 &&
      -1152         param.indexOf("4,ENCRYPTED") == -1) {
      -1153         var hex = _pemtohex(param, "EC PRIVATE KEY");
      -1154         return _KEYUTIL.getKey(hex, null, "pkcs5prv");
      -1155     }
      -1156 
      -1157     // 10. private key by plain PKCS#8 PEM ECC/RSA string
      -1158     if (param.indexOf("-END PRIVATE KEY-") != -1) {
      -1159         return _KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(param);
      -1160     }
      -1161 
      -1162     // 11.1 private key by encrypted PKCS#5 PEM RSA string
      -1163     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
      -1164         param.indexOf("4,ENCRYPTED") != -1) {
      -1165         var hPKey = _KEYUTIL.getDecryptedKeyHex(param, passcode);
      -1166         var rsaKey = new RSAKey();
      -1167         rsaKey.readPKCS5PrvKeyHex(hPKey);
      -1168         return rsaKey;
      -1169     }
      -1170 
      -1171     // 11.2. private key by encrypted PKCS#5 PEM ECDSA string
      -1172     if (param.indexOf("-END EC PRIVATE KEY-") != -1 &&
      -1173         param.indexOf("4,ENCRYPTED") != -1) {
      -1174         var hKey = _KEYUTIL.getDecryptedKeyHex(param, passcode);
      -1175 
      -1176         var key = _getVbyList(hKey, 0, [1], "04");
      -1177         var curveNameOidHex = _getVbyList(hKey, 0, [2,0], "06");
      -1178         var pubkey = _getVbyList(hKey, 0, [3,0], "03").substr(2);
      -1179         var curveName = "";
      -1180 
      -1181         if (KJUR.crypto.OID.oidhex2name[curveNameOidHex] !== undefined) {
      -1182             curveName = KJUR.crypto.OID.oidhex2name[curveNameOidHex];
      -1183         } else {
      -1184             throw new Error("undefined OID(hex) in KJUR.crypto.OID: " + 
      -1185 			    curveNameOidHex);
      -1186         }
      -1187 
      -1188         var ec = new _KJUR_crypto_ECDSA({'curve': curveName});
      -1189         ec.setPublicKeyHex(pubkey);
      -1190         ec.setPrivateKeyHex(key);
      -1191         ec.isPublic = false;
      -1192         return ec;
      -1193     }
      +1150             result.e = _getV(pubRawRSAHex, a1[1]);
      +1151 
      +1152             return result;
      +1153         },
      +1154 
      +1155         /**
      +1156          * parse hexadecimal string of PKCS#8 RSA/EC/DSA public key
      +1157          * @name parsePublicPKCS8Hex
      +1158          * @memberOf KEYUTIL
      +1159          * @function
      +1160          * @param {String} pkcs8PubHex hexadecimal string of PKCS#8 public key
      +1161          * @return {Hash} hash of key information
      +1162          * @description
      +1163          * Resulted hash has following attributes.
      +1164          * <ul>
      +1165          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
      +1166          * <li>algparam - hexadecimal string of OID of ECC curve name, parameter SEQUENCE of DSA or null</li>
      +1167          * <li>key - hexadecimal string of public key</li>
      +1168          * </ul>
      +1169          */
      +1170         parsePublicPKCS8Hex: function(pkcs8PubHex) {
      +1171 	    var _ASN1HEX = ASN1HEX;
      +1172 	    var _getChildIdx = _ASN1HEX.getChildIdx;
      +1173 	    var _getV = _ASN1HEX.getV;
      +1174             var result = {};
      +1175             result.algparam = null;
      +1176 
      +1177             // 1. AlgID and Key bit string
      +1178             var a1 = _getChildIdx(pkcs8PubHex, 0);
      +1179             if (a1.length != 2)
      +1180                 throw new Error("outer DERSequence shall have 2 elements: " + a1.length);
      +1181 
      +1182             // 2. AlgID
      +1183             var idxAlgIdTLV = a1[0];
      +1184             if (pkcs8PubHex.substr(idxAlgIdTLV, 2) != "30")
      +1185                 throw new Error("malformed PKCS8 public key(code:001)"); // AlgId not sequence
      +1186 
      +1187             var a2 = _getChildIdx(pkcs8PubHex, idxAlgIdTLV);
      +1188             if (a2.length != 2)
      +1189                 throw new Error("malformed PKCS8 public key(code:002)"); // AlgId not have two elements
      +1190 
      +1191             // 2.1. AlgID OID
      +1192             if (pkcs8PubHex.substr(a2[0], 2) != "06")
      +1193                 throw new Error("malformed PKCS8 public key(code:003)"); // AlgId.oid is not OID
       1194 
      -1195     // 11.3. private key by encrypted PKCS#5 PEM DSA string
      -1196     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
      -1197         param.indexOf("4,ENCRYPTED") != -1) {
      -1198         var hKey = _KEYUTIL.getDecryptedKeyHex(param, passcode);
      -1199         var p = _getVbyList(hKey, 0, [1], "02");
      -1200         var q = _getVbyList(hKey, 0, [2], "02");
      -1201         var g = _getVbyList(hKey, 0, [3], "02");
      -1202         var y = _getVbyList(hKey, 0, [4], "02");
      -1203         var x = _getVbyList(hKey, 0, [5], "02");
      -1204         var key = new _KJUR_crypto_DSA();
      -1205         key.setPrivate(new BigInteger(p, 16),
      -1206                        new BigInteger(q, 16),
      -1207                        new BigInteger(g, 16),
      -1208                        new BigInteger(y, 16),
      -1209                        new BigInteger(x, 16));
      -1210         return key;
      -1211     }
      -1212 
      -1213     // 11. private key by encrypted PKCS#8 hexadecimal RSA/ECDSA string
      -1214     if (param.indexOf("-END ENCRYPTED PRIVATE KEY-") != -1) {
      -1215         return _KEYUTIL.getKeyFromEncryptedPKCS8PEM(param, passcode);
      -1216     }
      -1217 
      -1218     throw new Error("not supported argument");
      -1219 };
      -1220 
      -1221 /**
      -1222  * @name generateKeypair
      +1195             result.algoid = _getV(pkcs8PubHex, a2[0]);
      +1196 
      +1197             // 2.2. AlgID param
      +1198             if (pkcs8PubHex.substr(a2[1], 2) == "06") { // OID for EC
      +1199                 result.algparam = _getV(pkcs8PubHex, a2[1]);
      +1200             } else if (pkcs8PubHex.substr(a2[1], 2) == "30") { // SEQ for DSA
      +1201                 result.algparam = {};
      +1202                 result.algparam.p = _ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [0], "02");
      +1203                 result.algparam.q = _ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [1], "02");
      +1204                 result.algparam.g = _ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [2], "02");
      +1205             }
      +1206 
      +1207             // 3. Key
      +1208             if (pkcs8PubHex.substr(a1[1], 2) != "03")
      +1209                 throw new Error("malformed PKCS8 public key(code:004)"); // Key is not bit string
      +1210 
      +1211             result.key = _getV(pkcs8PubHex, a1[1]).substr(2);
      +1212             
      +1213             // 4. return result assoc array
      +1214             return result;
      +1215         },
      +1216     };
      +1217 }();
      +1218 
      +1219 // -- MAJOR PUBLIC METHODS ----------------------------------------------------
      +1220 /**
      +1221  * get private or public key object from any arguments
      +1222  * @name getKey
       1223  * @memberOf KEYUTIL
       1224  * @function
       1225  * @static
      -1226  * @param {String} alg 'RSA' or 'EC'
      -1227  * @param {Object} keylenOrCurve key length for RSA or curve name for EC
      -1228  * @return {Array} associative array of keypair which has prvKeyObj and pubKeyObj parameters
      -1229  * @since keyutil 1.0.1
      -1230  * @description
      -1231  * This method generates a key pair of public key algorithm.
      -1232  * The result will be an associative array which has following
      -1233  * parameters:
      -1234  * <ul>
      -1235  * <li>prvKeyObj - RSAKey or ECDSA object of private key</li>
      -1236  * <li>pubKeyObj - RSAKey or ECDSA object of public key</li>
      -1237  * </ul>
      -1238  * NOTE1: As for RSA algoirthm, public exponent has fixed
      -1239  * value '0x10001'.
      -1240  * NOTE2: As for EC algorithm, supported names of curve are
      -1241  * secp256r1, secp256k1, secp384r1 and secp521r1.
      -1242  * NOTE3: DSA is not supported yet.
      -1243  * @example
      -1244  * var rsaKeypair = KEYUTIL.generateKeypair("RSA", 1024);
      -1245  * var ecKeypair = KEYUTIL.generateKeypair("EC", "secp256r1");
      -1246  *
      -1247  */
      -1248 KEYUTIL.generateKeypair = function(alg, keylenOrCurve) {
      -1249     if (alg == "RSA") {
      -1250         var keylen = keylenOrCurve;
      -1251         var prvKey = new RSAKey();
      -1252         prvKey.generate(keylen, '10001');
      -1253         prvKey.isPrivate = true;
      -1254         prvKey.isPublic = true;
      -1255         
      -1256         var pubKey = new RSAKey();
      -1257         var hN = prvKey.n.toString(16);
      -1258         var hE = prvKey.e.toString(16);
      -1259         pubKey.setPublic(hN, hE);
      -1260         pubKey.isPrivate = false;
      -1261         pubKey.isPublic = true;
      -1262         
      -1263         var result = {};
      -1264         result.prvKeyObj = prvKey;
      -1265         result.pubKeyObj = pubKey;
      -1266         return result;
      -1267     } else if (alg == "EC") {
      -1268         var curve = keylenOrCurve;
      -1269         var ec = new KJUR.crypto.ECDSA({curve: curve});
      -1270         var keypairHex = ec.generateKeyPairHex();
      -1271 
      -1272         var prvKey = new KJUR.crypto.ECDSA({curve: curve});
      -1273         prvKey.setPublicKeyHex(keypairHex.ecpubhex);
      -1274         prvKey.setPrivateKeyHex(keypairHex.ecprvhex);
      -1275         prvKey.isPrivate = true;
      -1276         prvKey.isPublic = false;
      -1277 
      -1278         var pubKey = new KJUR.crypto.ECDSA({curve: curve});
      -1279         pubKey.setPublicKeyHex(keypairHex.ecpubhex);
      -1280         pubKey.isPrivate = false;
      -1281         pubKey.isPublic = true;
      -1282 
      -1283         var result = {};
      -1284         result.prvKeyObj = prvKey;
      -1285         result.pubKeyObj = pubKey;
      -1286         return result;
      -1287     } else {
      -1288         throw new Error("unknown algorithm: " + alg);
      -1289     }
      -1290 };
      -1291 
      -1292 /**
      -1293  * get PEM formatted private or public key file from a RSA/ECDSA/DSA key object
      -1294  * @name getPEM
      -1295  * @memberOf KEYUTIL
      -1296  * @function
      -1297  * @static
      -1298  * @param {Object} keyObjOrHex key object {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} to encode to
      -1299  * @param {String} formatType (OPTION) output format type of "PKCS1PRV", "PKCS5PRV" or "PKCS8PRV" for private key
      -1300  * @param {String} passwd (OPTION) password to protect private key
      -1301  * @param {String} encAlg (OPTION) encryption algorithm for PKCS#5. currently supports DES-CBC, DES-EDE3-CBC and AES-{128,192,256}-CBC
      -1302  * @param {String} hexType (OPTION) type of hex string (ex. pkcs5prv, pkcs8prv)
      -1303  * @param {String} ivsaltHex hexadecimal string of IV and salt (default generated random IV)
      -1304  * @since keyutil 1.0.4
      -1305  * @description
      -1306  * <dl>
      -1307  * <dt><b>NOTE1:</b>
      -1308  * <dd>
      -1309  * PKCS#5 encrypted private key protection algorithm supports DES-CBC, 
      -1310  * DES-EDE3-CBC and AES-{128,192,256}-CBC
      -1311  * <dt><b>NOTE2:</b>
      -1312  * <dd>
      -1313  * OpenSSL supports
      -1314  * <dt><b>NOTE3:</b>
      -1315  * <dd>
      -1316  * Parameter "ivsaltHex" supported since jsrsasign 8.0.0 keyutil 1.2.0.
      -1317  * </dl>
      -1318  * @example
      -1319  * KEUUTIL.getPEM(publicKey) → generates PEM PKCS#8 public key 
      -1320  * KEUUTIL.getPEM(privateKey) → generates PEM PKCS#8 plain private key by default
      -1321  * KEUUTIL.getPEM(privateKey, "PKCS1PRV") → generates PEM PKCS#1 plain private key
      -1322  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass") → generates PEM PKCS#5 encrypted private key 
      -1323  *                                                          with DES-EDE3-CBC (DEFAULT)
      -1324  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass", "DES-CBC") → generates PEM PKCS#5 encrypted 
      -1325  *                                                                 private key with DES-CBC
      -1326  * KEUUTIL.getPEM(privateKey, "PKCS8PRV") → generates PEM PKCS#8 plain private key
      -1327  * KEUUTIL.getPEM(privateKey, "PKCS8PRV", "pass") → generates PEM PKCS#8 encrypted private key
      -1328  *                                                      with PBKDF2_HmacSHA1_3DES
      -1329  */
      -1330 KEYUTIL.getPEM = function(keyObjOrHex, formatType, passwd, encAlg, hexType, ivsaltHex) {
      -1331     var _KJUR = KJUR,
      -1332 	_KJUR_asn1 = _KJUR.asn1,
      -1333 	_DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier,
      -1334 	_DERInteger = _KJUR_asn1.DERInteger,
      -1335 	_newObject = _KJUR_asn1.ASN1Util.newObject,
      -1336 	_KJUR_asn1_x509 = _KJUR_asn1.x509,
      -1337 	_SubjectPublicKeyInfo = _KJUR_asn1_x509.SubjectPublicKeyInfo,
      -1338 	_KJUR_crypto = _KJUR.crypto,
      -1339 	_DSA = _KJUR_crypto.DSA,
      -1340 	_ECDSA = _KJUR_crypto.ECDSA,
      -1341 	_RSAKey = RSAKey;
      -1342 
      -1343     function _rsaprv2asn1obj(keyObjOrHex) {
      -1344         var asn1Obj = _newObject({
      -1345             "seq": [
      -1346                 {"int": 0 },
      -1347                 {"int": {"bigint": keyObjOrHex.n}},
      -1348                 {"int": keyObjOrHex.e},
      -1349                 {"int": {"bigint": keyObjOrHex.d}},
      -1350                 {"int": {"bigint": keyObjOrHex.p}},
      -1351                 {"int": {"bigint": keyObjOrHex.q}},
      -1352                 {"int": {"bigint": keyObjOrHex.dmp1}},
      -1353                 {"int": {"bigint": keyObjOrHex.dmq1}},
      -1354                 {"int": {"bigint": keyObjOrHex.coeff}}
      -1355             ]
      -1356         });
      -1357         return asn1Obj;
      -1358     };
      -1359 
      -1360     function _ecdsaprv2asn1obj(keyObjOrHex) {
      -1361         var asn1Obj2 = _newObject({
      -1362             "seq": [
      -1363                 {"int": 1 },
      -1364                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}},
      -1365                 {"tag": ['a0', true, {'oid': {'name': keyObjOrHex.curveName}}]},
      -1366                 {"tag": ['a1', true, {'bitstr': {'hex': '00' + keyObjOrHex.pubKeyHex}}]}
      -1367             ]
      -1368         });
      -1369         return asn1Obj2;
      -1370     };
      -1371 
      -1372     function _dsaprv2asn1obj(keyObjOrHex) {
      -1373         var asn1Obj = _newObject({
      -1374             "seq": [
      -1375                 {"int": 0 },
      -1376                 {"int": {"bigint": keyObjOrHex.p}},
      -1377                 {"int": {"bigint": keyObjOrHex.q}},
      -1378                 {"int": {"bigint": keyObjOrHex.g}},
      -1379                 {"int": {"bigint": keyObjOrHex.y}},
      -1380                 {"int": {"bigint": keyObjOrHex.x}}
      -1381             ]
      -1382         });
      -1383         return asn1Obj;
      -1384     };
      -1385 
      -1386     // 1. public key
      -1387 
      -1388     // x. PEM PKCS#8 public key of RSA/ECDSA/DSA public key object
      -1389     if (((_RSAKey !== undefined && keyObjOrHex instanceof _RSAKey) ||
      -1390          (_DSA !== undefined    && keyObjOrHex instanceof _DSA) ||
      -1391          (_ECDSA !== undefined  && keyObjOrHex instanceof _ECDSA)) &&
      -1392         keyObjOrHex.isPublic == true &&
      -1393         (formatType === undefined || formatType == "PKCS8PUB")) {
      -1394         var asn1Obj = new _SubjectPublicKeyInfo(keyObjOrHex);
      -1395         var asn1Hex = asn1Obj.tohex();
      -1396         return hextopem(asn1Hex, "PUBLIC KEY");
      -1397     }
      -1398     
      -1399     // 2. private
      -1400 
      -1401     // x. PEM PKCS#1 plain private key of RSA private key object
      -1402     if (formatType == "PKCS1PRV" &&
      -1403         _RSAKey !== undefined &&
      -1404         keyObjOrHex instanceof _RSAKey &&
      -1405         (passwd === undefined || passwd == null) &&
      -1406         keyObjOrHex.isPrivate  == true) {
      -1407 
      -1408         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
      -1409         var asn1Hex = asn1Obj.tohex();
      -1410         return hextopem(asn1Hex, "RSA PRIVATE KEY");
      -1411     }
      -1412 
      -1413     // x. PEM PKCS#1 plain private key of ECDSA private key object
      -1414     if (formatType == "PKCS1PRV" &&
      -1415         _ECDSA !== undefined &&
      -1416         keyObjOrHex instanceof _ECDSA &&
      -1417         (passwd === undefined || passwd == null) &&
      -1418         keyObjOrHex.isPrivate  == true) {
      -1419 
      -1420         var asn1Obj1 = 
      -1421 	    new _DERObjectIdentifier({'name': keyObjOrHex.curveName});
      -1422         var asn1Hex1 = asn1Obj1.tohex();
      -1423         var asn1Obj2 = _ecdsaprv2asn1obj(keyObjOrHex);
      -1424         var asn1Hex2 = asn1Obj2.tohex();
      -1425 
      -1426         var s = "";
      -1427         s += hextopem(asn1Hex1, "EC PARAMETERS");
      -1428         s += hextopem(asn1Hex2, "EC PRIVATE KEY");
      -1429         return s;
      -1430     }
      -1431 
      -1432     // x. PEM PKCS#1 plain private key of DSA private key object
      -1433     if (formatType == "PKCS1PRV" &&
      -1434         _DSA !== undefined &&
      -1435         keyObjOrHex instanceof _DSA &&
      -1436         (passwd === undefined || passwd == null) &&
      -1437         keyObjOrHex.isPrivate  == true) {
      -1438 
      -1439         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
      -1440         var asn1Hex = asn1Obj.tohex();
      -1441         return hextopem(asn1Hex, "DSA PRIVATE KEY");
      -1442     }
      -1443 
      -1444     // 3. private
      +1226  * @param {Object} param parameter to get key object. see description in detail.
      +1227  * @param {String} passcode (OPTION) parameter to get key object. see description in detail.
      +1228  * @param {String} hextype (OPTOIN) parameter to get key object. see description in detail.
      +1229  * @return {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.ECDSA} object
      +1230  * @since keyutil 1.0.0
      +1231  * @description
      +1232  * This method gets private or public key object({@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA})
      +1233  * for RSA, DSA and ECC.
      +1234  * Arguments for this methods depends on a key format you specify.
      +1235  * Following key representations are supported.
      +1236  * <ul>
      +1237  * <li>ECC private/public key object(as is): param=KJUR.crypto.ECDSA</li>
      +1238  * <li>DSA private/public key object(as is): param=KJUR.crypto.DSA</li>
      +1239  * <li>RSA private/public key object(as is): param=RSAKey </li>
      +1240  * <li>ECC private key parameters: param={d: d, curve: curveName}</li>
      +1241  * <li>RSA private key parameters: param={n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq, co: co}<br/>
      +1242  * NOTE: Each value shall be hexadecimal string of key spec.</li>
      +1243  * <li>DSA private key parameters: param={p: p, q: q, g: g, y: y, x: x}<br/>
      +1244  * NOTE: Each value shall be hexadecimal string of key spec.</li>
      +1245  * <li>ECC public key parameters: param={xy: xy, curve: curveName}<br/>
      +1246  * NOTE: ECC public key 'xy' shall be concatination of "04", x-bytes-hex and y-bytes-hex.</li>
      +1247  * <li>DSA public key parameters: param={p: p, q: q, g: g, y: y}<br/>
      +1248  * NOTE: Each value shall be hexadecimal string of key spec.</li>
      +1249  * <li>RSA public key parameters: param={n: n, e: e} </li>
      +1250  * <li>X.509v1/v3 PEM certificate (RSA/DSA/ECC): param=pemString</li>
      +1251  * <li>PKCS#8 hexadecimal RSA/ECC public key: param=pemString, null, "pkcs8pub"</li>
      +1252  * <li>PKCS#8 PEM RSA/DSA/ECC public key: param=pemString</li>
      +1253  * <li>PKCS#5 plain hexadecimal RSA private key: param=hexString, null, "pkcs5prv"</li>
      +1254  * <li>PKCS#5 plain PEM RSA/DSA/EC private key: param=pemString</li>
      +1255  * <li>PKCS#8 plain PEM RSA/EC private key: param=pemString</li>
      +1256  * <li>PKCS#5 encrypted PEM RSA/DSA/EC private key: param=pemString, passcode</li>
      +1257  * <li>PKCS#8 encrypted PEM RSA/EC private key: param=pemString, passcode</li>
      +1258  * </ul>
      +1259  * Please note following limitation on encrypted keys:
      +1260  * <ul>
      +1261  * <li>Encrypted PKCS#8 only supports PBKDF2/HmacSHA1/3DES</li>
      +1262  * <li>Encrypted PKCS#5 supports DES-CBC, DES-EDE3-CBC, AES-{128,192.256}-CBC</li>
      +1263  * <li>JWT plain ECC private/public key</li>
      +1264  * <li>JWT plain RSA public key</li>
      +1265  * <li>JWT plain RSA private key with P/Q/DP/DQ/COEFF</li>
      +1266  * <li>JWT plain RSA private key without P/Q/DP/DQ/COEFF (since jsrsasign 5.0.0)</li>
      +1267  * </ul>
      +1268  * NOTE1: <a href="https://tools.ietf.org/html/rfc7517">RFC 7517 JSON Web Key(JWK)</a> support for RSA/ECC private/public key from jsrsasign 4.8.1.<br/>
      +1269  * NOTE2: X509v1 support is added since jsrsasign 5.0.11.
      +1270  * 
      +1271  * <h5>EXAMPLE</h5>
      +1272  * @example
      +1273  * // 1. loading private key from PEM string
      +1274  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY...");
      +1275  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY..., "passcode");
      +1276  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
      +1277  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...", "passcode");
      +1278  * keyObj = KEYUTIL.getKey("-----BEGIN EC PARAMETERS...-----BEGIN EC PRIVATE KEY...");
      +1279  * // 2. loading public key from PEM string
      +1280  * keyObj = KEYUTIL.getKey("-----BEGIN PUBLIC KEY...");
      +1281  * keyObj = KEYUTIL.getKey("-----BEGIN X509 CERTIFICATE...");
      +1282  * // 3. loading hexadecimal PKCS#5/PKCS#8 key
      +1283  * keyObj = KEYUTIL.getKey("308205c1...", null, "pkcs8pub");
      +1284  * keyObj = KEYUTIL.getKey("3082048b...", null, "pkcs5prv");
      +1285  * // 4. loading JSON Web Key(JWK)
      +1286  * keyObj = KEYUTIL.getKey({kty: "RSA", n: "0vx7...", e: "AQAB"});
      +1287  * keyObj = KEYUTIL.getKey({kty: "EC", crv: "P-256", 
      +1288  *                          x: "MKBC...", y: "4Etl6...", d: "870Mb..."});
      +1289  * // 5. bare hexadecimal key
      +1290  * keyObj = KEYUTIL.getKey({n: "75ab..", e: "010001"});
      +1291  */
      +1292 KEYUTIL.getKey = function(param, passcode, hextype) {
      +1293     var _ASN1HEX = ASN1HEX,
      +1294 	_getChildIdx = _ASN1HEX.getChildIdx,
      +1295 	_getV = _ASN1HEX.getV,
      +1296 	_getVbyList = _ASN1HEX.getVbyList,
      +1297 	_KJUR_crypto = KJUR.crypto,
      +1298 	_KJUR_crypto_ECDSA = _KJUR_crypto.ECDSA,
      +1299 	_KJUR_crypto_DSA = _KJUR_crypto.DSA,
      +1300 	_RSAKey = RSAKey,
      +1301 	_pemtohex = pemtohex,
      +1302 	_KEYUTIL = KEYUTIL;
      +1303 
      +1304     // 1. by key RSAKey/KJUR.crypto.ECDSA/KJUR.crypto.DSA object
      +1305     if (typeof _RSAKey != 'undefined' && param instanceof _RSAKey)
      +1306         return param;
      +1307     if (typeof _KJUR_crypto_ECDSA != 'undefined' && param instanceof _KJUR_crypto_ECDSA)
      +1308         return param;
      +1309     if (typeof _KJUR_crypto_DSA != 'undefined' && param instanceof _KJUR_crypto_DSA)
      +1310         return param;
      +1311 
      +1312     // 2. by parameters of key
      +1313 
      +1314     // 2.1. bare ECC
      +1315     // 2.1.1. bare ECC public key by hex values
      +1316     if (param.curve !== undefined &&
      +1317 	param.xy !== undefined && param.d === undefined) {
      +1318         return new _KJUR_crypto_ECDSA({pub: param.xy, curve: param.curve});
      +1319     }
      +1320 
      +1321     // 2.1.2. bare ECC private key by hex values
      +1322     if (param.curve !== undefined && param.d !== undefined) {
      +1323         return new _KJUR_crypto_ECDSA({prv: param.d, curve: param.curve});
      +1324     }
      +1325 
      +1326     // 2.2. bare RSA
      +1327     // 2.2.1. bare RSA public key by hex values
      +1328     if (param.kty === undefined &&
      +1329 	param.n !== undefined && param.e !== undefined &&
      +1330         param.d === undefined) {
      +1331         var key = new _RSAKey();
      +1332         key.setPublic(param.n, param.e);
      +1333         return key;
      +1334     }
      +1335 
      +1336     // 2.2.2. bare RSA private key with P/Q/DP/DQ/COEFF by hex values
      +1337     if (param.kty === undefined &&
      +1338 	param.n !== undefined &&
      +1339 	param.e !== undefined &&
      +1340 	param.d !== undefined &&
      +1341         param.p !== undefined &&
      +1342 	param.q !== undefined &&
      +1343         param.dp !== undefined &&
      +1344 	param.dq !== undefined &&
      +1345 	param.co !== undefined &&
      +1346         param.qi === undefined) {
      +1347         var key = new _RSAKey();
      +1348         key.setPrivateEx(param.n, param.e, param.d, param.p, param.q,
      +1349                          param.dp, param.dq, param.co);
      +1350         return key;
      +1351     }
      +1352 
      +1353     // 2.2.3. bare RSA public key without P/Q/DP/DQ/COEFF by hex values
      +1354     if (param.kty === undefined &&
      +1355 	param.n !== undefined &&
      +1356 	param.e !== undefined &&
      +1357 	param.d !== undefined &&
      +1358         param.p === undefined) {
      +1359         var key = new _RSAKey();
      +1360         key.setPrivate(param.n, param.e, param.d);
      +1361         return key;
      +1362     }
      +1363 
      +1364     // 2.3. bare DSA
      +1365     // 2.3.1. bare DSA public key by hex values
      +1366     if (param.p !== undefined && param.q !== undefined &&
      +1367 	param.g !== undefined &&
      +1368         param.y !== undefined && param.x === undefined) {
      +1369         var key = new _KJUR_crypto_DSA();
      +1370         key.setPublic(param.p, param.q, param.g, param.y);
      +1371         return key;
      +1372     }
      +1373 
      +1374     // 2.3.2. bare DSA private key by hex values
      +1375     if (param.p !== undefined && param.q !== undefined &&
      +1376 	param.g !== undefined &&
      +1377         param.y !== undefined && param.x !== undefined) {
      +1378         var key = new _KJUR_crypto_DSA();
      +1379         key.setPrivate(param.p, param.q, param.g, param.y, param.x);
      +1380         return key;
      +1381     }
      +1382 
      +1383     // 3. JWK
      +1384     // 3.1. JWK RSA
      +1385     // 3.1.1. JWK RSA public key by b64u values
      +1386     if (param.kty === "RSA" &&
      +1387 	param.n !== undefined &&
      +1388 	param.e !== undefined &&
      +1389 	param.d === undefined) {
      +1390 	var key = new _RSAKey();
      +1391 	key.setPublic(b64utohex(param.n), b64utohex(param.e));
      +1392 	return key;
      +1393     }
      +1394 
      +1395     // 3.1.2. JWK RSA private key with p/q/dp/dq/coeff by b64u values
      +1396     if (param.kty === "RSA" &&
      +1397 	param.n !== undefined &&
      +1398 	param.e !== undefined &&
      +1399 	param.d !== undefined &&
      +1400 	param.p !== undefined &&
      +1401 	param.q !== undefined &&
      +1402 	param.dp !== undefined &&
      +1403 	param.dq !== undefined &&
      +1404 	param.qi !== undefined) {
      +1405 	var key = new _RSAKey();
      +1406         key.setPrivateEx(b64utohex(param.n),
      +1407 			 b64utohex(param.e),
      +1408 			 b64utohex(param.d),
      +1409 			 b64utohex(param.p),
      +1410 			 b64utohex(param.q),
      +1411                          b64utohex(param.dp),
      +1412 			 b64utohex(param.dq),
      +1413 			 b64utohex(param.qi));
      +1414 	return key;
      +1415     }
      +1416 
      +1417     // 3.1.3. JWK RSA private key without p/q/dp/dq/coeff by b64u
      +1418     //        since jsrsasign 5.0.0 keyutil 1.0.11
      +1419     if (param.kty === "RSA" &&
      +1420 	param.n !== undefined &&
      +1421 	param.e !== undefined &&
      +1422 	param.d !== undefined) {
      +1423 	var key = new _RSAKey();
      +1424         key.setPrivate(b64utohex(param.n),
      +1425 		       b64utohex(param.e),
      +1426 		       b64utohex(param.d));
      +1427 	return key;
      +1428     }
      +1429 
      +1430     // 3.2. JWK ECC
      +1431     // 3.2.1. JWK ECC public key by b64u values
      +1432     if (param.kty === "EC" &&
      +1433 	param.crv !== undefined &&
      +1434 	param.x !== undefined &&
      +1435 	param.y !== undefined &&
      +1436         param.d === undefined) {
      +1437 	var ec = new _KJUR_crypto_ECDSA({"curve": param.crv});
      +1438 	var charlen = ec.ecparams.keycharlen;
      +1439         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
      +1440         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
      +1441         var hPub = "04" + hX + hY;
      +1442 	ec.setPublicKeyHex(hPub);
      +1443 	return ec;
      +1444     }
       1445 
      -1446     // x. PEM PKCS#5 encrypted private key of RSA private key object
      -1447     if (formatType == "PKCS5PRV" &&
      -1448         _RSAKey !== undefined &&
      -1449         keyObjOrHex instanceof _RSAKey &&
      -1450         (passwd !== undefined && passwd != null) &&
      -1451         keyObjOrHex.isPrivate  == true) {
      -1452 
      -1453         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
      -1454         var asn1Hex = asn1Obj.tohex();
      -1455 
      -1456         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
      -1457         return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA", asn1Hex, passwd, encAlg, ivsaltHex);
      -1458     }
      -1459 
      -1460     // x. PEM PKCS#5 encrypted private key of ECDSA private key object
      -1461     if (formatType == "PKCS5PRV" &&
      -1462         _ECDSA !== undefined &&
      -1463         keyObjOrHex instanceof _ECDSA &&
      -1464         (passwd !== undefined && passwd != null) &&
      -1465         keyObjOrHex.isPrivate  == true) {
      -1466 
      -1467         var asn1Obj = _ecdsaprv2asn1obj(keyObjOrHex);
      -1468         var asn1Hex = asn1Obj.tohex();
      -1469 
      -1470         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
      -1471         return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC", asn1Hex, passwd, encAlg, ivsaltHex);
      -1472     }
      -1473 
      -1474     // x. PEM PKCS#5 encrypted private key of DSA private key object
      -1475     if (formatType == "PKCS5PRV" &&
      -1476         _DSA !== undefined &&
      -1477         keyObjOrHex instanceof _DSA &&
      -1478         (passwd !== undefined && passwd != null) &&
      -1479         keyObjOrHex.isPrivate  == true) {
      -1480 
      -1481         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
      -1482         var asn1Hex = asn1Obj.tohex();
      -1483 
      -1484         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
      -1485         return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA", asn1Hex, passwd, encAlg, ivsaltHex);
      -1486     }
      -1487 
      -1488     // x. ======================================================================
      -1489 
      -1490     var _getEncryptedPKCS8 = function(plainKeyHex, passcode) {
      -1491         var info = _getEencryptedPKCS8Info(plainKeyHex, passcode);
      -1492         //alert("iv=" + info.encryptionSchemeIV);
      -1493         //alert("info.ciphertext2[" + info.ciphertext.length + "=" + info.ciphertext);
      -1494         var asn1Obj = new _newObject({
      -1495             "seq": [
      -1496                 {"seq": [
      -1497                     {"oid": {"name": "pkcs5PBES2"}},
      -1498                     {"seq": [
      -1499                         {"seq": [
      -1500                             {"oid": {"name": "pkcs5PBKDF2"}},
      -1501                             {"seq": [
      -1502                                 {"octstr": {"hex": info.pbkdf2Salt}},
      -1503                                 {"int": info.pbkdf2Iter}
      -1504                             ]}
      -1505                         ]},
      -1506                         {"seq": [
      -1507                             {"oid": {"name": "des-EDE3-CBC"}},
      -1508                             {"octstr": {"hex": info.encryptionSchemeIV}}
      -1509                         ]}
      -1510                     ]}
      -1511                 ]},
      -1512                 {"octstr": {"hex": info.ciphertext}}
      -1513             ]
      -1514         });
      -1515         return asn1Obj.tohex();
      -1516     };
      -1517 
      -1518     var _getEencryptedPKCS8Info = function(plainKeyHex, passcode) {
      -1519         var pbkdf2Iter = 100;
      -1520         var pbkdf2SaltWS = CryptoJS.lib.WordArray.random(8);
      -1521         var encryptionSchemeAlg = "DES-EDE3-CBC";
      -1522         var encryptionSchemeIVWS = CryptoJS.lib.WordArray.random(8);
      -1523         // PBKDF2 key
      -1524         var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
      -1525                                           pbkdf2SaltWS, { "keySize": 192/32,
      -1526                                                           "iterations": pbkdf2Iter });
      -1527         // ENCRYPT
      -1528         var plainKeyWS = CryptoJS.enc.Hex.parse(plainKeyHex);
      -1529         var encryptedKeyHex = 
      -1530             CryptoJS.TripleDES.encrypt(plainKeyWS, pbkdf2KeyWS, { "iv": encryptionSchemeIVWS }) + "";
      -1531 
      -1532         //alert("encryptedKeyHex=" + encryptedKeyHex);
      -1533 
      -1534         var info = {};
      -1535         info.ciphertext = encryptedKeyHex;
      -1536         //alert("info.ciphertext=" + info.ciphertext);
      -1537         info.pbkdf2Salt = CryptoJS.enc.Hex.stringify(pbkdf2SaltWS);
      -1538         info.pbkdf2Iter = pbkdf2Iter;
      -1539         info.encryptionSchemeAlg = encryptionSchemeAlg;
      -1540         info.encryptionSchemeIV = CryptoJS.enc.Hex.stringify(encryptionSchemeIVWS);
      -1541         return info;
      -1542     };
      -1543 
      -1544     // x. PEM PKCS#8 plain private key of RSA private key object
      -1545     if (formatType == "PKCS8PRV" &&
      -1546         _RSAKey != undefined &&
      -1547         keyObjOrHex instanceof _RSAKey &&
      -1548         keyObjOrHex.isPrivate  == true) {
      -1549 
      -1550         var keyObj = _rsaprv2asn1obj(keyObjOrHex);
      -1551         var keyHex = keyObj.tohex();
      +1446     // 3.2.2. JWK ECC private key by b64u values
      +1447     if (param.kty === "EC" &&
      +1448 	param.crv !== undefined &&
      +1449 	param.x !== undefined &&
      +1450 	param.y !== undefined &&
      +1451         param.d !== undefined) {
      +1452 	var ec = new _KJUR_crypto_ECDSA({"curve": param.crv});
      +1453 	var charlen = ec.ecparams.keycharlen;
      +1454         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
      +1455         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
      +1456         var hPub = "04" + hX + hY;
      +1457         var hPrv = ("0000000000" + b64utohex(param.d)).slice(- charlen);
      +1458 	ec.setPublicKeyHex(hPub);
      +1459 	ec.setPrivateKeyHex(hPrv);
      +1460 	return ec;
      +1461     }
      +1462     
      +1463     // 4. (plain) hexadecimal data
      +1464     // 4.1. get private key by PKCS#5 plain RSA/DSA/ECDSA hexadecimal string
      +1465     if (hextype === "pkcs5prv") {
      +1466 	var h = param, _ASN1HEX = ASN1HEX, a, key;
      +1467 	a = _getChildIdx(h, 0);
      +1468 	if (a.length === 9) {        // RSA (INT x 9)
      +1469 	    key = new _RSAKey();
      +1470             key.readPKCS5PrvKeyHex(h);
      +1471 	} else if (a.length === 6) { // DSA (INT x 6)
      +1472 	    key = new _KJUR_crypto_DSA();
      +1473 	    key.readPKCS5PrvKeyHex(h);
      +1474 	} else if (a.length > 2 &&   // ECDSA (INT, OCT prv, [0] curve, [1] pub)
      +1475 		   h.substr(a[1], 2) === "04") {
      +1476 	    key = new _KJUR_crypto_ECDSA();
      +1477 	    key.readPKCS5PrvKeyHex(h);
      +1478 	} else {
      +1479 	    throw new Error("unsupported PKCS#1/5 hexadecimal key");
      +1480 	}
      +1481 
      +1482         return key;
      +1483     }
      +1484 
      +1485     // 4.2. get private key by PKCS#8 plain RSA/DSA/ECDSA hexadecimal string
      +1486     if (hextype === "pkcs8prv") {
      +1487 	var key = _KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(param);
      +1488         return key;
      +1489     }
      +1490 
      +1491     // 4.3. get public key by PKCS#8 RSA/DSA/ECDSA hexadecimal string
      +1492     if (hextype === "pkcs8pub") {
      +1493         return _KEYUTIL._getKeyFromPublicPKCS8Hex(param);
      +1494     }
      +1495 
      +1496     // 4.4. get public key by X.509 hexadecimal string for RSA/DSA/ECDSA
      +1497     if (hextype === "x509pub") {
      +1498         return X509.getPublicKeyFromCertHex(param);
      +1499     }
      +1500 
      +1501     // 5. by PEM certificate (-----BEGIN ... CERTIFICATE----)
      +1502     if (param.indexOf("-END CERTIFICATE-", 0) != -1 ||
      +1503         param.indexOf("-END X509 CERTIFICATE-", 0) != -1 ||
      +1504         param.indexOf("-END TRUSTED CERTIFICATE-", 0) != -1) {
      +1505         return X509.getPublicKeyFromCertPEM(param);
      +1506     }
      +1507 
      +1508     // 6. public key by PKCS#8 PEM string
      +1509     if (param.indexOf("-END PUBLIC KEY-") != -1) {
      +1510         var pubKeyHex = pemtohex(param, "PUBLIC KEY");
      +1511         return _KEYUTIL._getKeyFromPublicPKCS8Hex(pubKeyHex);
      +1512     }
      +1513     
      +1514     // 8.1 private key by plain PKCS#5 PEM RSA string 
      +1515     //    getKey("-----BEGIN RSA PRIVATE KEY-...")
      +1516     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
      +1517         param.indexOf("4,ENCRYPTED") == -1) {
      +1518         var hex = _pemtohex(param, "RSA PRIVATE KEY");
      +1519         return _KEYUTIL.getKey(hex, null, "pkcs5prv");
      +1520     }
      +1521 
      +1522     // 8.2. private key by plain PKCS#5 PEM DSA string
      +1523     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
      +1524         param.indexOf("4,ENCRYPTED") == -1) {
      +1525 
      +1526         var hKey = _pemtohex(param, "DSA PRIVATE KEY");
      +1527         var p = _getVbyList(hKey, 0, [1], "02");
      +1528         var q = _getVbyList(hKey, 0, [2], "02");
      +1529         var g = _getVbyList(hKey, 0, [3], "02");
      +1530         var y = _getVbyList(hKey, 0, [4], "02");
      +1531         var x = _getVbyList(hKey, 0, [5], "02");
      +1532         var key = new _KJUR_crypto_DSA();
      +1533         key.setPrivate(new BigInteger(p, 16),
      +1534                        new BigInteger(q, 16),
      +1535                        new BigInteger(g, 16),
      +1536                        new BigInteger(y, 16),
      +1537                        new BigInteger(x, 16));
      +1538         return key;
      +1539     }
      +1540 
      +1541     // 8.3. private key by plain PKCS#5 PEM EC string
      +1542     if (param.indexOf("-END EC PRIVATE KEY-") != -1 &&
      +1543         param.indexOf("4,ENCRYPTED") == -1) {
      +1544         var hex = _pemtohex(param, "EC PRIVATE KEY");
      +1545         return _KEYUTIL.getKey(hex, null, "pkcs5prv");
      +1546     }
      +1547 
      +1548     // 10. private key by plain PKCS#8 PEM ECC/RSA string
      +1549     if (param.indexOf("-END PRIVATE KEY-") != -1) {
      +1550         return _KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(param);
      +1551     }
       1552 
      -1553         var asn1Obj = _newObject({
      -1554             "seq": [
      -1555                 {"int": 0},
      -1556                 {"seq": [{"oid": {"name": "rsaEncryption"}},{"null": true}]},
      -1557                 {"octstr": {"hex": keyHex}}
      -1558             ]
      -1559         });
      -1560         var asn1Hex = asn1Obj.tohex();
      +1553     // 11.1 private key by encrypted PKCS#5 PEM RSA string
      +1554     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
      +1555         param.indexOf("4,ENCRYPTED") != -1) {
      +1556         var hPKey = _KEYUTIL.getDecryptedKeyHex(param, passcode);
      +1557         var rsaKey = new RSAKey();
      +1558         rsaKey.readPKCS5PrvKeyHex(hPKey);
      +1559         return rsaKey;
      +1560     }
       1561 
      -1562         if (passwd === undefined || passwd == null) {
      -1563             return hextopem(asn1Hex, "PRIVATE KEY");
      -1564         } else {
      -1565             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
      -1566             return hextopem(asn1Hex2, "ENCRYPTED PRIVATE KEY");
      -1567         }
      -1568     }
      -1569 
      -1570     // x. PEM PKCS#8 plain private key of ECDSA private key object
      -1571     if (formatType == "PKCS8PRV" &&
      -1572         _ECDSA !== undefined &&
      -1573         keyObjOrHex instanceof _ECDSA &&
      -1574         keyObjOrHex.isPrivate  == true) {
      -1575 
      -1576 	var pKeyObj = {
      -1577             "seq": [
      -1578                 {"int": 1},
      -1579                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}}
      -1580             ]
      -1581         };
      -1582 	if (typeof keyObjOrHex.pubKeyHex == "string") {
      -1583 	    pKeyObj.seq.push({"tag": ['a1', true, {"bitstr": {"hex": "00" + keyObjOrHex.pubKeyHex}}]});
      -1584 	}
      -1585         var keyObj = new _newObject(pKeyObj);
      -1586         var keyHex = keyObj.tohex();
      -1587 
      -1588         var asn1Obj = _newObject({
      -1589             "seq": [
      -1590                 {"int": 0},
      -1591                 {"seq": [
      -1592                     {"oid": {"name": "ecPublicKey"}},
      -1593                     {"oid": {"name": keyObjOrHex.curveName}}
      -1594                 ]},
      -1595                 {"octstr": {"hex": keyHex}}
      -1596             ]
      -1597         });
      -1598 
      -1599         var asn1Hex = asn1Obj.tohex();
      -1600         if (passwd === undefined || passwd == null) {
      -1601             return hextopem(asn1Hex, "PRIVATE KEY");
      -1602         } else {
      -1603             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
      -1604             return hextopem(asn1Hex2, "ENCRYPTED PRIVATE KEY");
      -1605         }
      -1606     }
      -1607 
      -1608     // x. PEM PKCS#8 plain private key of DSA private key object
      -1609     if (formatType == "PKCS8PRV" &&
      -1610         _DSA !== undefined &&
      -1611         keyObjOrHex instanceof _DSA &&
      -1612         keyObjOrHex.isPrivate  == true) {
      -1613 
      -1614         var keyObj = new _DERInteger({'bigint': keyObjOrHex.x});
      -1615         var keyHex = keyObj.tohex();
      -1616 
      -1617         var asn1Obj = _newObject({
      -1618             "seq": [
      -1619                 {"int": 0},
      -1620                 {"seq": [
      -1621                     {"oid": {"name": "dsa"}},
      -1622                     {"seq": [
      -1623                         {"int": {"bigint": keyObjOrHex.p}},
      -1624                         {"int": {"bigint": keyObjOrHex.q}},
      -1625                         {"int": {"bigint": keyObjOrHex.g}}
      -1626                     ]}
      -1627                 ]},
      -1628                 {"octstr": {"hex": keyHex}}
      -1629             ]
      -1630         });
      -1631 
      -1632         var asn1Hex = asn1Obj.tohex();
      -1633         if (passwd === undefined || passwd == null) {
      -1634             return hextopem(asn1Hex, "PRIVATE KEY");
      -1635         } else {
      -1636             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
      -1637             return hextopem(asn1Hex2, "ENCRYPTED PRIVATE KEY");
      -1638         }
      -1639     }
      -1640 
      -1641     throw new Error("unsupported object nor format");
      -1642 };
      -1643 
      -1644 // -- PUBLIC METHODS FOR CSR --------------------------------------------------
      -1645 
      -1646 /**
      -1647  * get RSAKey/DSA/ECDSA public key object from PEM formatted PKCS#10 CSR string
      -1648  * @name getKeyFromCSRPEM
      -1649  * @memberOf KEYUTIL
      -1650  * @function
      -1651  * @param {String} csrPEM PEM formatted PKCS#10 CSR string
      -1652  * @return {Object} RSAKey/DSA/ECDSA public key object
      -1653  * @since keyutil 1.0.5
      -1654  */
      -1655 KEYUTIL.getKeyFromCSRPEM = function(csrPEM) {
      -1656     var csrHex = pemtohex(csrPEM, "CERTIFICATE REQUEST");
      -1657     var key = KEYUTIL.getKeyFromCSRHex(csrHex);
      -1658     return key;
      -1659 };
      -1660 
      -1661 /**
      -1662  * get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#10 CSR
      -1663  * @name getKeyFromCSRHex
      -1664  * @memberOf KEYUTIL
      -1665  * @function
      -1666  * @param {String} csrHex hexadecimal string of PKCS#10 CSR
      -1667  * @return {Object} RSAKey/DSA/ECDSA public key object
      -1668  * @since keyutil 1.0.5
      -1669  */
      -1670 KEYUTIL.getKeyFromCSRHex = function(csrHex) {
      -1671     var info = KEYUTIL.parseCSRHex(csrHex);
      -1672     var key = KEYUTIL.getKey(info.p8pubkeyhex, null, "pkcs8pub");
      -1673     return key;
      -1674 };
      -1675 
      -1676 /**
      -1677  * parse hexadecimal string of PKCS#10 CSR (certificate signing request)
      -1678  * @name parseCSRHex
      -1679  * @memberOf KEYUTIL
      -1680  * @function
      -1681  * @param {String} csrHex hexadecimal string of PKCS#10 CSR
      -1682  * @return {Array} associative array of parsed CSR
      -1683  * @since keyutil 1.0.5
      -1684  * @description
      -1685  * Resulted associative array has following properties:
      -1686  * <ul>
      -1687  * <li>p8pubkeyhex - hexadecimal string of subject public key in PKCS#8</li>
      -1688  * </ul>
      -1689  */
      -1690 KEYUTIL.parseCSRHex = function(csrHex) {
      -1691     var _ASN1HEX = ASN1HEX;
      -1692     var _getChildIdx = _ASN1HEX.getChildIdx;
      -1693     var _getTLV = _ASN1HEX.getTLV;
      -1694     var result = {};
      -1695     var h = csrHex;
      -1696 
      -1697     // 1. sequence
      -1698     if (h.substr(0, 2) != "30")
      -1699         throw new Error("malformed CSR(code:001)"); // not sequence
      -1700 
      -1701     var a1 = _getChildIdx(h, 0);
      -1702     if (a1.length < 1)
      -1703         throw new Error("malformed CSR(code:002)"); // short length
      -1704 
      -1705     // 2. 2nd sequence
      -1706     if (h.substr(a1[0], 2) != "30")
      -1707         throw new Error("malformed CSR(code:003)"); // not sequence
      -1708 
      -1709     var a2 = _getChildIdx(h, a1[0]);
      -1710     if (a2.length < 3)
      -1711         throw new Error("malformed CSR(code:004)"); // 2nd seq short elem
      -1712 
      -1713     result.p8pubkeyhex = _getTLV(h, a2[2]);
      -1714 
      -1715     return result;
      -1716 };
      -1717 
      -1718 // -- OTHER STATIC PUBLIC METHODS  --------------------------------------------
      -1719 
      -1720 /**
      -1721  * get key ID by public key object for subject or authority key identifier
      -1722  * @name getKeyID
      -1723  * @memberof KEYUTIL
      -1724  * @function
      -1725  * @static
      -1726  * @param {Object} obj RSAKey/KJUR.crypto.ECDSA,DSA public key object or public key PEM string
      -1727  * @return hexadecimal string of public key identifier
      -1728  * @since keyutil 1.2.2 jsrsasign 5.0.16
      -1729  * @description
      -1730  * This static method generates a key identifier from a public key
      -1731  * by the method described in 
      -1732  * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2"
      -1733  * target="_blank">RFC 5280 4.2.1.2. Subject Key Identifier (1)</a>.
      -1734  * @example
      -1735  * pubkeyobj = KEYUTIL.getKey(...);
      -1736  * KEYTUTIL.getKey(pubkeyobj) → "a612..."
      -1737  */
      -1738 KEYUTIL.getKeyID = function(obj) {
      -1739     var _KEYUTIL = KEYUTIL;
      -1740     var _ASN1HEX = ASN1HEX;
      -1741 
      -1742     if (typeof obj  === "string" && obj.indexOf("BEGIN ") != -1) {
      -1743 	obj = _KEYUTIL.getKey(obj);
      -1744     }
      -1745 
      -1746     var p8hex = pemtohex(_KEYUTIL.getPEM(obj));
      -1747     var idx = _ASN1HEX.getIdxbyList(p8hex, 0, [1]); // BITSTRING
      -1748     var hV = _ASN1HEX.getV(p8hex, idx).substring(2); // value without unused bit
      -1749     return KJUR.crypto.Util.hashHex(hV, "sha1");
      -1750 }
      -1751 
      -1752 /**
      -1753  * convert from certificate, public/private key object to RFC 7517 JSON Web Key(JWK)<br/>
      -1754  * @name getJWK
      -1755  * @memberOf KEYUTIL
      -1756  * @function
      -1757  * @static
      -1758  * @param {Object or string} keyinfo public/private key object, PEM key or PEM certificate
      -1759  * @param {boolean} nokid set true if you don't need kid (OPTION, DEFAULT=undefined)
      -1760  * @param {boolean} nox5c set true if you don't need x5c of certificate (OPTION, DEFAULT=undefined)
      -1761  * @param {boolean} nox5t set true if you don't need x5t of certificate (OPTION, DEFAULT=undefined)
      -1762  * @param {boolean} nox5t2 set true if you don't need x5c#S256 of certificate (OPTION, DEFAULT=undefined)
      -1763  * @return {Object} JWK object
      -1764  * @since keyutil 1.2.5 jsrsasign 10.5.1
      -1765  * @see RSAKey
      -1766  * @see KJUR.crypto.ECDSA
      -1767  * @see KJUR.crypto.DSA
      -1768  *
      -1769  * @description
      -1770  * This static method provides 
      -1771  * <a href="https://datatracker.ietf.org/doc/html/rfc7517">
      -1772  * RFC 7517 JSON Web Key(JWK) JSON</a>
      -1773  * object from following argument types:
      -1774  * <ul>
      -1775  * <li>
      -1776  * <b>JWK private key</b>
      -1777  * <ul>
      -1778  * <li>RSAKey or KJUR.crypto.{ECDSA,DSA} private key object</li>
      -1779  * <li>PKCS#5 or PKCS#8 plain PEM private key</li>
      -1780  * </ul>
      -1781  * </li>
      -1782  * <li>
      -1783  * <b>JWK public key</b>
      -1784  * <ul>
      -1785  * <li>RSAKey or KJUR.crypto.{ECDSA,DSA} public key object</li>
      -1786  * <li>PKCS#5 or PKCS#8 PEM public key</li>
      -1787  * <li>X509 certificate object</li>
      -1788  * <li>PEM certificate</li>
      -1789  * </ul>
      -1790  * </li>
      -1791  * </ul>
      -1792  * 
      -1793  * @example
      -1794  * kp1 = KEYUTIL.generateKeypair("EC", "P-256");
      -1795  * jwkPrv1 = KEYUTIL.getJWK(kp1.prvKeyObj);
      -1796  * jwkPub1 = KEYUTIL.getJWK(kp1.pubKeyObj);
      -1797  *
      -1798  * kp2 = KEYUTIL.generateKeypair("RSA", 2048);
      -1799  * jwkPrv2 = KEYUTIL.getJWK(kp2.prvKeyObj);
      -1800  * jwkPub2 = KEYUTIL.getJWK(kp2.pubKeyObj);
      -1801  *
      -1802  * // from PEM certificate
      -1803  * KEYUTIL.getJWK("-----BEGIN CERTIFICATE...") →
      -1804  * {
      -1805  *   kty: "EC", crv: "P-521", x: "...", y: "...",
      -1806  *   x5c: ["MI..."],
      -1807  *   x5t: "...",
      -1808  *   "x5t#S256": "...",
      -1809  *   kid: "..."
      -1810  * }
      -1811  *
      -1812  * // from X509 object
      -1813  * x509obj = new X509("-----BEGIN CERTIFICATE...");
      -1814  * KEYUTIL.getJWK(x509obj) →
      -1815  * {
      -1816  *   kty: "EC", crv: "P-521", x: "...", y: "...",
      -1817  *   ...
      -1818  * }
      -1819  *
      -1820  * // from PEM certificate without kid, x5t and x5t#S256 (i.e. only x5c)
      -1821  * KEYUTIL.getJWK("-----BEGIN CERTIFICATE...", true, false, true, true) →
      -1822  * {
      -1823  *   kty: "EC", crv: "P-521", x: "...", y: "...",
      -1824  *   x5c: ["MI..."]
      -1825  * }
      -1826  */
      -1827 KEYUTIL.getJWK = function(keyinfo, nokid, nox5c, nox5t, nox5t2) {
      -1828     var keyObj;
      -1829     var jwk = {};
      -1830     var hCert;
      -1831     var _hashHex = KJUR.crypto.Util.hashHex;
      -1832 
      -1833     if (typeof keyinfo == "string") {
      -1834 	keyObj = KEYUTIL.getKey(keyinfo);
      -1835 	if (keyinfo.indexOf("CERTIFICATE") != -1) {
      -1836 	    hCert = pemtohex(keyinfo)
      -1837 	}
      -1838     } else if (typeof keyinfo == "object") {
      -1839 	if (keyinfo instanceof X509) {
      -1840 	    keyObj = keyinfo.getPublicKey();
      -1841 	    hCert = keyinfo.hex;
      -1842 	} else {
      -1843 	    keyObj = keyinfo;
      -1844 	}
      -1845     } else {
      -1846 	throw new Error("unsupported keyinfo type");
      -1847     }
      +1562     // 11.2. private key by encrypted PKCS#5 PEM ECDSA string
      +1563     if (param.indexOf("-END EC PRIVATE KEY-") != -1 &&
      +1564         param.indexOf("4,ENCRYPTED") != -1) {
      +1565         var hKey = _KEYUTIL.getDecryptedKeyHex(param, passcode);
      +1566 
      +1567         var key = _getVbyList(hKey, 0, [1], "04");
      +1568         var curveNameOidHex = _getVbyList(hKey, 0, [2,0], "06");
      +1569         var pubkey = _getVbyList(hKey, 0, [3,0], "03").substr(2);
      +1570         var curveName = "";
      +1571 
      +1572         if (KJUR.crypto.OID.oidhex2name[curveNameOidHex] !== undefined) {
      +1573             curveName = KJUR.crypto.OID.oidhex2name[curveNameOidHex];
      +1574         } else {
      +1575             throw new Error("undefined OID(hex) in KJUR.crypto.OID: " + 
      +1576 			    curveNameOidHex);
      +1577         }
      +1578 
      +1579         var ec = new _KJUR_crypto_ECDSA({'curve': curveName});
      +1580         ec.setPublicKeyHex(pubkey);
      +1581         ec.setPrivateKeyHex(key);
      +1582         ec.isPublic = false;
      +1583         return ec;
      +1584     }
      +1585 
      +1586     // 11.3. private key by encrypted PKCS#5 PEM DSA string
      +1587     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
      +1588         param.indexOf("4,ENCRYPTED") != -1) {
      +1589         var hKey = _KEYUTIL.getDecryptedKeyHex(param, passcode);
      +1590         var p = _getVbyList(hKey, 0, [1], "02");
      +1591         var q = _getVbyList(hKey, 0, [2], "02");
      +1592         var g = _getVbyList(hKey, 0, [3], "02");
      +1593         var y = _getVbyList(hKey, 0, [4], "02");
      +1594         var x = _getVbyList(hKey, 0, [5], "02");
      +1595         var key = new _KJUR_crypto_DSA();
      +1596         key.setPrivate(new BigInteger(p, 16),
      +1597                        new BigInteger(q, 16),
      +1598                        new BigInteger(g, 16),
      +1599                        new BigInteger(y, 16),
      +1600                        new BigInteger(x, 16));
      +1601         return key;
      +1602     }
      +1603 
      +1604     // 11. private key by encrypted PKCS#8 hexadecimal RSA/ECDSA string
      +1605     if (param.indexOf("-END ENCRYPTED PRIVATE KEY-") != -1) {
      +1606         return _KEYUTIL.getKeyFromEncryptedPKCS8PEM(param, passcode);
      +1607     }
      +1608 
      +1609     throw new Error("not supported argument");
      +1610 };
      +1611 
      +1612 /**
      +1613  * @name generateKeypair
      +1614  * @memberOf KEYUTIL
      +1615  * @function
      +1616  * @static
      +1617  * @param {String} alg 'RSA' or 'EC'
      +1618  * @param {Object} keylenOrCurve key length for RSA or curve name for EC
      +1619  * @return {Array} associative array of keypair which has prvKeyObj and pubKeyObj parameters
      +1620  * @since keyutil 1.0.1
      +1621  * @description
      +1622  * This method generates a key pair of public key algorithm.
      +1623  * The result will be an associative array which has following
      +1624  * parameters:
      +1625  * <ul>
      +1626  * <li>prvKeyObj - RSAKey or ECDSA object of private key</li>
      +1627  * <li>pubKeyObj - RSAKey or ECDSA object of public key</li>
      +1628  * </ul>
      +1629  * NOTE1: As for RSA algoirthm, public exponent has fixed
      +1630  * value '0x10001'.
      +1631  * NOTE2: As for EC algorithm, supported names of curve are
      +1632  * secp256r1, secp256k1, secp384r1 and secp521r1.
      +1633  * NOTE3: DSA is not supported yet.
      +1634  * @example
      +1635  * var rsaKeypair = KEYUTIL.generateKeypair("RSA", 1024);
      +1636  * var ecKeypair = KEYUTIL.generateKeypair("EC", "secp256r1");
      +1637  *
      +1638  */
      +1639 KEYUTIL.generateKeypair = function(alg, keylenOrCurve) {
      +1640     if (alg == "RSA") {
      +1641         var keylen = keylenOrCurve;
      +1642         var prvKey = new RSAKey();
      +1643         prvKey.generate(keylen, '10001');
      +1644         prvKey.isPrivate = true;
      +1645         prvKey.isPublic = true;
      +1646         
      +1647         var pubKey = new RSAKey();
      +1648         var hN = prvKey.n.toString(16);
      +1649         var hE = prvKey.e.toString(16);
      +1650         pubKey.setPublic(hN, hE);
      +1651         pubKey.isPrivate = false;
      +1652         pubKey.isPublic = true;
      +1653         
      +1654         var result = {};
      +1655         result.prvKeyObj = prvKey;
      +1656         result.pubKeyObj = pubKey;
      +1657         return result;
      +1658     } else if (alg == "EC") {
      +1659         var curve = keylenOrCurve;
      +1660         var ec = new KJUR.crypto.ECDSA({curve: curve});
      +1661         var keypairHex = ec.generateKeyPairHex();
      +1662 
      +1663         var prvKey = new KJUR.crypto.ECDSA({curve: curve});
      +1664         prvKey.setPublicKeyHex(keypairHex.ecpubhex);
      +1665         prvKey.setPrivateKeyHex(keypairHex.ecprvhex);
      +1666         prvKey.isPrivate = true;
      +1667         prvKey.isPublic = false;
      +1668 
      +1669         var pubKey = new KJUR.crypto.ECDSA({curve: curve});
      +1670         pubKey.setPublicKeyHex(keypairHex.ecpubhex);
      +1671         pubKey.isPrivate = false;
      +1672         pubKey.isPublic = true;
      +1673 
      +1674         var result = {};
      +1675         result.prvKeyObj = prvKey;
      +1676         result.pubKeyObj = pubKey;
      +1677         return result;
      +1678     } else {
      +1679         throw new Error("unknown algorithm: " + alg);
      +1680     }
      +1681 };
      +1682 
      +1683 /**
      +1684  * get PEM formatted private or public key file from a RSA/ECDSA/DSA key object
      +1685  * @name getPEM
      +1686  * @memberOf KEYUTIL
      +1687  * @function
      +1688  * @static
      +1689  * @param {Object} keyObjOrHex key object {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} to encode to
      +1690  * @param {String} formatType (OPTION) output format type of "PKCS1PRV", "PKCS5PRV" or "PKCS8PRV" for private key
      +1691  * @param {String} passwd (OPTION) password to protect private key
      +1692  * @param {String} encAlg (OPTION) encryption algorithm for PKCS#5. currently supports DES-CBC, DES-EDE3-CBC and AES-{128,192,256}-CBC
      +1693  * @param {String} hexType (OPTION) type of hex string (ex. pkcs5prv, pkcs8prv)
      +1694  * @param {String} ivsaltHex hexadecimal string of IV and salt (default generated random IV)
      +1695  * @since keyutil 1.0.4
      +1696  *
      +1697  * @description
      +1698  * <dl>
      +1699  * <dt><b>NOTE1:</b>
      +1700  * <dd>
      +1701  * PKCS#5 encrypted private key protection algorithm supports DES-CBC, 
      +1702  * DES-EDE3-CBC and AES-{128,192,256}-CBC
      +1703  * <dt><b>NOTE2:</b>
      +1704  * <dd>
      +1705  * OpenSSL supports
      +1706  * <dt><b>NOTE3:</b>
      +1707  * <dd>
      +1708  * Parameter "ivsaltHex" supported since jsrsasign 8.0.0 keyutil 1.2.0.
      +1709  * </dl>
      +1710  *
      +1711  * @example
      +1712  * KEUUTIL.getPEM(publicKey) → generates PEM PKCS#8 public key 
      +1713  * KEUUTIL.getPEM(privateKey) → generates PEM PKCS#8 plain private key by default
      +1714  * KEUUTIL.getPEM(privateKey, "PKCS1PRV") → generates PEM PKCS#1 plain private key
      +1715  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass") → generates PEM PKCS#5 encrypted private key 
      +1716  *                                                          with DES-EDE3-CBC (DEFAULT)
      +1717  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass", "DES-CBC") → generates PEM PKCS#5 encrypted 
      +1718  *                                                                 private key with DES-CBC
      +1719  * KEUUTIL.getPEM(privateKey, "PKCS8PRV") → generates PEM PKCS#8 plain private key
      +1720  * KEUUTIL.getPEM(privateKey, "PKCS8PRV", "pass") → generates PEM PKCS#8 encrypted private key
      +1721  *                                                      with PBKDF2_HmacSHA1_3DES
      +1722  */
      +1723 KEYUTIL.getPEM = function(keyObjOrHex, formatType, passwd, encAlg, hexType, ivsaltHex) {
      +1724     var _KJUR = KJUR,
      +1725 	_KJUR_asn1 = _KJUR.asn1,
      +1726 	_DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier,
      +1727 	_DERInteger = _KJUR_asn1.DERInteger,
      +1728 	_newObject = _KJUR_asn1.ASN1Util.newObject,
      +1729 	_KJUR_asn1_x509 = _KJUR_asn1.x509,
      +1730 	_SubjectPublicKeyInfo = _KJUR_asn1_x509.SubjectPublicKeyInfo,
      +1731 	_KJUR_crypto = _KJUR.crypto,
      +1732 	_DSA = _KJUR_crypto.DSA,
      +1733 	_ECDSA = _KJUR_crypto.ECDSA,
      +1734 	_RSAKey = RSAKey;
      +1735 
      +1736     function _rsaprv2asn1obj(keyObjOrHex) {
      +1737         var asn1Obj = _newObject({
      +1738             "seq": [
      +1739                 {"int": 0 },
      +1740                 {"int": {"bigint": keyObjOrHex.n}},
      +1741                 {"int": keyObjOrHex.e},
      +1742                 {"int": {"bigint": keyObjOrHex.d}},
      +1743                 {"int": {"bigint": keyObjOrHex.p}},
      +1744                 {"int": {"bigint": keyObjOrHex.q}},
      +1745                 {"int": {"bigint": keyObjOrHex.dmp1}},
      +1746                 {"int": {"bigint": keyObjOrHex.dmq1}},
      +1747                 {"int": {"bigint": keyObjOrHex.coeff}}
      +1748             ]
      +1749         });
      +1750         return asn1Obj;
      +1751     };
      +1752 
      +1753     function _ecdsaprv2asn1obj(keyObjOrHex) {
      +1754         var asn1Obj2 = _newObject({
      +1755             "seq": [
      +1756                 {"int": 1 },
      +1757                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}},
      +1758                 {"tag": ['a0', true, {'oid': {'name': keyObjOrHex.curveName}}]},
      +1759                 {"tag": ['a1', true, {'bitstr': {'hex': '00' + keyObjOrHex.pubKeyHex}}]}
      +1760             ]
      +1761         });
      +1762         return asn1Obj2;
      +1763     };
      +1764 
      +1765     function _dsaprv2asn1obj(keyObjOrHex) {
      +1766         var asn1Obj = _newObject({
      +1767             "seq": [
      +1768                 {"int": 0 },
      +1769                 {"int": {"bigint": keyObjOrHex.p}},
      +1770                 {"int": {"bigint": keyObjOrHex.q}},
      +1771                 {"int": {"bigint": keyObjOrHex.g}},
      +1772                 {"int": {"bigint": keyObjOrHex.y}},
      +1773                 {"int": {"bigint": keyObjOrHex.x}}
      +1774             ]
      +1775         });
      +1776         return asn1Obj;
      +1777     };
      +1778 
      +1779     // 1. public key
      +1780 
      +1781     // x. PEM PKCS#8 public key of RSA/ECDSA/DSA public key object
      +1782     if (((_RSAKey !== undefined && keyObjOrHex instanceof _RSAKey) ||
      +1783          (_DSA !== undefined    && keyObjOrHex instanceof _DSA) ||
      +1784          (_ECDSA !== undefined  && keyObjOrHex instanceof _ECDSA)) &&
      +1785         keyObjOrHex.isPublic == true &&
      +1786         (formatType === undefined || formatType == "PKCS8PUB")) {
      +1787         var asn1Obj = new _SubjectPublicKeyInfo(keyObjOrHex);
      +1788         var asn1Hex = asn1Obj.tohex();
      +1789         return hextopem(asn1Hex, "PUBLIC KEY");
      +1790     }
      +1791     
      +1792     // 2. private
      +1793 
      +1794     // x. PEM PKCS#1 plain private key of RSA private key object
      +1795     if (formatType == "PKCS1PRV" &&
      +1796         _RSAKey !== undefined &&
      +1797         keyObjOrHex instanceof _RSAKey &&
      +1798         (passwd === undefined || passwd == null) &&
      +1799         keyObjOrHex.isPrivate  == true) {
      +1800 
      +1801         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
      +1802         var asn1Hex = asn1Obj.tohex();
      +1803         return hextopem(asn1Hex, "RSA PRIVATE KEY");
      +1804     }
      +1805 
      +1806     // x. PEM PKCS#1 plain private key of ECDSA private key object
      +1807     if (formatType == "PKCS1PRV" &&
      +1808         _ECDSA !== undefined &&
      +1809         keyObjOrHex instanceof _ECDSA &&
      +1810         (passwd === undefined || passwd == null) &&
      +1811         keyObjOrHex.isPrivate  == true) {
      +1812 
      +1813         var asn1Obj1 = 
      +1814 	    new _DERObjectIdentifier({'name': keyObjOrHex.curveName});
      +1815         var asn1Hex1 = asn1Obj1.tohex();
      +1816         var asn1Obj2 = _ecdsaprv2asn1obj(keyObjOrHex);
      +1817         var asn1Hex2 = asn1Obj2.tohex();
      +1818 
      +1819         var s = "";
      +1820         s += hextopem(asn1Hex1, "EC PARAMETERS");
      +1821         s += hextopem(asn1Hex2, "EC PRIVATE KEY");
      +1822         return s;
      +1823     }
      +1824 
      +1825     // x. PEM PKCS#1 plain private key of DSA private key object
      +1826     if (formatType == "PKCS1PRV" &&
      +1827         _DSA !== undefined &&
      +1828         keyObjOrHex instanceof _DSA &&
      +1829         (passwd === undefined || passwd == null) &&
      +1830         keyObjOrHex.isPrivate  == true) {
      +1831 
      +1832         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
      +1833         var asn1Hex = asn1Obj.tohex();
      +1834         return hextopem(asn1Hex, "DSA PRIVATE KEY");
      +1835     }
      +1836 
      +1837     // 3. private
      +1838 
      +1839     // x. PEM PKCS#5 encrypted private key of RSA private key object
      +1840     if (formatType == "PKCS5PRV" &&
      +1841         _RSAKey !== undefined &&
      +1842         keyObjOrHex instanceof _RSAKey &&
      +1843         (passwd !== undefined && passwd != null) &&
      +1844         keyObjOrHex.isPrivate  == true) {
      +1845 
      +1846         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
      +1847         var asn1Hex = asn1Obj.tohex();
       1848 
      -1849     if (keyObj instanceof RSAKey && keyObj.isPrivate) {
      -1850 	jwk.kty = "RSA";
      -1851 	jwk.n = hextob64u(keyObj.n.toString(16));
      -1852 	jwk.e = hextob64u(keyObj.e.toString(16));
      -1853 	jwk.d = hextob64u(keyObj.d.toString(16));
      -1854 	jwk.p = hextob64u(keyObj.p.toString(16));
      -1855 	jwk.q = hextob64u(keyObj.q.toString(16));
      -1856 	jwk.dp = hextob64u(keyObj.dmp1.toString(16));
      -1857 	jwk.dq = hextob64u(keyObj.dmq1.toString(16));
      -1858 	jwk.qi = hextob64u(keyObj.coeff.toString(16));
      -1859     } else if (keyObj instanceof RSAKey && keyObj.isPublic) {
      -1860 	jwk.kty = "RSA";
      -1861 	jwk.n = hextob64u(keyObj.n.toString(16));
      -1862 	jwk.e = hextob64u(keyObj.e.toString(16));
      -1863     } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPrivate) {
      -1864 	var name = keyObj.getShortNISTPCurveName();
      -1865 	if (name !== "P-256" && name !== "P-384" && name !== "P-521")
      -1866 	    throw new Error("unsupported curve name for JWT: " + name);
      -1867 	var xy = keyObj.getPublicKeyXYHex();
      -1868 	jwk.kty = "EC";
      -1869 	jwk.crv =  name;
      -1870 	jwk.x = hextob64u(xy.x);
      -1871 	jwk.y = hextob64u(xy.y);
      -1872 	jwk.d = hextob64u(keyObj.prvKeyHex);
      -1873     } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPublic) {
      -1874 	var name = keyObj.getShortNISTPCurveName();
      -1875 	if (name !== "P-256" && name !== "P-384" && name !== "P-521")
      -1876 	    throw new Error("unsupported curve name for JWT: " + name);
      -1877 	var xy = keyObj.getPublicKeyXYHex();
      -1878 	jwk.kty = "EC";
      -1879 	jwk.crv =  name;
      -1880 	jwk.x = hextob64u(xy.x);
      -1881 	jwk.y = hextob64u(xy.y);
      -1882     }
      -1883     if (jwk.kty == undefined) throw new Error("unsupported keyinfo");
      -1884 
      -1885     if ((! keyObj.isPrivate) && nokid != true) {
      -1886 	jwk.kid = KJUR.jws.JWS.getJWKthumbprint(jwk);
      -1887     }
      -1888 
      -1889     if (hCert != undefined && nox5c != true) {
      -1890 	jwk.x5c = [hex2b64(hCert)];
      -1891     }
      -1892 
      -1893     if (hCert != undefined && nox5t != true) {
      -1894 	jwk.x5t = b64tob64u(hex2b64(_hashHex(hCert, "sha1")));
      -1895     }
      -1896 
      -1897     if (hCert != undefined && nox5t2 != true) {
      -1898 	jwk["x5t#S256"] = b64tob64u(hex2b64(_hashHex(hCert, "sha256")));
      -1899     }
      -1900 
      -1901     return jwk;
      -1902 };
      -1903 
      -1904 /**
      -1905  * convert from RSAKey/KJUR.crypto.ECDSA public/private key object to RFC 7517 JSON Web Key(JWK) (DEPRECATED)<br/>
      -1906  * @name getJWKFromKey
      -1907  * @memberOf KEYUTIL
      -1908  * @function
      -1909  * @static
      -1910  * @param {Object} RSAKey/KJUR.crypto.ECDSA public/private key object
      -1911  * @return {Object} JWK object
      -1912  * @since keyutil 1.0.13 jsrsasign 5.0.14
      -1913  * @deprecated since jsrsasign 10.5.1 keyutil 1.2.5 please use getJWK method
      -1914  * @see KEYUTIL.getJWK
      -1915  *
      -1916  * @description
      -1917  * This static method convert from RSAKey/KJUR.crypto.ECDSA public/private key object 
      -1918  * to RFC 7517 JSON Web Key(JWK)
      -1919  * 
      -1920  * @example
      -1921  * kp1 = KEYUTIL.generateKeypair("EC", "P-256");
      -1922  * jwkPrv1 = KEYUTIL.getJWKFromKey(kp1.prvKeyObj);
      -1923  * jwkPub1 = KEYUTIL.getJWKFromKey(kp1.pubKeyObj);
      -1924  *
      -1925  * kp2 = KEYUTIL.generateKeypair("RSA", 2048);
      -1926  * jwkPrv2 = KEYUTIL.getJWKFromKey(kp2.prvKeyObj);
      -1927  * jwkPub2 = KEYUTIL.getJWKFromKey(kp2.pubKeyObj);
      -1928  *
      -1929  * // if you need RFC 7638 JWK thumprint as kid do like this:
      -1930  * jwkPub2.kid = KJUR.jws.JWS.getJWKthumbprint(jwkPub2);
      -1931  */
      -1932 KEYUTIL.getJWKFromKey = function(keyObj) {
      -1933     return KEYUTIL.getJWK(keyObj, true, true, true, true);
      -1934 }
      -1935 
      \ No newline at end of file +1849
      if (encAlg === undefined) encAlg = "DES-EDE3-CBC"; +1850 return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA", asn1Hex, passwd, encAlg, ivsaltHex); +1851 } +1852 +1853 // x. PEM PKCS#5 encrypted private key of ECDSA private key object +1854 if (formatType == "PKCS5PRV" && +1855 _ECDSA !== undefined && +1856 keyObjOrHex instanceof _ECDSA && +1857 (passwd !== undefined && passwd != null) && +1858 keyObjOrHex.isPrivate == true) { +1859 +1860 var asn1Obj = _ecdsaprv2asn1obj(keyObjOrHex); +1861 var asn1Hex = asn1Obj.tohex(); +1862 +1863 if (encAlg === undefined) encAlg = "DES-EDE3-CBC"; +1864 return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC", asn1Hex, passwd, encAlg, ivsaltHex); +1865 } +1866 +1867 // x. PEM PKCS#5 encrypted private key of DSA private key object +1868 if (formatType == "PKCS5PRV" && +1869 _DSA !== undefined && +1870 keyObjOrHex instanceof _DSA && +1871 (passwd !== undefined && passwd != null) && +1872 keyObjOrHex.isPrivate == true) { +1873 +1874 var asn1Obj = _dsaprv2asn1obj(keyObjOrHex); +1875 var asn1Hex = asn1Obj.tohex(); +1876 +1877 if (encAlg === undefined) encAlg = "DES-EDE3-CBC"; +1878 return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA", asn1Hex, passwd, encAlg, ivsaltHex); +1879 } +1880 +1881 // x. ====================================================================== +1882 +1883 var _getEncryptedPKCS8PEM = function(plainKeyHex, passcodeOrParam) { +1884 if (typeof passcodeOrParam == "string") { +1885 return KEYUTIL.getEncryptedPKCS8PEM(plainKeyHex, passcodeOrParam); +1886 } else if (typeof passcodeOrParam == "object" && aryval(passcodeOrParam, "passcode") != undefined) { +1887 var param = JSON.parse(JSON.stringify(passcodeOrParam)); +1888 var passcode = param.passcode; +1889 delete param.passcode; +1890 return KEYUTIL.getEncryptedPKCS8PEM(plainKeyHex, passcode, param); +1891 } +1892 }; +1893 +1894 // x. PEM PKCS#8 plain private key of RSA private key object +1895 if (formatType == "PKCS8PRV" && +1896 _RSAKey != undefined && +1897 keyObjOrHex instanceof _RSAKey && +1898 keyObjOrHex.isPrivate == true) { +1899 +1900 var keyObj = _rsaprv2asn1obj(keyObjOrHex); +1901 var keyHex = keyObj.tohex(); +1902 +1903 var asn1Obj = _newObject({ +1904 "seq": [ +1905 {"int": 0}, +1906 {"seq": [{"oid": {"name": "rsaEncryption"}},{"null": true}]}, +1907 {"octstr": {"hex": keyHex}} +1908 ] +1909 }); +1910 var asn1Hex = asn1Obj.tohex(); +1911 +1912 if (passwd === undefined || passwd == null) { +1913 return hextopem(asn1Hex, "PRIVATE KEY"); +1914 } else { +1915 return _getEncryptedPKCS8PEM(asn1Hex, passwd); +1916 } +1917 } +1918 +1919 // x. PEM PKCS#8 plain private key of ECDSA private key object +1920 if (formatType == "PKCS8PRV" && +1921 _ECDSA !== undefined && +1922 keyObjOrHex instanceof _ECDSA && +1923 keyObjOrHex.isPrivate == true) { +1924 +1925 var pKeyObj = { +1926 "seq": [ +1927 {"int": 1}, +1928 {"octstr": {"hex": keyObjOrHex.prvKeyHex}} +1929 ] +1930 }; +1931 if (typeof keyObjOrHex.pubKeyHex == "string") { +1932 pKeyObj.seq.push({"tag": ['a1', true, {"bitstr": {"hex": "00" + keyObjOrHex.pubKeyHex}}]}); +1933 } +1934 var keyObj = new _newObject(pKeyObj); +1935 var keyHex = keyObj.tohex(); +1936 +1937 var asn1Obj = _newObject({ +1938 "seq": [ +1939 {"int": 0}, +1940 {"seq": [ +1941 {"oid": {"name": "ecPublicKey"}}, +1942 {"oid": {"name": keyObjOrHex.curveName}} +1943 ]}, +1944 {"octstr": {"hex": keyHex}} +1945 ] +1946 }); +1947 +1948 var asn1Hex = asn1Obj.tohex(); +1949 if (passwd === undefined || passwd == null) { +1950 return hextopem(asn1Hex, "PRIVATE KEY"); +1951 } else { +1952 return _getEncryptedPKCS8PEM(asn1Hex, passwd); +1953 } +1954 } +1955 +1956 // x. PEM PKCS#8 plain private key of DSA private key object +1957 if (formatType == "PKCS8PRV" && +1958 _DSA !== undefined && +1959 keyObjOrHex instanceof _DSA && +1960 keyObjOrHex.isPrivate == true) { +1961 +1962 var keyObj = new _DERInteger({'bigint': keyObjOrHex.x}); +1963 var keyHex = keyObj.tohex(); +1964 +1965 var asn1Obj = _newObject({ +1966 "seq": [ +1967 {"int": 0}, +1968 {"seq": [ +1969 {"oid": {"name": "dsa"}}, +1970 {"seq": [ +1971 {"int": {"bigint": keyObjOrHex.p}}, +1972 {"int": {"bigint": keyObjOrHex.q}}, +1973 {"int": {"bigint": keyObjOrHex.g}} +1974 ]} +1975 ]}, +1976 {"octstr": {"hex": keyHex}} +1977 ] +1978 }); +1979 +1980 var asn1Hex = asn1Obj.tohex(); +1981 if (passwd === undefined || passwd == null) { +1982 return hextopem(asn1Hex, "PRIVATE KEY"); +1983 } else { +1984 return _getEncryptedPKCS8PEM(asn1Hex, passwd); +1985 } +1986 } +1987 +1988 throw new Error("unsupported object nor format"); +1989 }; +1990 +1991 // -- PUBLIC METHODS FOR CSR -------------------------------------------------- +1992 +1993 /** +1994 * get RSAKey/DSA/ECDSA public key object from PEM formatted PKCS#10 CSR string +1995 * @name getKeyFromCSRPEM +1996 * @memberOf KEYUTIL +1997 * @function +1998 * @param {String} csrPEM PEM formatted PKCS#10 CSR string +1999 * @return {Object} RSAKey/DSA/ECDSA public key object +2000 * @since keyutil 1.0.5 +2001 */ +2002 KEYUTIL.getKeyFromCSRPEM = function(csrPEM) { +2003 var csrHex = pemtohex(csrPEM, "CERTIFICATE REQUEST"); +2004 var key = KEYUTIL.getKeyFromCSRHex(csrHex); +2005 return key; +2006 }; +2007 +2008 /** +2009 * get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#10 CSR +2010 * @name getKeyFromCSRHex +2011 * @memberOf KEYUTIL +2012 * @function +2013 * @param {String} csrHex hexadecimal string of PKCS#10 CSR +2014 * @return {Object} RSAKey/DSA/ECDSA public key object +2015 * @since keyutil 1.0.5 +2016 */ +2017 KEYUTIL.getKeyFromCSRHex = function(csrHex) { +2018 var info = KEYUTIL.parseCSRHex(csrHex); +2019 var key = KEYUTIL.getKey(info.p8pubkeyhex, null, "pkcs8pub"); +2020 return key; +2021 }; +2022 +2023 /** +2024 * parse hexadecimal string of PKCS#10 CSR (certificate signing request) +2025 * @name parseCSRHex +2026 * @memberOf KEYUTIL +2027 * @function +2028 * @param {String} csrHex hexadecimal string of PKCS#10 CSR +2029 * @return {Array} associative array of parsed CSR +2030 * @since keyutil 1.0.5 +2031 * @description +2032 * Resulted associative array has following properties: +2033 * <ul> +2034 * <li>p8pubkeyhex - hexadecimal string of subject public key in PKCS#8</li> +2035 * </ul> +2036 */ +2037 KEYUTIL.parseCSRHex = function(csrHex) { +2038 var _ASN1HEX = ASN1HEX; +2039 var _getChildIdx = _ASN1HEX.getChildIdx; +2040 var _getTLV = _ASN1HEX.getTLV; +2041 var result = {}; +2042 var h = csrHex; +2043 +2044 // 1. sequence +2045 if (h.substr(0, 2) != "30") +2046 throw new Error("malformed CSR(code:001)"); // not sequence +2047 +2048 var a1 = _getChildIdx(h, 0); +2049 if (a1.length < 1) +2050 throw new Error("malformed CSR(code:002)"); // short length +2051 +2052 // 2. 2nd sequence +2053 if (h.substr(a1[0], 2) != "30") +2054 throw new Error("malformed CSR(code:003)"); // not sequence +2055 +2056 var a2 = _getChildIdx(h, a1[0]); +2057 if (a2.length < 3) +2058 throw new Error("malformed CSR(code:004)"); // 2nd seq short elem +2059 +2060 result.p8pubkeyhex = _getTLV(h, a2[2]); +2061 +2062 return result; +2063 }; +2064 +2065 // -- ENCRYPTED PKCS#8 PRIVATE KEY GENERATION METHODS ------------------------ +2066 +2067 // -- OTHER STATIC PUBLIC METHODS -------------------------------------------- +2068 +2069 /** +2070 * get key ID by public key object for subject or authority key identifier +2071 * @name getKeyID +2072 * @memberof KEYUTIL +2073 * @function +2074 * @static +2075 * @param {Object} obj RSAKey/KJUR.crypto.ECDSA,DSA public key object or public key PEM string +2076 * @return hexadecimal string of public key identifier +2077 * @since keyutil 1.2.2 jsrsasign 5.0.16 +2078 * @description +2079 * This static method generates a key identifier from a public key +2080 * by the method described in +2081 * <a href="https://tools.ietf.org/html/rfc5280#section-4.2.1.2" +2082 * target="_blank">RFC 5280 4.2.1.2. Subject Key Identifier (1)</a>. +2083 * @example +2084 * pubkeyobj = KEYUTIL.getKey(...); +2085 * KEYTUTIL.getKey(pubkeyobj) → "a612..." +2086 */ +2087 KEYUTIL.getKeyID = function(obj) { +2088 var _KEYUTIL = KEYUTIL; +2089 var _ASN1HEX = ASN1HEX; +2090 +2091 if (typeof obj === "string" && obj.indexOf("BEGIN ") != -1) { +2092 obj = _KEYUTIL.getKey(obj); +2093 } +2094 +2095 var p8hex = pemtohex(_KEYUTIL.getPEM(obj)); +2096 var idx = _ASN1HEX.getIdxbyList(p8hex, 0, [1]); // BITSTRING +2097 var hV = _ASN1HEX.getV(p8hex, idx).substring(2); // value without unused bit +2098 return KJUR.crypto.Util.hashHex(hV, "sha1"); +2099 } +2100 +2101 /** +2102 * convert from certificate, public/private key object to RFC 7517 JSON Web Key(JWK)<br/> +2103 * @name getJWK +2104 * @memberOf KEYUTIL +2105 * @function +2106 * @static +2107 * @param {Object or string} keyinfo public/private key object, PEM key or PEM certificate +2108 * @param {boolean} nokid set true if you don't need kid (OPTION, DEFAULT=undefined) +2109 * @param {boolean} nox5c set true if you don't need x5c of certificate (OPTION, DEFAULT=undefined) +2110 * @param {boolean} nox5t set true if you don't need x5t of certificate (OPTION, DEFAULT=undefined) +2111 * @param {boolean} nox5t2 set true if you don't need x5c#S256 of certificate (OPTION, DEFAULT=undefined) +2112 * @return {Object} JWK object +2113 * @since keyutil 1.2.5 jsrsasign 10.5.1 +2114 * @see RSAKey +2115 * @see KJUR.crypto.ECDSA +2116 * @see KJUR.crypto.DSA +2117 * +2118 * @description +2119 * This static method provides +2120 * <a href="https://datatracker.ietf.org/doc/html/rfc7517"> +2121 * RFC 7517 JSON Web Key(JWK) JSON</a> +2122 * object from following argument types: +2123 * <ul> +2124 * <li> +2125 * <b>JWK private key</b> +2126 * <ul> +2127 * <li>RSAKey or KJUR.crypto.{ECDSA,DSA} private key object</li> +2128 * <li>PKCS#5 or PKCS#8 plain PEM private key</li> +2129 * </ul> +2130 * </li> +2131 * <li> +2132 * <b>JWK public key</b> +2133 * <ul> +2134 * <li>RSAKey or KJUR.crypto.{ECDSA,DSA} public key object</li> +2135 * <li>PKCS#5 or PKCS#8 PEM public key</li> +2136 * <li>X509 certificate object</li> +2137 * <li>PEM certificate</li> +2138 * </ul> +2139 * </li> +2140 * </ul> +2141 * +2142 * @example +2143 * kp1 = KEYUTIL.generateKeypair("EC", "P-256"); +2144 * jwkPrv1 = KEYUTIL.getJWK(kp1.prvKeyObj); +2145 * jwkPub1 = KEYUTIL.getJWK(kp1.pubKeyObj); +2146 * +2147 * kp2 = KEYUTIL.generateKeypair("RSA", 2048); +2148 * jwkPrv2 = KEYUTIL.getJWK(kp2.prvKeyObj); +2149 * jwkPub2 = KEYUTIL.getJWK(kp2.pubKeyObj); +2150 * +2151 * // from PEM certificate +2152 * KEYUTIL.getJWK("-----BEGIN CERTIFICATE...") → +2153 * { +2154 * kty: "EC", crv: "P-521", x: "...", y: "...", +2155 * x5c: ["MI..."], +2156 * x5t: "...", +2157 * "x5t#S256": "...", +2158 * kid: "..." +2159 * } +2160 * +2161 * // from X509 object +2162 * x509obj = new X509("-----BEGIN CERTIFICATE..."); +2163 * KEYUTIL.getJWK(x509obj) → +2164 * { +2165 * kty: "EC", crv: "P-521", x: "...", y: "...", +2166 * ... +2167 * } +2168 * +2169 * // from PEM certificate without kid, x5t and x5t#S256 (i.e. only x5c) +2170 * KEYUTIL.getJWK("-----BEGIN CERTIFICATE...", true, false, true, true) → +2171 * { +2172 * kty: "EC", crv: "P-521", x: "...", y: "...", +2173 * x5c: ["MI..."] +2174 * } +2175 */ +2176 KEYUTIL.getJWK = function(keyinfo, nokid, nox5c, nox5t, nox5t2) { +2177 var keyObj; +2178 var jwk = {}; +2179 var hCert; +2180 var _hashHex = KJUR.crypto.Util.hashHex; +2181 +2182 if (typeof keyinfo == "string") { +2183 keyObj = KEYUTIL.getKey(keyinfo); +2184 if (keyinfo.indexOf("CERTIFICATE") != -1) { +2185 hCert = pemtohex(keyinfo) +2186 } +2187 } else if (typeof keyinfo == "object") { +2188 if (keyinfo instanceof X509) { +2189 keyObj = keyinfo.getPublicKey(); +2190 hCert = keyinfo.hex; +2191 } else { +2192 keyObj = keyinfo; +2193 } +2194 } else { +2195 throw new Error("unsupported keyinfo type"); +2196 } +2197 +2198 if (keyObj instanceof RSAKey && keyObj.isPrivate) { +2199 jwk.kty = "RSA"; +2200 jwk.n = hextob64u(keyObj.n.toString(16)); +2201 jwk.e = hextob64u(keyObj.e.toString(16)); +2202 jwk.d = hextob64u(keyObj.d.toString(16)); +2203 jwk.p = hextob64u(keyObj.p.toString(16)); +2204 jwk.q = hextob64u(keyObj.q.toString(16)); +2205 jwk.dp = hextob64u(keyObj.dmp1.toString(16)); +2206 jwk.dq = hextob64u(keyObj.dmq1.toString(16)); +2207 jwk.qi = hextob64u(keyObj.coeff.toString(16)); +2208 } else if (keyObj instanceof RSAKey && keyObj.isPublic) { +2209 jwk.kty = "RSA"; +2210 jwk.n = hextob64u(keyObj.n.toString(16)); +2211 jwk.e = hextob64u(keyObj.e.toString(16)); +2212 } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPrivate) { +2213 var name = keyObj.getShortNISTPCurveName(); +2214 if (name !== "P-256" && name !== "P-384" && name !== "P-521") +2215 throw new Error("unsupported curve name for JWT: " + name); +2216 var xy = keyObj.getPublicKeyXYHex(); +2217 jwk.kty = "EC"; +2218 jwk.crv = name; +2219 jwk.x = hextob64u(xy.x); +2220 jwk.y = hextob64u(xy.y); +2221 jwk.d = hextob64u(keyObj.prvKeyHex); +2222 } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPublic) { +2223 var name = keyObj.getShortNISTPCurveName(); +2224 if (name !== "P-256" && name !== "P-384" && name !== "P-521") +2225 throw new Error("unsupported curve name for JWT: " + name); +2226 var xy = keyObj.getPublicKeyXYHex(); +2227 jwk.kty = "EC"; +2228 jwk.crv = name; +2229 jwk.x = hextob64u(xy.x); +2230 jwk.y = hextob64u(xy.y); +2231 } +2232 if (jwk.kty == undefined) throw new Error("unsupported keyinfo"); +2233 +2234 if ((! keyObj.isPrivate) && nokid != true) { +2235 jwk.kid = KJUR.jws.JWS.getJWKthumbprint(jwk); +2236 } +2237 +2238 if (hCert != undefined && nox5c != true) { +2239 jwk.x5c = [hex2b64(hCert)]; +2240 } +2241 +2242 if (hCert != undefined && nox5t != true) { +2243 jwk.x5t = b64tob64u(hex2b64(_hashHex(hCert, "sha1"))); +2244 } +2245 +2246 if (hCert != undefined && nox5t2 != true) { +2247 jwk["x5t#S256"] = b64tob64u(hex2b64(_hashHex(hCert, "sha256"))); +2248 } +2249 +2250 return jwk; +2251 }; +2252 +2253 /** +2254 * convert from RSAKey/KJUR.crypto.ECDSA public/private key object to RFC 7517 JSON Web Key(JWK) (DEPRECATED)<br/> +2255 * @name getJWKFromKey +2256 * @memberOf KEYUTIL +2257 * @function +2258 * @static +2259 * @param {Object} RSAKey/KJUR.crypto.ECDSA public/private key object +2260 * @return {Object} JWK object +2261 * @since keyutil 1.0.13 jsrsasign 5.0.14 +2262 * @deprecated since jsrsasign 10.5.1 keyutil 1.2.5 please use getJWK method +2263 * @see KEYUTIL.getJWK +2264 * +2265 * @description +2266 * This static method convert from RSAKey/KJUR.crypto.ECDSA public/private key object +2267 * to RFC 7517 JSON Web Key(JWK) +2268 * +2269 * @example +2270 * kp1 = KEYUTIL.generateKeypair("EC", "P-256"); +2271 * jwkPrv1 = KEYUTIL.getJWKFromKey(kp1.prvKeyObj); +2272 * jwkPub1 = KEYUTIL.getJWKFromKey(kp1.pubKeyObj); +2273 * +2274 * kp2 = KEYUTIL.generateKeypair("RSA", 2048); +2275 * jwkPrv2 = KEYUTIL.getJWKFromKey(kp2.prvKeyObj); +2276 * jwkPub2 = KEYUTIL.getJWKFromKey(kp2.pubKeyObj); +2277 * +2278 * // if you need RFC 7638 JWK thumprint as kid do like this: +2279 * jwkPub2.kid = KJUR.jws.JWS.getJWKthumbprint(jwkPub2); +2280 */ +2281 KEYUTIL.getJWKFromKey = function(keyObj) { +2282 return KEYUTIL.getJWK(keyObj, true, true, true, true); +2283 } +2284
      \ No newline at end of file