From 51fa7be4cbfe5cffd952517da8f3e18a67333c46 Mon Sep 17 00:00:00 2001 From: Kenji Urushima Date: Thu, 3 Nov 2016 11:34:22 +0900 Subject: [PATCH] 6.2.0 release --- ChangeLog.txt | 13 +- api/files.html | 2 +- api/symbols/KJUR.crypto.MessageDigest.html | 263 +- api/symbols/KJUR.crypto.html | 87 + api/symbols/src/crypto-1.1.js.html | 2593 +++++++++++--------- bower.json | 2 +- crypto-1.1.js | 229 +- ext/rsa-min.js | 2 +- ext/rsa.js | 48 +- ext/rsa2-min.js | 2 +- ext/rsa2.js | 57 +- index.html | 5 + jsrsasign-latest-all-min.js | 10 +- min/crypto-1.1.min.js | 4 +- npm/lib/footer.js | 2 + npm/lib/jsrsasign.js | 17 +- npm/package.json | 3 +- test/index.html | 2 + test/qunit-do-crypto-cipher.html | 72 + test/qunit-do-crypto-md.html | 62 + 20 files changed, 2185 insertions(+), 1290 deletions(-) create mode 100644 test/qunit-do-crypto-cipher.html create mode 100644 test/qunit-do-crypto-md.html diff --git a/ChangeLog.txt b/ChangeLog.txt index fdadc6ab..2137a537 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,18 @@ ChangeLog for jsrsasign -* Changes from 6.1.4 to next version +* Changes from 6.1.4 to 6.2.0 + - RSAKey + - CRITICAL BUGFIX: RSA-PSS and RSA-OAEP not working from jsrsasign 5.0.0 + because rstr_sha1 function is missingand. Now it was fixed. + (oaep_pad, oeap_unpad) + - API document added. + - crypto 1.1.9 to 1.1.10 + - KJUR.crypto.Cipher class added to encrypt/decrypt data. + Currently only RSA, RSAOAEP supported. Other ciphers like + AES, 3DES will be supported near in the future. + - KJUR.crypto.MessageDigest class + - HASHLENGTH, getCanonicalAlgName, getHashLength - asn1x509 1.0.15 to 1.0.16 - AuthorityInfoAccess class added by @lionello 's pull request. Thanks. - base64x diff --git a/api/files.html b/api/files.html index b79580e7..72c4fd34 100644 --- a/api/files.html +++ b/api/files.html @@ -606,7 +606,7 @@

crypto-1.1.js

Version:
-
1.1.9 (2016-Oct-08)
+
1.1.10 (2016-Oct-29)
diff --git a/api/symbols/KJUR.crypto.MessageDigest.html b/api/symbols/KJUR.crypto.MessageDigest.html index 85f84386..71b9867a 100644 --- a/api/symbols/KJUR.crypto.MessageDigest.html +++ b/api/symbols/KJUR.crypto.MessageDigest.html @@ -462,7 +462,7 @@

-
MessageDigest class which is very similar to java.security.MessageDigest class +
MessageDigest class which is very similar to java.security.MessageDigest class

Currently this supports following algorithm and providers combination:
    @@ -483,6 +483,34 @@

    + + + + + + + + + + + + + + + + + + +
    Field Summary
    Field AttributesField Name and Description
      + +
    static Array of resulted byte length of hash (ex.
    +
    + + + + @@ -509,9 +537,9 @@

    - <static>   +   -
    KJUR.crypto.MessageDigest.digestHex(hex) +
    digestHex(hex)
    performs final update on the digest using hexadecimal string, then completes the digest computation
    @@ -519,9 +547,9 @@

    - <static>   +   -
    KJUR.crypto.MessageDigest.digestString(str) +
    performs final update on the digest using string, then completes the digest computation
    @@ -531,17 +559,39 @@

    <static>   -
    KJUR.crypto.MessageDigest.setAlgAndProvider(alg, prov) +
    KJUR.crypto.MessageDigest.getCanonicalAlgName(alg)
    -
    set hash algorithm and provider -
    +
    get canonical hash algorithm name
    +This static method normalizes from any hash algorithm name such as +"SHA-1", "SHA1", "MD5", "sha512" to lower case name without hyphens +such as "sha1".
    <static>   -
    KJUR.crypto.MessageDigest.updateHex(hex) +
    KJUR.crypto.MessageDigest.getHashLength(alg) +
    +
    get resulted hash byte length for specified algorithm name
    +This static method returns resulted byte length for specified algorithm name such as "SHA-1".
    + + + + +   + +
    setAlgAndProvider(alg, prov) +
    +
    set hash algorithm and provider
    +This methods set an algorithm and a cryptographic provider.
    + + + + +   + +
    updateHex(hex)
    update digest by specified hexadecimal string
    @@ -549,9 +599,9 @@

    - <static>   +   -
    KJUR.crypto.MessageDigest.updateString(str) +
    update digest by specified string
    @@ -579,7 +629,7 @@

    - MessageDigest class which is very similar to java.security.MessageDigest class + MessageDigest class which is very similar to java.security.MessageDigest class

    Currently this supports following algorithm and providers combination:
      @@ -605,7 +655,11 @@

      // SJCL(Stanford JavaScript Crypto Library) provider sample var md = new KJUR.crypto.MessageDigest({alg: "sha256", prov: "sjcl"}); // sjcl supports sha256 only md.updateString('aaa') -var mdHex = md.digest() +var mdHex = md.digest() + +// HASHLENGTH property +KJUR.crypto.MessageDigest.HASHLENGTH['sha1'] &rarr 20 +KJUR.crypto.MessageDigest.HASHLENGTH['sha512'] &rarr 64 @@ -634,6 +688,33 @@

      +
      + Field Detail +
      + + +
      + + {Array} + HASHLENGTH + +
      +
      + static Array of resulted byte length of hash (ex. HASHLENGTH["sha1"] == 20) + + +
      + + + + + + + + + + + @@ -671,11 +752,11 @@


      - -
      <static> + +
      - KJUR.crypto.MessageDigest.digestHex(hex) + digestHex(hex)
      @@ -712,11 +793,11 @@


      - -
      <static> + +
      - KJUR.crypto.MessageDigest.digestString(str) + digestString(str)
      @@ -753,16 +834,141 @@


      - +
      <static> + {String} + KJUR.crypto.MessageDigest.getCanonicalAlgName(alg) + +
      +
      + get canonical hash algorithm name
      +This static method normalizes from any hash algorithm name such as +"SHA-1", "SHA1", "MD5", "sha512" to lower case name without hyphens +such as "sha1". + + +
      + + + +
      KJUR.crypto.MessageDigest.getCanonicalAlgName("SHA-1") &rarr "sha1"
      +KJUR.crypto.MessageDigest.getCanonicalAlgName("MD5")   &rarr "md5"
      + - KJUR.crypto.MessageDigest.setAlgAndProvider(alg, prov) + + +
      +
      Parameters:
      + +
      + {String} alg + +
      +
      hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.)
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 6.2.0 crypto 1.1.10
      +
      + + + + +
      +
      Returns:
      + +
      {String} canonical hash algorithm name
      + +
      + + + + +
      + + +
      <static> + + {Integer} + KJUR.crypto.MessageDigest.getHashLength(alg)
      - set hash algorithm and provider + get resulted hash byte length for specified algorithm name
      +This static method returns resulted byte length for specified algorithm name such as "SHA-1". + + +
      + + + +
      KJUR.crypto.MessageDigest.getHashLength("SHA-1") &rarr 20
      +KJUR.crypto.MessageDigest.getHashLength("sha1") &rarr 20
      + + + + +
      +
      Parameters:
      + +
      + {String} alg + +
      +
      non-canonicalized hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.)
      + +
      + + + +
      +
      Since:
      +
      jsrsasign 6.2.0 crypto 1.1.10
      +
      + + + + +
      +
      Returns:
      + +
      {Integer} resulted hash byte length
      + +
      + + + +
      + + +
      + + + setAlgAndProvider(alg, prov) + +
      +
      + set hash algorithm and provider
      +This methods set an algorithm and a cryptographic provider.
      +Here is acceptable algorithm names ignoring cases and hyphens: +
        +
      • MD5
      • +
      • SHA1
      • +
      • SHA224
      • +
      • SHA256
      • +
      • SHA384
      • +
      • SHA512
      • +
      • RIPEMD160
      • +
      +NOTE: Since jsrsasign 6.2.0 crypto 1.1.10, this method ignores +upper or lower cases. Also any hyphens (i.e. "-") will be ignored +so that "SHA1" or "SHA-1" will be acceptable.
      @@ -771,6 +977,7 @@

      // for SHA1
       md.setAlgAndProvider('sha1', 'cryptojs');
      +md.setAlgAndProvider('SHA1');
       // for RIPEMD160
       md.setAlgAndProvider('ripemd160', 'cryptojs');
      @@ -803,11 +1010,11 @@


      - -
      <static> + +
      - KJUR.crypto.MessageDigest.updateHex(hex) + updateHex(hex)
      @@ -844,11 +1051,11 @@


      - -
      <static> + +
      - KJUR.crypto.MessageDigest.updateString(str) + updateString(str)
      diff --git a/api/symbols/KJUR.crypto.html b/api/symbols/KJUR.crypto.html index 20c0a579..3cf9c5f3 100644 --- a/api/symbols/KJUR.crypto.html +++ b/api/symbols/KJUR.crypto.html @@ -473,6 +473,44 @@

      + + + + + + + + + + + + + + + + + + +
      Field Summary
      Field AttributesField Name and Description
      <static>   +
      + KJUR.crypto.Cipher +
      +
      Cipher class to encrypt and decrypt data
      +Here is supported canonicalized cipher algorithm names and its standard names: +
        +
      • RSA - RSA/ECB/PKCS1Padding (default for RSAKey)
      • +
      • RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding
      • +
      • RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)
      • +
      • RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding
      • +
      • RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)
      • +
      • RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)
      • +
      +NOTE: (*) is not supported in Java JCE.
      +
      + + + + @@ -686,6 +724,7 @@

      NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2. @@ -709,6 +748,54 @@

      +
      + Field Detail +
      + + +
      <static> + + + KJUR.crypto.Cipher + +
      +
      + Cipher class to encrypt and decrypt data
      +Here is supported canonicalized cipher algorithm names and its standard names: +
        +
      • RSA - RSA/ECB/PKCS1Padding (default for RSAKey)
      • +
      • RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding
      • +
      • RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)
      • +
      • RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding
      • +
      • RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)
      • +
      • RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)
      • +
      +NOTE: (*) is not supported in Java JCE.
      +Currently this class supports only RSA encryption and decryption. +However it is planning to implement also symmetric ciphers near in the future. + + +
      + + + +
      
      +					
      +					
      +
      +						
      +						
      +							
      +
      Since:
      +
      jsrsasign 6.2.0 crypto 1.1.10
      +
      + + + + + + + diff --git a/api/symbols/src/crypto-1.1.js.html b/api/symbols/src/crypto-1.1.js.html index 5916f016..f6a8be78 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.1.9.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
      +	
        1 /*! crypto-1.1.10.js (c) 2013-2016 Kenji Urushima | kjur.github.com/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 1.1.9 (2016-Oct-08)
      + 19  * @version 1.1.10 (2016-Oct-29)
        20  * @since jsrsasign 2.2
        21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
        22  */
      @@ -41,1198 +41,1403 @@
        34  * <ul>
        35  * <li>{@link KJUR.crypto.MessageDigest} - Java JCE(cryptograhic extension) style MessageDigest class</li>
        36  * <li>{@link KJUR.crypto.Signature} - Java JCE(cryptograhic extension) style Signature class</li>
      - 37  * <li>{@link KJUR.crypto.Util} - cryptographic utility functions and properties</li>
      - 38  * </ul>
      - 39  * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.
      - 40  * </p>
      - 41  * @name KJUR.crypto
      - 42  * @namespace
      - 43  */
      - 44 if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
      - 45 
      - 46 /**
      - 47  * static object for cryptographic function utilities
      - 48  * @name KJUR.crypto.Util
      - 49  * @class static object for cryptographic function utilities
      - 50  * @property {Array} DIGESTINFOHEAD PKCS#1 DigestInfo heading hexadecimal bytes for each hash algorithms
      - 51  * @property {Array} DEFAULTPROVIDER associative array of default provider name for each hash and signature algorithms
      - 52  * @description
      - 53  */
      - 54 KJUR.crypto.Util = new function() {
      - 55     this.DIGESTINFOHEAD = {
      - 56 	'sha1':      "3021300906052b0e03021a05000414",
      - 57         'sha224':    "302d300d06096086480165030402040500041c",
      - 58 	'sha256':    "3031300d060960864801650304020105000420",
      - 59 	'sha384':    "3041300d060960864801650304020205000430",
      - 60 	'sha512':    "3051300d060960864801650304020305000440",
      - 61 	'md2':       "3020300c06082a864886f70d020205000410",
      - 62 	'md5':       "3020300c06082a864886f70d020505000410",
      - 63 	'ripemd160': "3021300906052b2403020105000414",
      - 64     };
      - 65 
      - 66     /*
      - 67      * @since crypto 1.1.1
      - 68      */
      - 69     this.DEFAULTPROVIDER = {
      - 70 	'md5':			'cryptojs',
      - 71 	'sha1':			'cryptojs',
      - 72 	'sha224':		'cryptojs',
      - 73 	'sha256':		'cryptojs',
      - 74 	'sha384':		'cryptojs',
      - 75 	'sha512':		'cryptojs',
      - 76 	'ripemd160':		'cryptojs',
      - 77 	'hmacmd5':		'cryptojs',
      - 78 	'hmacsha1':		'cryptojs',
      - 79 	'hmacsha224':		'cryptojs',
      - 80 	'hmacsha256':		'cryptojs',
      - 81 	'hmacsha384':		'cryptojs',
      - 82 	'hmacsha512':		'cryptojs',
      - 83 	'hmacripemd160':	'cryptojs',
      - 84 
      - 85 	'MD5withRSA':		'cryptojs/jsrsa',
      - 86 	'SHA1withRSA':		'cryptojs/jsrsa',
      - 87 	'SHA224withRSA':	'cryptojs/jsrsa',
      - 88 	'SHA256withRSA':	'cryptojs/jsrsa',
      - 89 	'SHA384withRSA':	'cryptojs/jsrsa',
      - 90 	'SHA512withRSA':	'cryptojs/jsrsa',
      - 91 	'RIPEMD160withRSA':	'cryptojs/jsrsa',
      - 92 
      - 93 	'MD5withECDSA':		'cryptojs/jsrsa',
      - 94 	'SHA1withECDSA':	'cryptojs/jsrsa',
      - 95 	'SHA224withECDSA':	'cryptojs/jsrsa',
      - 96 	'SHA256withECDSA':	'cryptojs/jsrsa',
      - 97 	'SHA384withECDSA':	'cryptojs/jsrsa',
      - 98 	'SHA512withECDSA':	'cryptojs/jsrsa',
      - 99 	'RIPEMD160withECDSA':	'cryptojs/jsrsa',
      -100 
      -101 	'SHA1withDSA':		'cryptojs/jsrsa',
      -102 	'SHA224withDSA':	'cryptojs/jsrsa',
      -103 	'SHA256withDSA':	'cryptojs/jsrsa',
      -104 
      -105 	'MD5withRSAandMGF1':		'cryptojs/jsrsa',
      -106 	'SHA1withRSAandMGF1':		'cryptojs/jsrsa',
      -107 	'SHA224withRSAandMGF1':		'cryptojs/jsrsa',
      -108 	'SHA256withRSAandMGF1':		'cryptojs/jsrsa',
      -109 	'SHA384withRSAandMGF1':		'cryptojs/jsrsa',
      -110 	'SHA512withRSAandMGF1':		'cryptojs/jsrsa',
      -111 	'RIPEMD160withRSAandMGF1':	'cryptojs/jsrsa',
      -112     };
      -113 
      -114     /*
      -115      * @since crypto 1.1.2
      -116      */
      -117     this.CRYPTOJSMESSAGEDIGESTNAME = {
      -118 	'md5':		CryptoJS.algo.MD5,
      -119 	'sha1':		CryptoJS.algo.SHA1,
      -120 	'sha224':	CryptoJS.algo.SHA224,
      -121 	'sha256':	CryptoJS.algo.SHA256,
      -122 	'sha384':	CryptoJS.algo.SHA384,
      -123 	'sha512':	CryptoJS.algo.SHA512,
      -124 	'ripemd160':	CryptoJS.algo.RIPEMD160
      -125     };
      -126 
      -127     /**
      -128      * get hexadecimal DigestInfo
      -129      * @name getDigestInfoHex
      -130      * @memberOf KJUR.crypto.Util
      -131      * @function
      -132      * @param {String} hHash hexadecimal hash value
      -133      * @param {String} alg hash algorithm name (ex. 'sha1')
      -134      * @return {String} hexadecimal string DigestInfo ASN.1 structure
      -135      */
      -136     this.getDigestInfoHex = function(hHash, alg) {
      -137 	if (typeof this.DIGESTINFOHEAD[alg] == "undefined")
      -138 	    throw "alg not supported in Util.DIGESTINFOHEAD: " + alg;
      -139 	return this.DIGESTINFOHEAD[alg] + hHash;
      -140     };
      -141 
      -142     /**
      -143      * get PKCS#1 padded hexadecimal DigestInfo
      -144      * @name getPaddedDigestInfoHex
      -145      * @memberOf KJUR.crypto.Util
      -146      * @function
      -147      * @param {String} hHash hexadecimal hash value of message to be signed
      -148      * @param {String} alg hash algorithm name (ex. 'sha1')
      -149      * @param {Integer} keySize key bit length (ex. 1024)
      -150      * @return {String} hexadecimal string of PKCS#1 padded DigestInfo
      -151      */
      -152     this.getPaddedDigestInfoHex = function(hHash, alg, keySize) {
      -153 	var hDigestInfo = this.getDigestInfoHex(hHash, alg);
      -154 	var pmStrLen = keySize / 4; // minimum PM length
      -155 
      -156 	if (hDigestInfo.length + 22 > pmStrLen) // len(0001+ff(*8)+00+hDigestInfo)=22
      -157 	    throw "key is too short for SigAlg: keylen=" + keySize + "," + alg;
      -158 
      -159 	var hHead = "0001";
      -160 	var hTail = "00" + hDigestInfo;
      -161 	var hMid = "";
      -162 	var fLen = pmStrLen - hHead.length - hTail.length;
      -163 	for (var i = 0; i < fLen; i += 2) {
      -164 	    hMid += "ff";
      -165 	}
      -166 	var hPaddedMessage = hHead + hMid + hTail;
      -167 	return hPaddedMessage;
      -168     };
      -169 
      -170     /**
      -171      * get hexadecimal hash of string with specified algorithm
      -172      * @name hashString
      -173      * @memberOf KJUR.crypto.Util
      -174      * @function
      -175      * @param {String} s input string to be hashed
      -176      * @param {String} alg hash algorithm name
      -177      * @return {String} hexadecimal string of hash value
      -178      * @since 1.1.1
      -179      */
      -180     this.hashString = function(s, alg) {
      -181         var md = new KJUR.crypto.MessageDigest({'alg': alg});
      -182         return md.digestString(s);
      -183     };
      -184 
      -185     /**
      -186      * get hexadecimal hash of hexadecimal string with specified algorithm
      -187      * @name hashHex
      -188      * @memberOf KJUR.crypto.Util
      -189      * @function
      -190      * @param {String} sHex input hexadecimal string to be hashed
      -191      * @param {String} alg hash algorithm name
      -192      * @return {String} hexadecimal string of hash value
      -193      * @since 1.1.1
      -194      */
      -195     this.hashHex = function(sHex, alg) {
      -196         var md = new KJUR.crypto.MessageDigest({'alg': alg});
      -197         return md.digestHex(sHex);
      -198     };
      -199 
      -200     /**
      -201      * get hexadecimal SHA1 hash of string
      -202      * @name sha1
      -203      * @memberOf KJUR.crypto.Util
      -204      * @function
      -205      * @param {String} s input string to be hashed
      -206      * @return {String} hexadecimal string of hash value
      -207      * @since 1.0.3
      -208      */
      -209     this.sha1 = function(s) {
      -210         var md = new KJUR.crypto.MessageDigest({'alg':'sha1', 'prov':'cryptojs'});
      -211         return md.digestString(s);
      -212     };
      -213 
      -214     /**
      -215      * get hexadecimal SHA256 hash of string
      -216      * @name sha256
      -217      * @memberOf KJUR.crypto.Util
      -218      * @function
      -219      * @param {String} s input string to be hashed
      -220      * @return {String} hexadecimal string of hash value
      -221      * @since 1.0.3
      -222      */
      -223     this.sha256 = function(s) {
      -224         var md = new KJUR.crypto.MessageDigest({'alg':'sha256', 'prov':'cryptojs'});
      -225         return md.digestString(s);
      -226     };
      -227 
      -228     this.sha256Hex = function(s) {
      -229         var md = new KJUR.crypto.MessageDigest({'alg':'sha256', 'prov':'cryptojs'});
      -230         return md.digestHex(s);
      -231     };
      -232 
      -233     /**
      -234      * get hexadecimal SHA512 hash of string
      -235      * @name sha512
      -236      * @memberOf KJUR.crypto.Util
      -237      * @function
      -238      * @param {String} s input string to be hashed
      -239      * @return {String} hexadecimal string of hash value
      -240      * @since 1.0.3
      -241      */
      -242     this.sha512 = function(s) {
      -243         var md = new KJUR.crypto.MessageDigest({'alg':'sha512', 'prov':'cryptojs'});
      -244         return md.digestString(s);
      -245     };
      -246 
      -247     this.sha512Hex = function(s) {
      -248         var md = new KJUR.crypto.MessageDigest({'alg':'sha512', 'prov':'cryptojs'});
      -249         return md.digestHex(s);
      -250     };
      -251 
      -252     /**
      -253      * get hexadecimal MD5 hash of string
      -254      * @name md5
      -255      * @memberOf KJUR.crypto.Util
      -256      * @function
      -257      * @param {String} s input string to be hashed
      -258      * @return {String} hexadecimal string of hash value
      -259      * @since 1.0.3
      -260      */
      -261     this.md5 = function(s) {
      -262         var md = new KJUR.crypto.MessageDigest({'alg':'md5', 'prov':'cryptojs'});
      -263         return md.digestString(s);
      -264     };
      -265 
      -266     /**
      -267      * get hexadecimal RIPEMD160 hash of string
      -268      * @name ripemd160
      -269      * @memberOf KJUR.crypto.Util
      -270      * @function
      -271      * @param {String} s input string to be hashed
      -272      * @return {String} hexadecimal string of hash value
      -273      * @since 1.0.3
      -274      */
      -275     this.ripemd160 = function(s) {
      -276         var md = new KJUR.crypto.MessageDigest({'alg':'ripemd160', 'prov':'cryptojs'});
      -277         return md.digestString(s);
      -278     };
      -279 
      -280     /*
      -281      * @since 1.1.2
      -282      */
      -283     this.getCryptoJSMDByName = function(s) {
      -284 	
      -285     };
      -286 };
      -287 
      -288 /**
      -289  * MessageDigest class which is very similar to java.security.MessageDigest class
      -290  * @name KJUR.crypto.MessageDigest
      -291  * @class MessageDigest class which is very similar to java.security.MessageDigest class
      -292  * @param {Array} params parameters for constructor
      -293  * @description
      -294  * <br/>
      -295  * Currently this supports following algorithm and providers combination:
      -296  * <ul>
      -297  * <li>md5 - cryptojs</li>
      -298  * <li>sha1 - cryptojs</li>
      -299  * <li>sha224 - cryptojs</li>
      -300  * <li>sha256 - cryptojs</li>
      -301  * <li>sha384 - cryptojs</li>
      -302  * <li>sha512 - cryptojs</li>
      -303  * <li>ripemd160 - cryptojs</li>
      -304  * <li>sha256 - sjcl (NEW from crypto.js 1.0.4)</li>
      -305  * </ul>
      -306  * @example
      -307  * // CryptoJS provider sample
      -308  * var md = new KJUR.crypto.MessageDigest({alg: "sha1", prov: "cryptojs"});
      -309  * md.updateString('aaa')
      -310  * var mdHex = md.digest()
      -311  *
      -312  * // SJCL(Stanford JavaScript Crypto Library) provider sample
      -313  * var md = new KJUR.crypto.MessageDigest({alg: "sha256", prov: "sjcl"}); // sjcl supports sha256 only
      -314  * md.updateString('aaa')
      -315  * var mdHex = md.digest()
      -316  */
      -317 KJUR.crypto.MessageDigest = function(params) {
      -318     var md = null;
      -319     var algName = null;
      -320     var provName = null;
      -321 
      -322     /**
      -323      * set hash algorithm and provider
      -324      * @name setAlgAndProvider
      -325      * @memberOf KJUR.crypto.MessageDigest
      -326      * @function
      -327      * @param {String} alg hash algorithm name
      -328      * @param {String} prov provider name
      -329      * @description
      -330      * @example
      -331      * // for SHA1
      -332      * md.setAlgAndProvider('sha1', 'cryptojs');
      -333      * // for RIPEMD160
      -334      * md.setAlgAndProvider('ripemd160', 'cryptojs');
      -335      */
      -336     this.setAlgAndProvider = function(alg, prov) {
      -337 	if (alg != null && prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg];
      -338 
      -339 	// for cryptojs
      -340 	if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(alg) != -1 &&
      -341 	    prov == 'cryptojs') {
      -342 	    try {
      -343 		this.md = KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[alg].create();
      -344 	    } catch (ex) {
      -345 		throw "setAlgAndProvider hash alg set fail alg=" + alg + "/" + ex;
      -346 	    }
      -347 	    this.updateString = function(str) {
      -348 		this.md.update(str);
      -349 	    };
      -350 	    this.updateHex = function(hex) {
      -351 		var wHex = CryptoJS.enc.Hex.parse(hex);
      -352 		this.md.update(wHex);
      -353 	    };
      -354 	    this.digest = function() {
      -355 		var hash = this.md.finalize();
      -356 		return hash.toString(CryptoJS.enc.Hex);
      -357 	    };
      -358 	    this.digestString = function(str) {
      -359 		this.updateString(str);
      -360 		return this.digest();
      -361 	    };
      -362 	    this.digestHex = function(hex) {
      -363 		this.updateHex(hex);
      -364 		return this.digest();
      -365 	    };
      -366 	}
      -367 	if (':sha256:'.indexOf(alg) != -1 &&
      -368 	    prov == 'sjcl') {
      -369 	    try {
      -370 		this.md = new sjcl.hash.sha256();
      -371 	    } catch (ex) {
      -372 		throw "setAlgAndProvider hash alg set fail alg=" + alg + "/" + ex;
      -373 	    }
      -374 	    this.updateString = function(str) {
      -375 		this.md.update(str);
      -376 	    };
      -377 	    this.updateHex = function(hex) {
      -378 		var baHex = sjcl.codec.hex.toBits(hex);
      -379 		this.md.update(baHex);
      -380 	    };
      -381 	    this.digest = function() {
      -382 		var hash = this.md.finalize();
      -383 		return sjcl.codec.hex.fromBits(hash);
      -384 	    };
      -385 	    this.digestString = function(str) {
      -386 		this.updateString(str);
      -387 		return this.digest();
      -388 	    };
      -389 	    this.digestHex = function(hex) {
      -390 		this.updateHex(hex);
      -391 		return this.digest();
      -392 	    };
      -393 	}
      -394     };
      -395 
      -396     /**
      -397      * update digest by specified string
      -398      * @name updateString
      -399      * @memberOf KJUR.crypto.MessageDigest
      -400      * @function
      -401      * @param {String} str string to update
      -402      * @description
      -403      * @example
      -404      * md.updateString('New York');
      -405      */
      -406     this.updateString = function(str) {
      -407 	throw "updateString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      -408     };
      -409 
      -410     /**
      -411      * update digest by specified hexadecimal string
      -412      * @name updateHex
      -413      * @memberOf KJUR.crypto.MessageDigest
      -414      * @function
      -415      * @param {String} hex hexadecimal string to update
      -416      * @description
      -417      * @example
      -418      * md.updateHex('0afe36');
      -419      */
      -420     this.updateHex = function(hex) {
      -421 	throw "updateHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      -422     };
      -423 
      -424     /**
      -425      * completes hash calculation and returns hash result
      -426      * @name digest
      -427      * @memberOf KJUR.crypto.MessageDigest
      -428      * @function
      -429      * @description
      -430      * @example
      -431      * md.digest()
      -432      */
      -433     this.digest = function() {
      -434 	throw "digest() not supported for this alg/prov: " + this.algName + "/" + this.provName;
      -435     };
      -436 
      -437     /**
      -438      * performs final update on the digest using string, then completes the digest computation
      -439      * @name digestString
      -440      * @memberOf KJUR.crypto.MessageDigest
      -441      * @function
      -442      * @param {String} str string to final update
      -443      * @description
      -444      * @example
      -445      * md.digestString('aaa')
      -446      */
      -447     this.digestString = function(str) {
      -448 	throw "digestString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      -449     };
      -450 
      -451     /**
      -452      * performs final update on the digest using hexadecimal string, then completes the digest computation
      -453      * @name digestHex
      -454      * @memberOf KJUR.crypto.MessageDigest
      -455      * @function
      -456      * @param {String} hex hexadecimal string to final update
      -457      * @description
      -458      * @example
      -459      * md.digestHex('0f2abd')
      -460      */
      -461     this.digestHex = function(hex) {
      -462 	throw "digestHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      -463     };
      -464 
      -465     if (params !== undefined) {
      -466 	if (params['alg'] !== undefined) {
      -467 	    this.algName = params['alg'];
      -468 	    if (params['prov'] === undefined)
      -469 		this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName];
      -470 	    this.setAlgAndProvider(this.algName, this.provName);
      -471 	}
      -472     }
      -473 };
      -474 
      -475 /**
      -476  * Mac(Message Authentication Code) class which is very similar to java.security.Mac class 
      -477  * @name KJUR.crypto.Mac
      -478  * @class Mac class which is very similar to java.security.Mac class
      -479  * @param {Array} params parameters for constructor
      -480  * @description
      -481  * <br/>
      -482  * Currently this supports following algorithm and providers combination:
      -483  * <ul>
      -484  * <li>hmacmd5 - cryptojs</li>
      -485  * <li>hmacsha1 - cryptojs</li>
      -486  * <li>hmacsha224 - cryptojs</li>
      -487  * <li>hmacsha256 - cryptojs</li>
      -488  * <li>hmacsha384 - cryptojs</li>
      -489  * <li>hmacsha512 - cryptojs</li>
      -490  * </ul>
      -491  * NOTE: HmacSHA224 and HmacSHA384 issue was fixed since jsrsasign 4.1.4.
      -492  * Please use 'ext/cryptojs-312-core-fix*.js' instead of 'core.js' of original CryptoJS
      -493  * to avoid those issue.
      -494  * <br/>
      -495  * NOTE2: Hmac signature bug was fixed in jsrsasign 4.9.0 by providing CryptoJS
      -496  * bug workaround.
      -497  * <br/>
      -498  * Please see {@link KJUR.crypto.Mac.setPassword}, how to provide password
      -499  * in various ways in detail.
      -500  * @example
      -501  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA1", "pass": "pass"});
      -502  * mac.updateString('aaa')
      -503  * var macHex = md.doFinal()
      -504  *
      -505  * // other password representation 
      -506  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"hex":  "6161"}});
      -507  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"utf8": "aa"}});
      -508  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"rstr": "\x61\x61"}});
      -509  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64":  "Mi02/+...a=="}});
      -510  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64u": "Mi02_-...a"}});
      -511  */
      -512 KJUR.crypto.Mac = function(params) {
      -513     var mac = null;
      -514     var pass = null;
      -515     var algName = null;
      -516     var provName = null;
      -517     var algProv = null;
      -518 
      -519     this.setAlgAndProvider = function(alg, prov) {
      -520 	alg = alg.toLowerCase();
      -521 
      -522 	if (alg == null) alg = "hmacsha1";
      + 37  * <li>{@link KJUR.crypto.Cipher} - class for encrypting and decrypting data</li>
      + 38  * <li>{@link KJUR.crypto.Util} - cryptographic utility functions and properties</li>
      + 39  * </ul>
      + 40  * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.
      + 41  * </p>
      + 42  * @name KJUR.crypto
      + 43  * @namespace
      + 44  */
      + 45 if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
      + 46 
      + 47 /**
      + 48  * static object for cryptographic function utilities
      + 49  * @name KJUR.crypto.Util
      + 50  * @class static object for cryptographic function utilities
      + 51  * @property {Array} DIGESTINFOHEAD PKCS#1 DigestInfo heading hexadecimal bytes for each hash algorithms
      + 52  * @property {Array} DEFAULTPROVIDER associative array of default provider name for each hash and signature algorithms
      + 53  * @description
      + 54  */
      + 55 KJUR.crypto.Util = new function() {
      + 56     this.DIGESTINFOHEAD = {
      + 57 	'sha1':      "3021300906052b0e03021a05000414",
      + 58         'sha224':    "302d300d06096086480165030402040500041c",
      + 59 	'sha256':    "3031300d060960864801650304020105000420",
      + 60 	'sha384':    "3041300d060960864801650304020205000430",
      + 61 	'sha512':    "3051300d060960864801650304020305000440",
      + 62 	'md2':       "3020300c06082a864886f70d020205000410",
      + 63 	'md5':       "3020300c06082a864886f70d020505000410",
      + 64 	'ripemd160': "3021300906052b2403020105000414",
      + 65     };
      + 66 
      + 67     /*
      + 68      * @since crypto 1.1.1
      + 69      */
      + 70     this.DEFAULTPROVIDER = {
      + 71 	'md5':			'cryptojs',
      + 72 	'sha1':			'cryptojs',
      + 73 	'sha224':		'cryptojs',
      + 74 	'sha256':		'cryptojs',
      + 75 	'sha384':		'cryptojs',
      + 76 	'sha512':		'cryptojs',
      + 77 	'ripemd160':		'cryptojs',
      + 78 	'hmacmd5':		'cryptojs',
      + 79 	'hmacsha1':		'cryptojs',
      + 80 	'hmacsha224':		'cryptojs',
      + 81 	'hmacsha256':		'cryptojs',
      + 82 	'hmacsha384':		'cryptojs',
      + 83 	'hmacsha512':		'cryptojs',
      + 84 	'hmacripemd160':	'cryptojs',
      + 85 
      + 86 	'MD5withRSA':		'cryptojs/jsrsa',
      + 87 	'SHA1withRSA':		'cryptojs/jsrsa',
      + 88 	'SHA224withRSA':	'cryptojs/jsrsa',
      + 89 	'SHA256withRSA':	'cryptojs/jsrsa',
      + 90 	'SHA384withRSA':	'cryptojs/jsrsa',
      + 91 	'SHA512withRSA':	'cryptojs/jsrsa',
      + 92 	'RIPEMD160withRSA':	'cryptojs/jsrsa',
      + 93 
      + 94 	'MD5withECDSA':		'cryptojs/jsrsa',
      + 95 	'SHA1withECDSA':	'cryptojs/jsrsa',
      + 96 	'SHA224withECDSA':	'cryptojs/jsrsa',
      + 97 	'SHA256withECDSA':	'cryptojs/jsrsa',
      + 98 	'SHA384withECDSA':	'cryptojs/jsrsa',
      + 99 	'SHA512withECDSA':	'cryptojs/jsrsa',
      +100 	'RIPEMD160withECDSA':	'cryptojs/jsrsa',
      +101 
      +102 	'SHA1withDSA':		'cryptojs/jsrsa',
      +103 	'SHA224withDSA':	'cryptojs/jsrsa',
      +104 	'SHA256withDSA':	'cryptojs/jsrsa',
      +105 
      +106 	'MD5withRSAandMGF1':		'cryptojs/jsrsa',
      +107 	'SHA1withRSAandMGF1':		'cryptojs/jsrsa',
      +108 	'SHA224withRSAandMGF1':		'cryptojs/jsrsa',
      +109 	'SHA256withRSAandMGF1':		'cryptojs/jsrsa',
      +110 	'SHA384withRSAandMGF1':		'cryptojs/jsrsa',
      +111 	'SHA512withRSAandMGF1':		'cryptojs/jsrsa',
      +112 	'RIPEMD160withRSAandMGF1':	'cryptojs/jsrsa',
      +113     };
      +114 
      +115     /*
      +116      * @since crypto 1.1.2
      +117      */
      +118     this.CRYPTOJSMESSAGEDIGESTNAME = {
      +119 	'md5':		CryptoJS.algo.MD5,
      +120 	'sha1':		CryptoJS.algo.SHA1,
      +121 	'sha224':	CryptoJS.algo.SHA224,
      +122 	'sha256':	CryptoJS.algo.SHA256,
      +123 	'sha384':	CryptoJS.algo.SHA384,
      +124 	'sha512':	CryptoJS.algo.SHA512,
      +125 	'ripemd160':	CryptoJS.algo.RIPEMD160
      +126     };
      +127 
      +128     /**
      +129      * get hexadecimal DigestInfo
      +130      * @name getDigestInfoHex
      +131      * @memberOf KJUR.crypto.Util
      +132      * @function
      +133      * @param {String} hHash hexadecimal hash value
      +134      * @param {String} alg hash algorithm name (ex. 'sha1')
      +135      * @return {String} hexadecimal string DigestInfo ASN.1 structure
      +136      */
      +137     this.getDigestInfoHex = function(hHash, alg) {
      +138 	if (typeof this.DIGESTINFOHEAD[alg] == "undefined")
      +139 	    throw "alg not supported in Util.DIGESTINFOHEAD: " + alg;
      +140 	return this.DIGESTINFOHEAD[alg] + hHash;
      +141     };
      +142 
      +143     /**
      +144      * get PKCS#1 padded hexadecimal DigestInfo
      +145      * @name getPaddedDigestInfoHex
      +146      * @memberOf KJUR.crypto.Util
      +147      * @function
      +148      * @param {String} hHash hexadecimal hash value of message to be signed
      +149      * @param {String} alg hash algorithm name (ex. 'sha1')
      +150      * @param {Integer} keySize key bit length (ex. 1024)
      +151      * @return {String} hexadecimal string of PKCS#1 padded DigestInfo
      +152      */
      +153     this.getPaddedDigestInfoHex = function(hHash, alg, keySize) {
      +154 	var hDigestInfo = this.getDigestInfoHex(hHash, alg);
      +155 	var pmStrLen = keySize / 4; // minimum PM length
      +156 
      +157 	if (hDigestInfo.length + 22 > pmStrLen) // len(0001+ff(*8)+00+hDigestInfo)=22
      +158 	    throw "key is too short for SigAlg: keylen=" + keySize + "," + alg;
      +159 
      +160 	var hHead = "0001";
      +161 	var hTail = "00" + hDigestInfo;
      +162 	var hMid = "";
      +163 	var fLen = pmStrLen - hHead.length - hTail.length;
      +164 	for (var i = 0; i < fLen; i += 2) {
      +165 	    hMid += "ff";
      +166 	}
      +167 	var hPaddedMessage = hHead + hMid + hTail;
      +168 	return hPaddedMessage;
      +169     };
      +170 
      +171     /**
      +172      * get hexadecimal hash of string with specified algorithm
      +173      * @name hashString
      +174      * @memberOf KJUR.crypto.Util
      +175      * @function
      +176      * @param {String} s input string to be hashed
      +177      * @param {String} alg hash algorithm name
      +178      * @return {String} hexadecimal string of hash value
      +179      * @since 1.1.1
      +180      */
      +181     this.hashString = function(s, alg) {
      +182         var md = new KJUR.crypto.MessageDigest({'alg': alg});
      +183         return md.digestString(s);
      +184     };
      +185 
      +186     /**
      +187      * get hexadecimal hash of hexadecimal string with specified algorithm
      +188      * @name hashHex
      +189      * @memberOf KJUR.crypto.Util
      +190      * @function
      +191      * @param {String} sHex input hexadecimal string to be hashed
      +192      * @param {String} alg hash algorithm name
      +193      * @return {String} hexadecimal string of hash value
      +194      * @since 1.1.1
      +195      */
      +196     this.hashHex = function(sHex, alg) {
      +197         var md = new KJUR.crypto.MessageDigest({'alg': alg});
      +198         return md.digestHex(sHex);
      +199     };
      +200 
      +201     /**
      +202      * get hexadecimal SHA1 hash of string
      +203      * @name sha1
      +204      * @memberOf KJUR.crypto.Util
      +205      * @function
      +206      * @param {String} s input string to be hashed
      +207      * @return {String} hexadecimal string of hash value
      +208      * @since 1.0.3
      +209      */
      +210     this.sha1 = function(s) {
      +211         var md = new KJUR.crypto.MessageDigest({'alg':'sha1', 'prov':'cryptojs'});
      +212         return md.digestString(s);
      +213     };
      +214 
      +215     /**
      +216      * get hexadecimal SHA256 hash of string
      +217      * @name sha256
      +218      * @memberOf KJUR.crypto.Util
      +219      * @function
      +220      * @param {String} s input string to be hashed
      +221      * @return {String} hexadecimal string of hash value
      +222      * @since 1.0.3
      +223      */
      +224     this.sha256 = function(s) {
      +225         var md = new KJUR.crypto.MessageDigest({'alg':'sha256', 'prov':'cryptojs'});
      +226         return md.digestString(s);
      +227     };
      +228 
      +229     this.sha256Hex = function(s) {
      +230         var md = new KJUR.crypto.MessageDigest({'alg':'sha256', 'prov':'cryptojs'});
      +231         return md.digestHex(s);
      +232     };
      +233 
      +234     /**
      +235      * get hexadecimal SHA512 hash of string
      +236      * @name sha512
      +237      * @memberOf KJUR.crypto.Util
      +238      * @function
      +239      * @param {String} s input string to be hashed
      +240      * @return {String} hexadecimal string of hash value
      +241      * @since 1.0.3
      +242      */
      +243     this.sha512 = function(s) {
      +244         var md = new KJUR.crypto.MessageDigest({'alg':'sha512', 'prov':'cryptojs'});
      +245         return md.digestString(s);
      +246     };
      +247 
      +248     this.sha512Hex = function(s) {
      +249         var md = new KJUR.crypto.MessageDigest({'alg':'sha512', 'prov':'cryptojs'});
      +250         return md.digestHex(s);
      +251     };
      +252 
      +253     /**
      +254      * get hexadecimal MD5 hash of string
      +255      * @name md5
      +256      * @memberOf KJUR.crypto.Util
      +257      * @function
      +258      * @param {String} s input string to be hashed
      +259      * @return {String} hexadecimal string of hash value
      +260      * @since 1.0.3
      +261      */
      +262     this.md5 = function(s) {
      +263         var md = new KJUR.crypto.MessageDigest({'alg':'md5', 'prov':'cryptojs'});
      +264         return md.digestString(s);
      +265     };
      +266 
      +267     /**
      +268      * get hexadecimal RIPEMD160 hash of string
      +269      * @name ripemd160
      +270      * @memberOf KJUR.crypto.Util
      +271      * @function
      +272      * @param {String} s input string to be hashed
      +273      * @return {String} hexadecimal string of hash value
      +274      * @since 1.0.3
      +275      */
      +276     this.ripemd160 = function(s) {
      +277         var md = new KJUR.crypto.MessageDigest({'alg':'ripemd160', 'prov':'cryptojs'});
      +278         return md.digestString(s);
      +279     };
      +280 
      +281     /*
      +282      * @since 1.1.2
      +283      */
      +284     this.getCryptoJSMDByName = function(s) {
      +285 	
      +286     };
      +287 };
      +288 
      +289 // === Mac ===============================================================
      +290 
      +291 /**
      +292  * MessageDigest class which is very similar to java.security.MessageDigest class<br/>
      +293  * @name KJUR.crypto.MessageDigest
      +294  * @class MessageDigest class which is very similar to java.security.MessageDigest class
      +295  * @param {Array} params parameters for constructor
      +296  * @property {Array} HASHLENGTH static Array of resulted byte length of hash (ex. HASHLENGTH["sha1"] == 20)
      +297  * @description
      +298  * <br/>
      +299  * Currently this supports following algorithm and providers combination:
      +300  * <ul>
      +301  * <li>md5 - cryptojs</li>
      +302  * <li>sha1 - cryptojs</li>
      +303  * <li>sha224 - cryptojs</li>
      +304  * <li>sha256 - cryptojs</li>
      +305  * <li>sha384 - cryptojs</li>
      +306  * <li>sha512 - cryptojs</li>
      +307  * <li>ripemd160 - cryptojs</li>
      +308  * <li>sha256 - sjcl (NEW from crypto.js 1.0.4)</li>
      +309  * </ul>
      +310  * @example
      +311  * // CryptoJS provider sample
      +312  * var md = new KJUR.crypto.MessageDigest({alg: "sha1", prov: "cryptojs"});
      +313  * md.updateString('aaa')
      +314  * var mdHex = md.digest()
      +315  *
      +316  * // SJCL(Stanford JavaScript Crypto Library) provider sample
      +317  * var md = new KJUR.crypto.MessageDigest({alg: "sha256", prov: "sjcl"}); // sjcl supports sha256 only
      +318  * md.updateString('aaa')
      +319  * var mdHex = md.digest()
      +320  *
      +321  * // HASHLENGTH property
      +322  * KJUR.crypto.MessageDigest.HASHLENGTH['sha1'] &rarr 20
      +323  * KJUR.crypto.MessageDigest.HASHLENGTH['sha512'] &rarr 64
      +324  */
      +325 KJUR.crypto.MessageDigest = function(params) {
      +326     var md = null;
      +327     var algName = null;
      +328     var provName = null;
      +329 
      +330     /**
      +331      * set hash algorithm and provider<br/>
      +332      * @name setAlgAndProvider
      +333      * @memberOf KJUR.crypto.MessageDigest#
      +334      * @function
      +335      * @param {String} alg hash algorithm name
      +336      * @param {String} prov provider name
      +337      * @description
      +338      * This methods set an algorithm and a cryptographic provider.<br/>
      +339      * Here is acceptable algorithm names ignoring cases and hyphens:
      +340      * <ul>
      +341      * <li>MD5</li>
      +342      * <li>SHA1</li>
      +343      * <li>SHA224</li>
      +344      * <li>SHA256</li>
      +345      * <li>SHA384</li>
      +346      * <li>SHA512</li>
      +347      * <li>RIPEMD160</li>
      +348      * </ul>
      +349      * NOTE: Since jsrsasign 6.2.0 crypto 1.1.10, this method ignores
      +350      * upper or lower cases. Also any hyphens (i.e. "-") will be ignored
      +351      * so that "SHA1" or "SHA-1" will be acceptable.
      +352      * @example
      +353      * // for SHA1
      +354      * md.setAlgAndProvider('sha1', 'cryptojs');
      +355      * md.setAlgAndProvider('SHA1');
      +356      * // for RIPEMD160
      +357      * md.setAlgAndProvider('ripemd160', 'cryptojs');
      +358      */
      +359     this.setAlgAndProvider = function(alg, prov) {
      +360 	alg = KJUR.crypto.MessageDigest.getCanonicalAlgName(alg);
      +361 
      +362 	if (alg !== null && prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg];
      +363 
      +364 	// for cryptojs
      +365 	if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(alg) != -1 &&
      +366 	    prov == 'cryptojs') {
      +367 	    try {
      +368 		this.md = KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[alg].create();
      +369 	    } catch (ex) {
      +370 		throw "setAlgAndProvider hash alg set fail alg=" + alg + "/" + ex;
      +371 	    }
      +372 	    this.updateString = function(str) {
      +373 		this.md.update(str);
      +374 	    };
      +375 	    this.updateHex = function(hex) {
      +376 		var wHex = CryptoJS.enc.Hex.parse(hex);
      +377 		this.md.update(wHex);
      +378 	    };
      +379 	    this.digest = function() {
      +380 		var hash = this.md.finalize();
      +381 		return hash.toString(CryptoJS.enc.Hex);
      +382 	    };
      +383 	    this.digestString = function(str) {
      +384 		this.updateString(str);
      +385 		return this.digest();
      +386 	    };
      +387 	    this.digestHex = function(hex) {
      +388 		this.updateHex(hex);
      +389 		return this.digest();
      +390 	    };
      +391 	}
      +392 	if (':sha256:'.indexOf(alg) != -1 &&
      +393 	    prov == 'sjcl') {
      +394 	    try {
      +395 		this.md = new sjcl.hash.sha256();
      +396 	    } catch (ex) {
      +397 		throw "setAlgAndProvider hash alg set fail alg=" + alg + "/" + ex;
      +398 	    }
      +399 	    this.updateString = function(str) {
      +400 		this.md.update(str);
      +401 	    };
      +402 	    this.updateHex = function(hex) {
      +403 		var baHex = sjcl.codec.hex.toBits(hex);
      +404 		this.md.update(baHex);
      +405 	    };
      +406 	    this.digest = function() {
      +407 		var hash = this.md.finalize();
      +408 		return sjcl.codec.hex.fromBits(hash);
      +409 	    };
      +410 	    this.digestString = function(str) {
      +411 		this.updateString(str);
      +412 		return this.digest();
      +413 	    };
      +414 	    this.digestHex = function(hex) {
      +415 		this.updateHex(hex);
      +416 		return this.digest();
      +417 	    };
      +418 	}
      +419     };
      +420 
      +421     /**
      +422      * update digest by specified string
      +423      * @name updateString
      +424      * @memberOf KJUR.crypto.MessageDigest#
      +425      * @function
      +426      * @param {String} str string to update
      +427      * @description
      +428      * @example
      +429      * md.updateString('New York');
      +430      */
      +431     this.updateString = function(str) {
      +432 	throw "updateString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      +433     };
      +434 
      +435     /**
      +436      * update digest by specified hexadecimal string
      +437      * @name updateHex
      +438      * @memberOf KJUR.crypto.MessageDigest#
      +439      * @function
      +440      * @param {String} hex hexadecimal string to update
      +441      * @description
      +442      * @example
      +443      * md.updateHex('0afe36');
      +444      */
      +445     this.updateHex = function(hex) {
      +446 	throw "updateHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      +447     };
      +448 
      +449     /**
      +450      * completes hash calculation and returns hash result
      +451      * @name digest
      +452      * @memberOf KJUR.crypto.MessageDigest
      +453      * @function
      +454      * @description
      +455      * @example
      +456      * md.digest()
      +457      */
      +458     this.digest = function() {
      +459 	throw "digest() not supported for this alg/prov: " + this.algName + "/" + this.provName;
      +460     };
      +461 
      +462     /**
      +463      * performs final update on the digest using string, then completes the digest computation
      +464      * @name digestString
      +465      * @memberOf KJUR.crypto.MessageDigest#
      +466      * @function
      +467      * @param {String} str string to final update
      +468      * @description
      +469      * @example
      +470      * md.digestString('aaa')
      +471      */
      +472     this.digestString = function(str) {
      +473 	throw "digestString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      +474     };
      +475 
      +476     /**
      +477      * performs final update on the digest using hexadecimal string, then completes the digest computation
      +478      * @name digestHex
      +479      * @memberOf KJUR.crypto.MessageDigest#
      +480      * @function
      +481      * @param {String} hex hexadecimal string to final update
      +482      * @description
      +483      * @example
      +484      * md.digestHex('0f2abd')
      +485      */
      +486     this.digestHex = function(hex) {
      +487 	throw "digestHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName;
      +488     };
      +489 
      +490     if (params !== undefined) {
      +491 	if (params['alg'] !== undefined) {
      +492 	    this.algName = params['alg'];
      +493 	    if (params['prov'] === undefined)
      +494 		this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName];
      +495 	    this.setAlgAndProvider(this.algName, this.provName);
      +496 	}
      +497     }
      +498 };
      +499 
      +500 /**
      +501  * get canonical hash algorithm name<br/>
      +502  * @name getCanonicalAlgName
      +503  * @memberOf KJUR.crypto.MessageDigest
      +504  * @function
      +505  * @param {String} alg hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.)
      +506  * @return {String} canonical hash algorithm name
      +507  * @since jsrsasign 6.2.0 crypto 1.1.10
      +508  * @description
      +509  * This static method normalizes from any hash algorithm name such as
      +510  * "SHA-1", "SHA1", "MD5", "sha512" to lower case name without hyphens
      +511  * such as "sha1".
      +512  * @example
      +513  * KJUR.crypto.MessageDigest.getCanonicalAlgName("SHA-1") &rarr "sha1"
      +514  * KJUR.crypto.MessageDigest.getCanonicalAlgName("MD5")   &rarr "md5"
      +515  */
      +516 KJUR.crypto.MessageDigest.getCanonicalAlgName = function(alg) {
      +517     if (typeof alg === "string") {
      +518 	alg = alg.toLowerCase();
      +519 	alg = alg.replace(/-/, '');
      +520     }
      +521     return alg;
      +522 };
       523 
      -524 	alg = alg.toLowerCase();
      -525         if (alg.substr(0, 4) != "hmac") {
      -526 	    throw "setAlgAndProvider unsupported HMAC alg: " + alg;
      -527 	}
      -528 
      -529 	if (prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg];
      -530 	this.algProv = alg + "/" + prov;
      -531 
      -532 	var hashAlg = alg.substr(4);
      -533 
      -534 	// for cryptojs
      -535 	if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(hashAlg) != -1 &&
      -536 	    prov == 'cryptojs') {
      -537 	    try {
      -538 		var mdObj = KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[hashAlg];
      -539 		this.mac = CryptoJS.algo.HMAC.create(mdObj, this.pass);
      -540 	    } catch (ex) {
      -541 		throw "setAlgAndProvider hash alg set fail hashAlg=" + hashAlg + "/" + ex;
      -542 	    }
      -543 	    this.updateString = function(str) {
      -544 		this.mac.update(str);
      -545 	    };
      -546 	    this.updateHex = function(hex) {
      -547 		var wHex = CryptoJS.enc.Hex.parse(hex);
      -548 		this.mac.update(wHex);
      -549 	    };
      -550 	    this.doFinal = function() {
      -551 		var hash = this.mac.finalize();
      -552 		return hash.toString(CryptoJS.enc.Hex);
      -553 	    };
      -554 	    this.doFinalString = function(str) {
      -555 		this.updateString(str);
      -556 		return this.doFinal();
      -557 	    };
      -558 	    this.doFinalHex = function(hex) {
      -559 		this.updateHex(hex);
      -560 		return this.doFinal();
      -561 	    };
      -562 	}
      -563     };
      -564 
      -565     /**
      -566      * update digest by specified string
      -567      * @name updateString
      -568      * @memberOf KJUR.crypto.Mac
      -569      * @function
      -570      * @param {String} str string to update
      -571      * @description
      -572      * @example
      -573      * md.updateString('New York');
      -574      */
      -575     this.updateString = function(str) {
      -576 	throw "updateString(str) not supported for this alg/prov: " + this.algProv;
      -577     };
      -578 
      -579     /**
      -580      * update digest by specified hexadecimal string
      -581      * @name updateHex
      -582      * @memberOf KJUR.crypto.Mac
      -583      * @function
      -584      * @param {String} hex hexadecimal string to update
      -585      * @description
      -586      * @example
      -587      * md.updateHex('0afe36');
      -588      */
      -589     this.updateHex = function(hex) {
      -590 	throw "updateHex(hex) not supported for this alg/prov: " + this.algProv;
      -591     };
      -592 
      -593     /**
      -594      * completes hash calculation and returns hash result
      -595      * @name doFinal
      -596      * @memberOf KJUR.crypto.Mac
      -597      * @function
      -598      * @description
      -599      * @example
      -600      * md.digest()
      -601      */
      -602     this.doFinal = function() {
      -603 	throw "digest() not supported for this alg/prov: " + this.algProv;
      -604     };
      +524 /**
      +525  * get resulted hash byte length for specified algorithm name<br/>
      +526  * @name getHashLength
      +527  * @memberOf KJUR.crypto.MessageDigest
      +528  * @function
      +529  * @param {String} alg non-canonicalized hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.)
      +530  * @return {Integer} resulted hash byte length
      +531  * @since jsrsasign 6.2.0 crypto 1.1.10
      +532  * @description
      +533  * This static method returns resulted byte length for specified algorithm name such as "SHA-1".
      +534  * @example
      +535  * KJUR.crypto.MessageDigest.getHashLength("SHA-1") &rarr 20
      +536  * KJUR.crypto.MessageDigest.getHashLength("sha1") &rarr 20
      +537  */
      +538 KJUR.crypto.MessageDigest.getHashLength = function(alg) {
      +539     var MD = KJUR.crypto.MessageDigest
      +540     var alg2 = MD.getCanonicalAlgName(alg);
      +541     if (MD.HASHLENGTH[alg2] === undefined)
      +542 	throw "not supported algorithm: " + alg;
      +543     return MD.HASHLENGTH[alg2];
      +544 };
      +545 
      +546 // described in KJUR.crypto.MessageDigest class (since jsrsasign 6.2.0 crypto 1.1.10)
      +547 KJUR.crypto.MessageDigest.HASHLENGTH = {
      +548     'md5':		16,
      +549     'sha1':		20,
      +550     'sha224':		28,
      +551     'sha256':		32,
      +552     'sha384':		48,
      +553     'sha512':		64,
      +554     'ripemd160':	20
      +555 };
      +556 
      +557 // === Mac ===============================================================
      +558 
      +559 /**
      +560  * Mac(Message Authentication Code) class which is very similar to java.security.Mac class 
      +561  * @name KJUR.crypto.Mac
      +562  * @class Mac class which is very similar to java.security.Mac class
      +563  * @param {Array} params parameters for constructor
      +564  * @description
      +565  * <br/>
      +566  * Currently this supports following algorithm and providers combination:
      +567  * <ul>
      +568  * <li>hmacmd5 - cryptojs</li>
      +569  * <li>hmacsha1 - cryptojs</li>
      +570  * <li>hmacsha224 - cryptojs</li>
      +571  * <li>hmacsha256 - cryptojs</li>
      +572  * <li>hmacsha384 - cryptojs</li>
      +573  * <li>hmacsha512 - cryptojs</li>
      +574  * </ul>
      +575  * NOTE: HmacSHA224 and HmacSHA384 issue was fixed since jsrsasign 4.1.4.
      +576  * Please use 'ext/cryptojs-312-core-fix*.js' instead of 'core.js' of original CryptoJS
      +577  * to avoid those issue.
      +578  * <br/>
      +579  * NOTE2: Hmac signature bug was fixed in jsrsasign 4.9.0 by providing CryptoJS
      +580  * bug workaround.
      +581  * <br/>
      +582  * Please see {@link KJUR.crypto.Mac.setPassword}, how to provide password
      +583  * in various ways in detail.
      +584  * @example
      +585  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA1", "pass": "pass"});
      +586  * mac.updateString('aaa')
      +587  * var macHex = md.doFinal()
      +588  *
      +589  * // other password representation 
      +590  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"hex":  "6161"}});
      +591  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"utf8": "aa"}});
      +592  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"rstr": "\x61\x61"}});
      +593  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64":  "Mi02/+...a=="}});
      +594  * var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64u": "Mi02_-...a"}});
      +595  */
      +596 KJUR.crypto.Mac = function(params) {
      +597     var mac = null;
      +598     var pass = null;
      +599     var algName = null;
      +600     var provName = null;
      +601     var algProv = null;
      +602 
      +603     this.setAlgAndProvider = function(alg, prov) {
      +604 	alg = alg.toLowerCase();
       605 
      -606     /**
      -607      * performs final update on the digest using string, then completes the digest computation
      -608      * @name doFinalString
      -609      * @memberOf KJUR.crypto.Mac
      -610      * @function
      -611      * @param {String} str string to final update
      -612      * @description
      -613      * @example
      -614      * md.digestString('aaa')
      -615      */
      -616     this.doFinalString = function(str) {
      -617 	throw "digestString(str) not supported for this alg/prov: " + this.algProv;
      -618     };
      -619 
      -620     /**
      -621      * performs final update on the digest using hexadecimal string, 
      -622      * then completes the digest computation
      -623      * @name doFinalHex
      -624      * @memberOf KJUR.crypto.Mac
      -625      * @function
      -626      * @param {String} hex hexadecimal string to final update
      -627      * @description
      -628      * @example
      -629      * md.digestHex('0f2abd')
      -630      */
      -631     this.doFinalHex = function(hex) {
      -632 	throw "digestHex(hex) not supported for this alg/prov: " + this.algProv;
      -633     };
      -634 
      -635     /**
      -636      * set password for Mac
      -637      * @name setPassword
      -638      * @memberOf KJUR.crypto.Mac
      -639      * @function
      -640      * @param {Object} pass password for Mac
      -641      * @since crypto 1.1.7 jsrsasign 4.9.0
      -642      * @description
      -643      * This method will set password for (H)Mac internally.
      -644      * Argument 'pass' can be specified as following:
      -645      * <ul>
      -646      * <li>even length string of 0..9, a..f or A-F: implicitly specified as hexadecimal string</li>
      -647      * <li>not above string: implicitly specified as raw string</li>
      -648      * <li>{rstr: "\x65\x70"}: explicitly specified as raw string</li>
      -649      * <li>{hex: "6570"}: explicitly specified as hexacedimal string</li>
      -650      * <li>{utf8: "秘密"}: explicitly specified as UTF8 string</li>
      -651      * <li>{b64: "Mi78..=="}: explicitly specified as Base64 string</li>
      -652      * <li>{b64u: "Mi7-_"}: explicitly specified as Base64URL string</li>
      -653      * </ul>
      -654      * It is *STRONGLY RECOMMENDED* that explicit representation of password argument
      -655      * to avoid ambiguity. For example string  "6161" can mean a string "6161" or 
      -656      * a hexadecimal string of "aa" (i.e. \x61\x61).
      -657      * @example
      -658      * mac = KJUR.crypto.Mac({'alg': 'hmacsha256'});
      -659      * // set password by implicit raw string
      -660      * mac.setPassword("\x65\x70\xb9\x0b");
      -661      * mac.setPassword("password");
      -662      * // set password by implicit hexadecimal string
      -663      * mac.setPassword("6570b90b");
      -664      * mac.setPassword("6570B90B");
      -665      * // set password by explicit raw string
      -666      * mac.setPassword({"rstr": "\x65\x70\xb9\x0b"});
      -667      * // set password by explicit hexadecimal string
      -668      * mac.setPassword({"hex": "6570b90b"});
      -669      * // set password by explicit utf8 string
      -670      * mac.setPassword({"utf8": "passwordパスワード");
      -671      * // set password by explicit Base64 string
      -672      * mac.setPassword({"b64": "Mb+c3f/=="});
      -673      * // set password by explicit Base64URL string
      -674      * mac.setPassword({"b64u": "Mb-c3f_"});
      -675      */
      -676     this.setPassword = function(pass) {
      -677 	// internal this.pass shall be CryptoJS DWord Object for CryptoJS bug
      -678 	// work around. CrytoJS HMac password can be passed by
      -679 	// raw string as described in the manual however it doesn't
      -680 	// work properly in some case. If password was passed
      -681 	// by CryptoJS DWord which is not described in the manual
      -682 	// it seems to work. (fixed since crypto 1.1.7)
      -683 
      -684 	if (typeof pass == 'string') {
      -685 	    var hPass = pass;
      -686 	    if (pass.length % 2 == 1 || ! pass.match(/^[0-9A-Fa-f]+$/)) { // raw str
      -687 		hPass = rstrtohex(pass);
      -688 	    }
      -689 	    this.pass = CryptoJS.enc.Hex.parse(hPass);
      -690 	    return;
      -691 	}
      -692 
      -693 	if (typeof pass != 'object')
      -694 	    throw "KJUR.crypto.Mac unsupported password type: " + pass;
      -695 	
      -696 	var hPass = null;
      -697 	if (pass.hex  !== undefined) {
      -698 	    if (pass.hex.length % 2 != 0 || ! pass.hex.match(/^[0-9A-Fa-f]+$/))
      -699 		throw "Mac: wrong hex password: " + pass.hex;
      -700 	    hPass = pass.hex;
      -701 	}
      -702 	if (pass.utf8 !== undefined) hPass = utf8tohex(pass.utf8);
      -703 	if (pass.rstr !== undefined) hPass = rstrtohex(pass.rstr);
      -704 	if (pass.b64  !== undefined) hPass = b64tohex(pass.b64);
      -705 	if (pass.b64u !== undefined) hPass = b64utohex(pass.b64u);
      -706 
      -707 	if (hPass == null)
      -708 	    throw "KJUR.crypto.Mac unsupported password type: " + pass;
      -709 
      -710 	this.pass = CryptoJS.enc.Hex.parse(hPass);
      -711     };
      -712 
      -713     if (params !== undefined) {
      -714 	if (params.pass !== undefined) {
      -715 	    this.setPassword(params.pass);
      -716 	}
      -717 	if (params.alg !== undefined) {
      -718 	    this.algName = params.alg;
      -719 	    if (params['prov'] === undefined)
      -720 		this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName];
      -721 	    this.setAlgAndProvider(this.algName, this.provName);
      -722 	}
      -723     }
      -724 };
      -725 
      -726 /**
      -727  * Signature class which is very similar to java.security.Signature class
      -728  * @name KJUR.crypto.Signature
      -729  * @class Signature class which is very similar to java.security.Signature class
      -730  * @param {Array} params parameters for constructor
      -731  * @property {String} state Current state of this signature object whether 'SIGN', 'VERIFY' or null
      -732  * @description
      -733  * <br/>
      -734  * As for params of constructor's argument, it can be specify following attributes:
      -735  * <ul>
      -736  * <li>alg - signature algorithm name (ex. {MD5,SHA1,SHA224,SHA256,SHA384,SHA512,RIPEMD160}with{RSA,ECDSA,DSA})</li>
      -737  * <li>provider - currently 'cryptojs/jsrsa' only</li>
      -738  * </ul>
      -739  * <h4>SUPPORTED ALGORITHMS AND PROVIDERS</h4>
      -740  * This Signature class supports following signature algorithm and provider names:
      -741  * <ul>
      -742  * <li>MD5withRSA - cryptojs/jsrsa</li>
      -743  * <li>SHA1withRSA - cryptojs/jsrsa</li>
      -744  * <li>SHA224withRSA - cryptojs/jsrsa</li>
      -745  * <li>SHA256withRSA - cryptojs/jsrsa</li>
      -746  * <li>SHA384withRSA - cryptojs/jsrsa</li>
      -747  * <li>SHA512withRSA - cryptojs/jsrsa</li>
      -748  * <li>RIPEMD160withRSA - cryptojs/jsrsa</li>
      -749  * <li>MD5withECDSA - cryptojs/jsrsa</li>
      -750  * <li>SHA1withECDSA - cryptojs/jsrsa</li>
      -751  * <li>SHA224withECDSA - cryptojs/jsrsa</li>
      -752  * <li>SHA256withECDSA - cryptojs/jsrsa</li>
      -753  * <li>SHA384withECDSA - cryptojs/jsrsa</li>
      -754  * <li>SHA512withECDSA - cryptojs/jsrsa</li>
      -755  * <li>RIPEMD160withECDSA - cryptojs/jsrsa</li>
      -756  * <li>MD5withRSAandMGF1 - cryptojs/jsrsa</li>
      -757  * <li>SHA1withRSAandMGF1 - cryptojs/jsrsa</li>
      -758  * <li>SHA224withRSAandMGF1 - cryptojs/jsrsa</li>
      -759  * <li>SHA256withRSAandMGF1 - cryptojs/jsrsa</li>
      -760  * <li>SHA384withRSAandMGF1 - cryptojs/jsrsa</li>
      -761  * <li>SHA512withRSAandMGF1 - cryptojs/jsrsa</li>
      -762  * <li>RIPEMD160withRSAandMGF1 - cryptojs/jsrsa</li>
      -763  * <li>SHA1withDSA - cryptojs/jsrsa</li>
      -764  * <li>SHA224withDSA - cryptojs/jsrsa</li>
      -765  * <li>SHA256withDSA - cryptojs/jsrsa</li>
      -766  * </ul>
      -767  * Here are supported elliptic cryptographic curve names and their aliases for ECDSA:
      -768  * <ul>
      -769  * <li>secp256k1</li>
      -770  * <li>secp256r1, NIST P-256, P-256, prime256v1</li>
      -771  * <li>secp384r1, NIST P-384, P-384</li>
      -772  * </ul>
      -773  * NOTE1: DSA signing algorithm is also supported since crypto 1.1.5.
      -774  * <h4>EXAMPLES</h4>
      -775  * @example
      -776  * // RSA signature generation
      -777  * var sig = new KJUR.crypto.Signature({"alg": "SHA1withRSA"});
      -778  * sig.init(prvKeyPEM);
      -779  * sig.updateString('aaa');
      -780  * var hSigVal = sig.sign();
      -781  *
      -782  * // DSA signature validation
      -783  * var sig2 = new KJUR.crypto.Signature({"alg": "SHA1withDSA"});
      -784  * sig2.init(certPEM);
      -785  * sig.updateString('aaa');
      -786  * var isValid = sig2.verify(hSigVal);
      -787  * 
      -788  * // ECDSA signing
      -789  * var sig = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'});
      -790  * sig.init(prvKeyPEM);
      -791  * sig.updateString('aaa');
      -792  * var sigValueHex = sig.sign();
      -793  *
      -794  * // ECDSA verifying
      -795  * var sig2 = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'});
      -796  * sig.init(certPEM);
      -797  * sig.updateString('aaa');
      -798  * var isValid = sig.verify(sigValueHex);
      -799  */
      -800 KJUR.crypto.Signature = function(params) {
      -801     var prvKey = null; // RSAKey/KJUR.crypto.{ECDSA,DSA} object for signing
      -802     var pubKey = null; // RSAKey/KJUR.crypto.{ECDSA,DSA} object for verifying
      -803 
      -804     var md = null; // KJUR.crypto.MessageDigest object
      -805     var sig = null;
      -806     var algName = null;
      -807     var provName = null;
      -808     var algProvName = null;
      -809     var mdAlgName = null;
      -810     var pubkeyAlgName = null;	// rsa,ecdsa,rsaandmgf1(=rsapss)
      -811     var state = null;
      -812     var pssSaltLen = -1;
      -813     var initParams = null;
      -814 
      -815     var sHashHex = null; // hex hash value for hex
      -816     var hDigestInfo = null;
      -817     var hPaddedDigestInfo = null;
      -818     var hSign = null;
      -819 
      -820     this._setAlgNames = function() {
      -821     var matchResult = this.algName.match(/^(.+)with(.+)$/);
      -822 	if (matchResult) {
      -823 	    this.mdAlgName = matchResult[1].toLowerCase();
      -824 	    this.pubkeyAlgName = matchResult[2].toLowerCase();
      -825 	}
      -826     };
      -827 
      -828     this._zeroPaddingOfSignature = function(hex, bitLength) {
      -829 	var s = "";
      -830 	var nZero = bitLength / 4 - hex.length;
      -831 	for (var i = 0; i < nZero; i++) {
      -832 	    s = s + "0";
      -833 	}
      -834 	return s + hex;
      -835     };
      -836 
      -837     /**
      -838      * set signature algorithm and provider
      -839      * @name setAlgAndProvider
      -840      * @memberOf KJUR.crypto.Signature
      -841      * @function
      -842      * @param {String} alg signature algorithm name
      -843      * @param {String} prov provider name
      -844      * @description
      -845      * @example
      -846      * md.setAlgAndProvider('SHA1withRSA', 'cryptojs/jsrsa');
      -847      */
      -848     this.setAlgAndProvider = function(alg, prov) {
      -849 	this._setAlgNames();
      -850 	if (prov != 'cryptojs/jsrsa')
      -851 	    throw "provider not supported: " + prov;
      -852 
      -853 	if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(this.mdAlgName) != -1) {
      -854 	    try {
      -855 		this.md = new KJUR.crypto.MessageDigest({'alg':this.mdAlgName});
      -856 	    } catch (ex) {
      -857 		throw "setAlgAndProvider hash alg set fail alg=" +
      -858                       this.mdAlgName + "/" + ex;
      -859 	    }
      -860 
      -861 	    this.init = function(keyparam, pass) {
      -862 		var keyObj = null;
      -863 		try {
      -864 		    if (pass === undefined) {
      -865 			keyObj = KEYUTIL.getKey(keyparam);
      -866 		    } else {
      -867 			keyObj = KEYUTIL.getKey(keyparam, pass);
      -868 		    }
      -869 		} catch (ex) {
      -870 		    throw "init failed:" + ex;
      -871 		}
      -872 
      -873 		if (keyObj.isPrivate === true) {
      -874 		    this.prvKey = keyObj;
      -875 		    this.state = "SIGN";
      -876 		} else if (keyObj.isPublic === true) {
      -877 		    this.pubKey = keyObj;
      -878 		    this.state = "VERIFY";
      -879 		} else {
      -880 		    throw "init failed.:" + keyObj;
      -881 		}
      -882 	    };
      -883 
      -884 	    this.initSign = function(params) {
      -885 		if (typeof params['ecprvhex'] == 'string' &&
      -886                     typeof params['eccurvename'] == 'string') {
      -887 		    this.ecprvhex = params['ecprvhex'];
      -888 		    this.eccurvename = params['eccurvename'];
      -889 		} else {
      -890 		    this.prvKey = params;
      -891 		}
      -892 		this.state = "SIGN";
      -893 	    };
      -894 
      -895 	    this.initVerifyByPublicKey = function(params) {
      -896 		if (typeof params['ecpubhex'] == 'string' &&
      -897 		    typeof params['eccurvename'] == 'string') {
      -898 		    this.ecpubhex = params['ecpubhex'];
      -899 		    this.eccurvename = params['eccurvename'];
      -900 		} else if (params instanceof KJUR.crypto.ECDSA) {
      -901 		    this.pubKey = params;
      -902 		} else if (params instanceof RSAKey) {
      -903 		    this.pubKey = params;
      -904 		}
      -905 		this.state = "VERIFY";
      -906 	    };
      -907 
      -908 	    this.initVerifyByCertificatePEM = function(certPEM) {
      -909 		var x509 = new X509();
      -910 		x509.readCertPEM(certPEM);
      -911 		this.pubKey = x509.subjectPublicKeyRSA;
      -912 		this.state = "VERIFY";
      -913 	    };
      -914 
      -915 	    this.updateString = function(str) {
      -916 		this.md.updateString(str);
      -917 	    };
      -918 
      -919 	    this.updateHex = function(hex) {
      -920 		this.md.updateHex(hex);
      -921 	    };
      -922 
      -923 	    this.sign = function() {
      -924 		this.sHashHex = this.md.digest();
      -925 		if (typeof this.ecprvhex != "undefined" &&
      -926 		    typeof this.eccurvename != "undefined") {
      -927 		    var ec = new KJUR.crypto.ECDSA({'curve': this.eccurvename});
      -928 		    this.hSign = ec.signHex(this.sHashHex, this.ecprvhex);
      -929 		} else if (this.prvKey instanceof RSAKey &&
      -930 		           this.pubkeyAlgName == "rsaandmgf1") {
      -931 		    this.hSign = this.prvKey.signWithMessageHashPSS(this.sHashHex,
      -932 								    this.mdAlgName,
      -933 								    this.pssSaltLen);
      -934 		} else if (this.prvKey instanceof RSAKey &&
      -935 			   this.pubkeyAlgName == "rsa") {
      -936 		    this.hSign = this.prvKey.signWithMessageHash(this.sHashHex,
      -937 								 this.mdAlgName);
      -938 		} else if (this.prvKey instanceof KJUR.crypto.ECDSA) {
      -939 		    this.hSign = this.prvKey.signWithMessageHash(this.sHashHex);
      -940 		} else if (this.prvKey instanceof KJUR.crypto.DSA) {
      -941 		    this.hSign = this.prvKey.signWithMessageHash(this.sHashHex);
      -942 		} else {
      -943 		    throw "Signature: unsupported public key alg: " + this.pubkeyAlgName;
      -944 		}
      -945 		return this.hSign;
      -946 	    };
      -947 	    this.signString = function(str) {
      -948 		this.updateString(str);
      -949 		return this.sign();
      -950 	    };
      -951 	    this.signHex = function(hex) {
      -952 		this.updateHex(hex);
      -953 		return this.sign();
      -954 	    };
      -955 	    this.verify = function(hSigVal) {
      -956 	        this.sHashHex = this.md.digest();
      -957 		if (typeof this.ecpubhex != "undefined" &&
      -958 		    typeof this.eccurvename != "undefined") {
      -959 		    var ec = new KJUR.crypto.ECDSA({curve: this.eccurvename});
      -960 		    return ec.verifyHex(this.sHashHex, hSigVal, this.ecpubhex);
      -961 		} else if (this.pubKey instanceof RSAKey &&
      -962 			   this.pubkeyAlgName == "rsaandmgf1") {
      -963 		    return this.pubKey.verifyWithMessageHashPSS(this.sHashHex, hSigVal, 
      -964 								this.mdAlgName,
      -965 								this.pssSaltLen);
      -966 		} else if (this.pubKey instanceof RSAKey &&
      -967 			   this.pubkeyAlgName == "rsa") {
      -968 		    return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal);
      -969 		} else if (this.pubKey instanceof KJUR.crypto.ECDSA) {
      -970 		    return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal);
      -971 		} else if (this.pubKey instanceof KJUR.crypto.DSA) {
      -972 		    return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal);
      -973 		} else {
      -974 		    throw "Signature: unsupported public key alg: " + this.pubkeyAlgName;
      -975 		}
      -976 	    };
      -977 	}
      -978     };
      +606 	if (alg == null) alg = "hmacsha1";
      +607 
      +608 	alg = alg.toLowerCase();
      +609         if (alg.substr(0, 4) != "hmac") {
      +610 	    throw "setAlgAndProvider unsupported HMAC alg: " + alg;
      +611 	}
      +612 
      +613 	if (prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg];
      +614 	this.algProv = alg + "/" + prov;
      +615 
      +616 	var hashAlg = alg.substr(4);
      +617 
      +618 	// for cryptojs
      +619 	if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(hashAlg) != -1 &&
      +620 	    prov == 'cryptojs') {
      +621 	    try {
      +622 		var mdObj = KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[hashAlg];
      +623 		this.mac = CryptoJS.algo.HMAC.create(mdObj, this.pass);
      +624 	    } catch (ex) {
      +625 		throw "setAlgAndProvider hash alg set fail hashAlg=" + hashAlg + "/" + ex;
      +626 	    }
      +627 	    this.updateString = function(str) {
      +628 		this.mac.update(str);
      +629 	    };
      +630 	    this.updateHex = function(hex) {
      +631 		var wHex = CryptoJS.enc.Hex.parse(hex);
      +632 		this.mac.update(wHex);
      +633 	    };
      +634 	    this.doFinal = function() {
      +635 		var hash = this.mac.finalize();
      +636 		return hash.toString(CryptoJS.enc.Hex);
      +637 	    };
      +638 	    this.doFinalString = function(str) {
      +639 		this.updateString(str);
      +640 		return this.doFinal();
      +641 	    };
      +642 	    this.doFinalHex = function(hex) {
      +643 		this.updateHex(hex);
      +644 		return this.doFinal();
      +645 	    };
      +646 	}
      +647     };
      +648 
      +649     /**
      +650      * update digest by specified string
      +651      * @name updateString
      +652      * @memberOf KJUR.crypto.Mac
      +653      * @function
      +654      * @param {String} str string to update
      +655      * @description
      +656      * @example
      +657      * md.updateString('New York');
      +658      */
      +659     this.updateString = function(str) {
      +660 	throw "updateString(str) not supported for this alg/prov: " + this.algProv;
      +661     };
      +662 
      +663     /**
      +664      * update digest by specified hexadecimal string
      +665      * @name updateHex
      +666      * @memberOf KJUR.crypto.Mac
      +667      * @function
      +668      * @param {String} hex hexadecimal string to update
      +669      * @description
      +670      * @example
      +671      * md.updateHex('0afe36');
      +672      */
      +673     this.updateHex = function(hex) {
      +674 	throw "updateHex(hex) not supported for this alg/prov: " + this.algProv;
      +675     };
      +676 
      +677     /**
      +678      * completes hash calculation and returns hash result
      +679      * @name doFinal
      +680      * @memberOf KJUR.crypto.Mac
      +681      * @function
      +682      * @description
      +683      * @example
      +684      * md.digest()
      +685      */
      +686     this.doFinal = function() {
      +687 	throw "digest() not supported for this alg/prov: " + this.algProv;
      +688     };
      +689 
      +690     /**
      +691      * performs final update on the digest using string, then completes the digest computation
      +692      * @name doFinalString
      +693      * @memberOf KJUR.crypto.Mac
      +694      * @function
      +695      * @param {String} str string to final update
      +696      * @description
      +697      * @example
      +698      * md.digestString('aaa')
      +699      */
      +700     this.doFinalString = function(str) {
      +701 	throw "digestString(str) not supported for this alg/prov: " + this.algProv;
      +702     };
      +703 
      +704     /**
      +705      * performs final update on the digest using hexadecimal string, 
      +706      * then completes the digest computation
      +707      * @name doFinalHex
      +708      * @memberOf KJUR.crypto.Mac
      +709      * @function
      +710      * @param {String} hex hexadecimal string to final update
      +711      * @description
      +712      * @example
      +713      * md.digestHex('0f2abd')
      +714      */
      +715     this.doFinalHex = function(hex) {
      +716 	throw "digestHex(hex) not supported for this alg/prov: " + this.algProv;
      +717     };
      +718 
      +719     /**
      +720      * set password for Mac
      +721      * @name setPassword
      +722      * @memberOf KJUR.crypto.Mac
      +723      * @function
      +724      * @param {Object} pass password for Mac
      +725      * @since crypto 1.1.7 jsrsasign 4.9.0
      +726      * @description
      +727      * This method will set password for (H)Mac internally.
      +728      * Argument 'pass' can be specified as following:
      +729      * <ul>
      +730      * <li>even length string of 0..9, a..f or A-F: implicitly specified as hexadecimal string</li>
      +731      * <li>not above string: implicitly specified as raw string</li>
      +732      * <li>{rstr: "\x65\x70"}: explicitly specified as raw string</li>
      +733      * <li>{hex: "6570"}: explicitly specified as hexacedimal string</li>
      +734      * <li>{utf8: "秘密"}: explicitly specified as UTF8 string</li>
      +735      * <li>{b64: "Mi78..=="}: explicitly specified as Base64 string</li>
      +736      * <li>{b64u: "Mi7-_"}: explicitly specified as Base64URL string</li>
      +737      * </ul>
      +738      * It is *STRONGLY RECOMMENDED* that explicit representation of password argument
      +739      * to avoid ambiguity. For example string  "6161" can mean a string "6161" or 
      +740      * a hexadecimal string of "aa" (i.e. \x61\x61).
      +741      * @example
      +742      * mac = KJUR.crypto.Mac({'alg': 'hmacsha256'});
      +743      * // set password by implicit raw string
      +744      * mac.setPassword("\x65\x70\xb9\x0b");
      +745      * mac.setPassword("password");
      +746      * // set password by implicit hexadecimal string
      +747      * mac.setPassword("6570b90b");
      +748      * mac.setPassword("6570B90B");
      +749      * // set password by explicit raw string
      +750      * mac.setPassword({"rstr": "\x65\x70\xb9\x0b"});
      +751      * // set password by explicit hexadecimal string
      +752      * mac.setPassword({"hex": "6570b90b"});
      +753      * // set password by explicit utf8 string
      +754      * mac.setPassword({"utf8": "passwordパスワード");
      +755      * // set password by explicit Base64 string
      +756      * mac.setPassword({"b64": "Mb+c3f/=="});
      +757      * // set password by explicit Base64URL string
      +758      * mac.setPassword({"b64u": "Mb-c3f_"});
      +759      */
      +760     this.setPassword = function(pass) {
      +761 	// internal this.pass shall be CryptoJS DWord Object for CryptoJS bug
      +762 	// work around. CrytoJS HMac password can be passed by
      +763 	// raw string as described in the manual however it doesn't
      +764 	// work properly in some case. If password was passed
      +765 	// by CryptoJS DWord which is not described in the manual
      +766 	// it seems to work. (fixed since crypto 1.1.7)
      +767 
      +768 	if (typeof pass == 'string') {
      +769 	    var hPass = pass;
      +770 	    if (pass.length % 2 == 1 || ! pass.match(/^[0-9A-Fa-f]+$/)) { // raw str
      +771 		hPass = rstrtohex(pass);
      +772 	    }
      +773 	    this.pass = CryptoJS.enc.Hex.parse(hPass);
      +774 	    return;
      +775 	}
      +776 
      +777 	if (typeof pass != 'object')
      +778 	    throw "KJUR.crypto.Mac unsupported password type: " + pass;
      +779 	
      +780 	var hPass = null;
      +781 	if (pass.hex  !== undefined) {
      +782 	    if (pass.hex.length % 2 != 0 || ! pass.hex.match(/^[0-9A-Fa-f]+$/))
      +783 		throw "Mac: wrong hex password: " + pass.hex;
      +784 	    hPass = pass.hex;
      +785 	}
      +786 	if (pass.utf8 !== undefined) hPass = utf8tohex(pass.utf8);
      +787 	if (pass.rstr !== undefined) hPass = rstrtohex(pass.rstr);
      +788 	if (pass.b64  !== undefined) hPass = b64tohex(pass.b64);
      +789 	if (pass.b64u !== undefined) hPass = b64utohex(pass.b64u);
      +790 
      +791 	if (hPass == null)
      +792 	    throw "KJUR.crypto.Mac unsupported password type: " + pass;
      +793 
      +794 	this.pass = CryptoJS.enc.Hex.parse(hPass);
      +795     };
      +796 
      +797     if (params !== undefined) {
      +798 	if (params.pass !== undefined) {
      +799 	    this.setPassword(params.pass);
      +800 	}
      +801 	if (params.alg !== undefined) {
      +802 	    this.algName = params.alg;
      +803 	    if (params['prov'] === undefined)
      +804 		this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName];
      +805 	    this.setAlgAndProvider(this.algName, this.provName);
      +806 	}
      +807     }
      +808 };
      +809 
      +810 // ====== Signature class =========================================================
      +811 /**
      +812  * Signature class which is very similar to java.security.Signature class
      +813  * @name KJUR.crypto.Signature
      +814  * @class Signature class which is very similar to java.security.Signature class
      +815  * @param {Array} params parameters for constructor
      +816  * @property {String} state Current state of this signature object whether 'SIGN', 'VERIFY' or null
      +817  * @description
      +818  * <br/>
      +819  * As for params of constructor's argument, it can be specify following attributes:
      +820  * <ul>
      +821  * <li>alg - signature algorithm name (ex. {MD5,SHA1,SHA224,SHA256,SHA384,SHA512,RIPEMD160}with{RSA,ECDSA,DSA})</li>
      +822  * <li>provider - currently 'cryptojs/jsrsa' only</li>
      +823  * </ul>
      +824  * <h4>SUPPORTED ALGORITHMS AND PROVIDERS</h4>
      +825  * This Signature class supports following signature algorithm and provider names:
      +826  * <ul>
      +827  * <li>MD5withRSA - cryptojs/jsrsa</li>
      +828  * <li>SHA1withRSA - cryptojs/jsrsa</li>
      +829  * <li>SHA224withRSA - cryptojs/jsrsa</li>
      +830  * <li>SHA256withRSA - cryptojs/jsrsa</li>
      +831  * <li>SHA384withRSA - cryptojs/jsrsa</li>
      +832  * <li>SHA512withRSA - cryptojs/jsrsa</li>
      +833  * <li>RIPEMD160withRSA - cryptojs/jsrsa</li>
      +834  * <li>MD5withECDSA - cryptojs/jsrsa</li>
      +835  * <li>SHA1withECDSA - cryptojs/jsrsa</li>
      +836  * <li>SHA224withECDSA - cryptojs/jsrsa</li>
      +837  * <li>SHA256withECDSA - cryptojs/jsrsa</li>
      +838  * <li>SHA384withECDSA - cryptojs/jsrsa</li>
      +839  * <li>SHA512withECDSA - cryptojs/jsrsa</li>
      +840  * <li>RIPEMD160withECDSA - cryptojs/jsrsa</li>
      +841  * <li>MD5withRSAandMGF1 - cryptojs/jsrsa</li>
      +842  * <li>SHA1withRSAandMGF1 - cryptojs/jsrsa</li>
      +843  * <li>SHA224withRSAandMGF1 - cryptojs/jsrsa</li>
      +844  * <li>SHA256withRSAandMGF1 - cryptojs/jsrsa</li>
      +845  * <li>SHA384withRSAandMGF1 - cryptojs/jsrsa</li>
      +846  * <li>SHA512withRSAandMGF1 - cryptojs/jsrsa</li>
      +847  * <li>RIPEMD160withRSAandMGF1 - cryptojs/jsrsa</li>
      +848  * <li>SHA1withDSA - cryptojs/jsrsa</li>
      +849  * <li>SHA224withDSA - cryptojs/jsrsa</li>
      +850  * <li>SHA256withDSA - cryptojs/jsrsa</li>
      +851  * </ul>
      +852  * Here are supported elliptic cryptographic curve names and their aliases for ECDSA:
      +853  * <ul>
      +854  * <li>secp256k1</li>
      +855  * <li>secp256r1, NIST P-256, P-256, prime256v1</li>
      +856  * <li>secp384r1, NIST P-384, P-384</li>
      +857  * </ul>
      +858  * NOTE1: DSA signing algorithm is also supported since crypto 1.1.5.
      +859  * <h4>EXAMPLES</h4>
      +860  * @example
      +861  * // RSA signature generation
      +862  * var sig = new KJUR.crypto.Signature({"alg": "SHA1withRSA"});
      +863  * sig.init(prvKeyPEM);
      +864  * sig.updateString('aaa');
      +865  * var hSigVal = sig.sign();
      +866  *
      +867  * // DSA signature validation
      +868  * var sig2 = new KJUR.crypto.Signature({"alg": "SHA1withDSA"});
      +869  * sig2.init(certPEM);
      +870  * sig.updateString('aaa');
      +871  * var isValid = sig2.verify(hSigVal);
      +872  * 
      +873  * // ECDSA signing
      +874  * var sig = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'});
      +875  * sig.init(prvKeyPEM);
      +876  * sig.updateString('aaa');
      +877  * var sigValueHex = sig.sign();
      +878  *
      +879  * // ECDSA verifying
      +880  * var sig2 = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'});
      +881  * sig.init(certPEM);
      +882  * sig.updateString('aaa');
      +883  * var isValid = sig.verify(sigValueHex);
      +884  */
      +885 KJUR.crypto.Signature = function(params) {
      +886     var prvKey = null; // RSAKey/KJUR.crypto.{ECDSA,DSA} object for signing
      +887     var pubKey = null; // RSAKey/KJUR.crypto.{ECDSA,DSA} object for verifying
      +888 
      +889     var md = null; // KJUR.crypto.MessageDigest object
      +890     var sig = null;
      +891     var algName = null;
      +892     var provName = null;
      +893     var algProvName = null;
      +894     var mdAlgName = null;
      +895     var pubkeyAlgName = null;	// rsa,ecdsa,rsaandmgf1(=rsapss)
      +896     var state = null;
      +897     var pssSaltLen = -1;
      +898     var initParams = null;
      +899 
      +900     var sHashHex = null; // hex hash value for hex
      +901     var hDigestInfo = null;
      +902     var hPaddedDigestInfo = null;
      +903     var hSign = null;
      +904 
      +905     this._setAlgNames = function() {
      +906     var matchResult = this.algName.match(/^(.+)with(.+)$/);
      +907 	if (matchResult) {
      +908 	    this.mdAlgName = matchResult[1].toLowerCase();
      +909 	    this.pubkeyAlgName = matchResult[2].toLowerCase();
      +910 	}
      +911     };
      +912 
      +913     this._zeroPaddingOfSignature = function(hex, bitLength) {
      +914 	var s = "";
      +915 	var nZero = bitLength / 4 - hex.length;
      +916 	for (var i = 0; i < nZero; i++) {
      +917 	    s = s + "0";
      +918 	}
      +919 	return s + hex;
      +920     };
      +921 
      +922     /**
      +923      * set signature algorithm and provider
      +924      * @name setAlgAndProvider
      +925      * @memberOf KJUR.crypto.Signature
      +926      * @function
      +927      * @param {String} alg signature algorithm name
      +928      * @param {String} prov provider name
      +929      * @description
      +930      * @example
      +931      * md.setAlgAndProvider('SHA1withRSA', 'cryptojs/jsrsa');
      +932      */
      +933     this.setAlgAndProvider = function(alg, prov) {
      +934 	this._setAlgNames();
      +935 	if (prov != 'cryptojs/jsrsa')
      +936 	    throw "provider not supported: " + prov;
      +937 
      +938 	if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(this.mdAlgName) != -1) {
      +939 	    try {
      +940 		this.md = new KJUR.crypto.MessageDigest({'alg':this.mdAlgName});
      +941 	    } catch (ex) {
      +942 		throw "setAlgAndProvider hash alg set fail alg=" +
      +943                       this.mdAlgName + "/" + ex;
      +944 	    }
      +945 
      +946 	    this.init = function(keyparam, pass) {
      +947 		var keyObj = null;
      +948 		try {
      +949 		    if (pass === undefined) {
      +950 			keyObj = KEYUTIL.getKey(keyparam);
      +951 		    } else {
      +952 			keyObj = KEYUTIL.getKey(keyparam, pass);
      +953 		    }
      +954 		} catch (ex) {
      +955 		    throw "init failed:" + ex;
      +956 		}
      +957 
      +958 		if (keyObj.isPrivate === true) {
      +959 		    this.prvKey = keyObj;
      +960 		    this.state = "SIGN";
      +961 		} else if (keyObj.isPublic === true) {
      +962 		    this.pubKey = keyObj;
      +963 		    this.state = "VERIFY";
      +964 		} else {
      +965 		    throw "init failed.:" + keyObj;
      +966 		}
      +967 	    };
      +968 
      +969 	    this.initSign = function(params) {
      +970 		if (typeof params['ecprvhex'] == 'string' &&
      +971                     typeof params['eccurvename'] == 'string') {
      +972 		    this.ecprvhex = params['ecprvhex'];
      +973 		    this.eccurvename = params['eccurvename'];
      +974 		} else {
      +975 		    this.prvKey = params;
      +976 		}
      +977 		this.state = "SIGN";
      +978 	    };
       979 
      -980     /**
      -981      * Initialize this object for signing or verifying depends on key
      -982      * @name init
      -983      * @memberOf KJUR.crypto.Signature
      -984      * @function
      -985      * @param {Object} key specifying public or private key as plain/encrypted PKCS#5/8 PEM file, certificate PEM or {@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA} object
      -986      * @param {String} pass (OPTION) passcode for encrypted private key
      -987      * @since crypto 1.1.3
      -988      * @description
      -989      * This method is very useful initialize method for Signature class since
      -990      * you just specify key then this method will automatically initialize it
      -991      * using {@link KEYUTIL.getKey} method.
      -992      * As for 'key',  following argument type are supported:
      -993      * <h5>signing</h5>
      -994      * <ul>
      -995      * <li>PEM formatted PKCS#8 encrypted RSA/ECDSA private key concluding "BEGIN ENCRYPTED PRIVATE KEY"</li>
      -996      * <li>PEM formatted PKCS#5 encrypted RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" and ",ENCRYPTED"</li>
      -997      * <li>PEM formatted PKCS#8 plain RSA/ECDSA private key concluding "BEGIN PRIVATE KEY"</li>
      -998      * <li>PEM formatted PKCS#5 plain RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" without ",ENCRYPTED"</li>
      -999      * <li>RSAKey object of private key</li>
      -1000      * <li>KJUR.crypto.ECDSA object of private key</li>
      -1001      * <li>KJUR.crypto.DSA object of private key</li>
      -1002      * </ul>
      -1003      * <h5>verification</h5>
      -1004      * <ul>
      -1005      * <li>PEM formatted PKCS#8 RSA/EC/DSA public key concluding "BEGIN PUBLIC KEY"</li>
      -1006      * <li>PEM formatted X.509 certificate with RSA/EC/DSA public key concluding
      -1007      *     "BEGIN CERTIFICATE", "BEGIN X509 CERTIFICATE" or "BEGIN TRUSTED CERTIFICATE".</li>
      -1008      * <li>RSAKey object of public key</li>
      -1009      * <li>KJUR.crypto.ECDSA object of public key</li>
      -1010      * <li>KJUR.crypto.DSA object of public key</li>
      -1011      * </ul>
      -1012      * @example
      -1013      * sig.init(sCertPEM)
      -1014      */
      -1015     this.init = function(key, pass) {
      -1016 	throw "init(key, pass) not supported for this alg:prov=" +
      -1017 	      this.algProvName;
      -1018     };
      -1019 
      -1020     /**
      -1021      * Initialize this object for verifying with a public key
      -1022      * @name initVerifyByPublicKey
      -1023      * @memberOf KJUR.crypto.Signature
      -1024      * @function
      -1025      * @param {Object} param RSAKey object of public key or associative array for ECDSA
      -1026      * @since 1.0.2
      -1027      * @deprecated from crypto 1.1.5. please use init() method instead.
      -1028      * @description
      -1029      * Public key information will be provided as 'param' parameter and the value will be
      -1030      * following:
      -1031      * <ul>
      -1032      * <li>{@link RSAKey} object for RSA verification</li>
      -1033      * <li>associative array for ECDSA verification
      -1034      *     (ex. <code>{'ecpubhex': '041f..', 'eccurvename': 'secp256r1'}</code>)
      -1035      * </li>
      -1036      * </ul>
      -1037      * @example
      -1038      * sig.initVerifyByPublicKey(rsaPrvKey)
      -1039      */
      -1040     this.initVerifyByPublicKey = function(rsaPubKey) {
      -1041 	throw "initVerifyByPublicKey(rsaPubKeyy) not supported for this alg:prov=" +
      -1042 	      this.algProvName;
      -1043     };
      -1044 
      -1045     /**
      -1046      * Initialize this object for verifying with a certficate
      -1047      * @name initVerifyByCertificatePEM
      -1048      * @memberOf KJUR.crypto.Signature
      -1049      * @function
      -1050      * @param {String} certPEM PEM formatted string of certificate
      -1051      * @since 1.0.2
      -1052      * @deprecated from crypto 1.1.5. please use init() method instead.
      -1053      * @description
      -1054      * @example
      -1055      * sig.initVerifyByCertificatePEM(certPEM)
      -1056      */
      -1057     this.initVerifyByCertificatePEM = function(certPEM) {
      -1058 	throw "initVerifyByCertificatePEM(certPEM) not supported for this alg:prov=" +
      -1059 	    this.algProvName;
      -1060     };
      -1061 
      -1062     /**
      -1063      * Initialize this object for signing
      -1064      * @name initSign
      -1065      * @memberOf KJUR.crypto.Signature
      -1066      * @function
      -1067      * @param {Object} param RSAKey object of public key or associative array for ECDSA
      -1068      * @deprecated from crypto 1.1.5. please use init() method instead.
      -1069      * @description
      -1070      * Private key information will be provided as 'param' parameter and the value will be
      -1071      * following:
      -1072      * <ul>
      -1073      * <li>{@link RSAKey} object for RSA signing</li>
      -1074      * <li>associative array for ECDSA signing
      -1075      *     (ex. <code>{'ecprvhex': '1d3f..', 'eccurvename': 'secp256r1'}</code>)</li>
      -1076      * </ul>
      -1077      * @example
      -1078      * sig.initSign(prvKey)
      -1079      */
      -1080     this.initSign = function(prvKey) {
      -1081 	throw "initSign(prvKey) not supported for this alg:prov=" + this.algProvName;
      -1082     };
      -1083 
      -1084     /**
      -1085      * Updates the data to be signed or verified by a string
      -1086      * @name updateString
      -1087      * @memberOf KJUR.crypto.Signature
      -1088      * @function
      -1089      * @param {String} str string to use for the update
      -1090      * @description
      -1091      * @example
      -1092      * sig.updateString('aaa')
      -1093      */
      -1094     this.updateString = function(str) {
      -1095 	throw "updateString(str) not supported for this alg:prov=" + this.algProvName;
      -1096     };
      -1097 
      -1098     /**
      -1099      * Updates the data to be signed or verified by a hexadecimal string
      -1100      * @name updateHex
      -1101      * @memberOf KJUR.crypto.Signature
      -1102      * @function
      -1103      * @param {String} hex hexadecimal string to use for the update
      -1104      * @description
      -1105      * @example
      -1106      * sig.updateHex('1f2f3f')
      -1107      */
      -1108     this.updateHex = function(hex) {
      -1109 	throw "updateHex(hex) not supported for this alg:prov=" + this.algProvName;
      -1110     };
      -1111 
      -1112     /**
      -1113      * Returns the signature bytes of all data updates as a hexadecimal string
      -1114      * @name sign
      -1115      * @memberOf KJUR.crypto.Signature
      -1116      * @function
      -1117      * @return the signature bytes as a hexadecimal string
      -1118      * @description
      -1119      * @example
      -1120      * var hSigValue = sig.sign()
      -1121      */
      -1122     this.sign = function() {
      -1123 	throw "sign() not supported for this alg:prov=" + this.algProvName;
      -1124     };
      -1125 
      -1126     /**
      -1127      * performs final update on the sign using string, then returns the signature bytes of all data updates as a hexadecimal string
      -1128      * @name signString
      -1129      * @memberOf KJUR.crypto.Signature
      -1130      * @function
      -1131      * @param {String} str string to final update
      -1132      * @return the signature bytes of a hexadecimal string
      -1133      * @description
      -1134      * @example
      -1135      * var hSigValue = sig.signString('aaa')
      -1136      */
      -1137     this.signString = function(str) {
      -1138 	throw "digestString(str) not supported for this alg:prov=" + this.algProvName;
      -1139     };
      -1140 
      -1141     /**
      -1142      * performs final update on the sign using hexadecimal string, then returns the signature bytes of all data updates as a hexadecimal string
      -1143      * @name signHex
      -1144      * @memberOf KJUR.crypto.Signature
      -1145      * @function
      -1146      * @param {String} hex hexadecimal string to final update
      -1147      * @return the signature bytes of a hexadecimal string
      -1148      * @description
      -1149      * @example
      -1150      * var hSigValue = sig.signHex('1fdc33')
      -1151      */
      -1152     this.signHex = function(hex) {
      -1153 	throw "digestHex(hex) not supported for this alg:prov=" + this.algProvName;
      -1154     };
      -1155 
      -1156     /**
      -1157      * verifies the passed-in signature.
      -1158      * @name verify
      -1159      * @memberOf KJUR.crypto.Signature
      -1160      * @function
      -1161      * @param {String} str string to final update
      -1162      * @return {Boolean} true if the signature was verified, otherwise false
      -1163      * @description
      -1164      * @example
      -1165      * var isValid = sig.verify('1fbcefdca4823a7(snip)')
      -1166      */
      -1167     this.verify = function(hSigVal) {
      -1168 	throw "verify(hSigVal) not supported for this alg:prov=" + this.algProvName;
      -1169     };
      -1170 
      -1171     this.initParams = params;
      -1172 
      -1173     if (params !== undefined) {
      -1174 	if (params['alg'] !== undefined) {
      -1175 	    this.algName = params['alg'];
      -1176 	    if (params['prov'] === undefined) {
      -1177 		this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName];
      -1178 	    } else {
      -1179 		this.provName = params['prov'];
      -1180 	    }
      -1181 	    this.algProvName = this.algName + ":" + this.provName;
      -1182 	    this.setAlgAndProvider(this.algName, this.provName);
      -1183 	    this._setAlgNames();
      -1184 	}
      -1185 
      -1186 	if (params['psssaltlen'] !== undefined) this.pssSaltLen = params['psssaltlen'];
      -1187 
      -1188 	if (params['prvkeypem'] !== undefined) {
      -1189 	    if (params['prvkeypas'] !== undefined) {
      -1190 		throw "both prvkeypem and prvkeypas parameters not supported";
      -1191 	    } else {
      -1192 		try {
      -1193 		    var prvKey = new RSAKey();
      -1194 		    prvKey.readPrivateKeyFromPEMString(params['prvkeypem']);
      -1195 		    this.initSign(prvKey);
      -1196 		} catch (ex) {
      -1197 		    throw "fatal error to load pem private key: " + ex;
      -1198 		}
      -1199 	    }
      -1200 	}
      -1201     }
      -1202 };
      -1203 
      -1204 /**
      -1205  * static object for cryptographic function utilities
      -1206  * @name KJUR.crypto.OID
      -1207  * @class static object for cryptography related OIDs
      -1208  * @property {Array} oidhex2name key value of hexadecimal OID and its name
      -1209  *           (ex. '2a8648ce3d030107' and 'secp256r1')
      -1210  * @since crypto 1.1.3
      -1211  * @description
      -1212  */
      -1213 
      -1214 
      -1215 KJUR.crypto.OID = new function() {
      -1216     this.oidhex2name = {
      -1217 	'2a864886f70d010101': 'rsaEncryption',
      -1218 	'2a8648ce3d0201': 'ecPublicKey',
      -1219 	'2a8648ce380401': 'dsa',
      -1220 	'2a8648ce3d030107': 'secp256r1',
      -1221 	'2b8104001f': 'secp192k1',
      -1222 	'2b81040021': 'secp224r1',
      -1223 	'2b8104000a': 'secp256k1',
      -1224 	'2b81040023': 'secp521r1',
      -1225 	'2b81040022': 'secp384r1',
      -1226 	'2a8648ce380403': 'SHA1withDSA', // 1.2.840.10040.4.3
      -1227 	'608648016503040301': 'SHA224withDSA', // 2.16.840.1.101.3.4.3.1
      -1228 	'608648016503040302': 'SHA256withDSA', // 2.16.840.1.101.3.4.3.2
      -1229     };
      -1230 };
      -1231 
      \ No newline at end of file +980
      this.initVerifyByPublicKey = function(params) { +981 if (typeof params['ecpubhex'] == 'string' && +982 typeof params['eccurvename'] == 'string') { +983 this.ecpubhex = params['ecpubhex']; +984 this.eccurvename = params['eccurvename']; +985 } else if (params instanceof KJUR.crypto.ECDSA) { +986 this.pubKey = params; +987 } else if (params instanceof RSAKey) { +988 this.pubKey = params; +989 } +990 this.state = "VERIFY"; +991 }; +992 +993 this.initVerifyByCertificatePEM = function(certPEM) { +994 var x509 = new X509(); +995 x509.readCertPEM(certPEM); +996 this.pubKey = x509.subjectPublicKeyRSA; +997 this.state = "VERIFY"; +998 }; +999 +1000 this.updateString = function(str) { +1001 this.md.updateString(str); +1002 }; +1003 +1004 this.updateHex = function(hex) { +1005 this.md.updateHex(hex); +1006 }; +1007 +1008 this.sign = function() { +1009 this.sHashHex = this.md.digest(); +1010 if (typeof this.ecprvhex != "undefined" && +1011 typeof this.eccurvename != "undefined") { +1012 var ec = new KJUR.crypto.ECDSA({'curve': this.eccurvename}); +1013 this.hSign = ec.signHex(this.sHashHex, this.ecprvhex); +1014 } else if (this.prvKey instanceof RSAKey && +1015 this.pubkeyAlgName == "rsaandmgf1") { +1016 this.hSign = this.prvKey.signWithMessageHashPSS(this.sHashHex, +1017 this.mdAlgName, +1018 this.pssSaltLen); +1019 } else if (this.prvKey instanceof RSAKey && +1020 this.pubkeyAlgName == "rsa") { +1021 this.hSign = this.prvKey.signWithMessageHash(this.sHashHex, +1022 this.mdAlgName); +1023 } else if (this.prvKey instanceof KJUR.crypto.ECDSA) { +1024 this.hSign = this.prvKey.signWithMessageHash(this.sHashHex); +1025 } else if (this.prvKey instanceof KJUR.crypto.DSA) { +1026 this.hSign = this.prvKey.signWithMessageHash(this.sHashHex); +1027 } else { +1028 throw "Signature: unsupported public key alg: " + this.pubkeyAlgName; +1029 } +1030 return this.hSign; +1031 }; +1032 this.signString = function(str) { +1033 this.updateString(str); +1034 return this.sign(); +1035 }; +1036 this.signHex = function(hex) { +1037 this.updateHex(hex); +1038 return this.sign(); +1039 }; +1040 this.verify = function(hSigVal) { +1041 this.sHashHex = this.md.digest(); +1042 if (typeof this.ecpubhex != "undefined" && +1043 typeof this.eccurvename != "undefined") { +1044 var ec = new KJUR.crypto.ECDSA({curve: this.eccurvename}); +1045 return ec.verifyHex(this.sHashHex, hSigVal, this.ecpubhex); +1046 } else if (this.pubKey instanceof RSAKey && +1047 this.pubkeyAlgName == "rsaandmgf1") { +1048 return this.pubKey.verifyWithMessageHashPSS(this.sHashHex, hSigVal, +1049 this.mdAlgName, +1050 this.pssSaltLen); +1051 } else if (this.pubKey instanceof RSAKey && +1052 this.pubkeyAlgName == "rsa") { +1053 return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal); +1054 } else if (this.pubKey instanceof KJUR.crypto.ECDSA) { +1055 return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal); +1056 } else if (this.pubKey instanceof KJUR.crypto.DSA) { +1057 return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal); +1058 } else { +1059 throw "Signature: unsupported public key alg: " + this.pubkeyAlgName; +1060 } +1061 }; +1062 } +1063 }; +1064 +1065 /** +1066 * Initialize this object for signing or verifying depends on key +1067 * @name init +1068 * @memberOf KJUR.crypto.Signature +1069 * @function +1070 * @param {Object} key specifying public or private key as plain/encrypted PKCS#5/8 PEM file, certificate PEM or {@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA} object +1071 * @param {String} pass (OPTION) passcode for encrypted private key +1072 * @since crypto 1.1.3 +1073 * @description +1074 * This method is very useful initialize method for Signature class since +1075 * you just specify key then this method will automatically initialize it +1076 * using {@link KEYUTIL.getKey} method. +1077 * As for 'key', following argument type are supported: +1078 * <h5>signing</h5> +1079 * <ul> +1080 * <li>PEM formatted PKCS#8 encrypted RSA/ECDSA private key concluding "BEGIN ENCRYPTED PRIVATE KEY"</li> +1081 * <li>PEM formatted PKCS#5 encrypted RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" and ",ENCRYPTED"</li> +1082 * <li>PEM formatted PKCS#8 plain RSA/ECDSA private key concluding "BEGIN PRIVATE KEY"</li> +1083 * <li>PEM formatted PKCS#5 plain RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" without ",ENCRYPTED"</li> +1084 * <li>RSAKey object of private key</li> +1085 * <li>KJUR.crypto.ECDSA object of private key</li> +1086 * <li>KJUR.crypto.DSA object of private key</li> +1087 * </ul> +1088 * <h5>verification</h5> +1089 * <ul> +1090 * <li>PEM formatted PKCS#8 RSA/EC/DSA public key concluding "BEGIN PUBLIC KEY"</li> +1091 * <li>PEM formatted X.509 certificate with RSA/EC/DSA public key concluding +1092 * "BEGIN CERTIFICATE", "BEGIN X509 CERTIFICATE" or "BEGIN TRUSTED CERTIFICATE".</li> +1093 * <li>RSAKey object of public key</li> +1094 * <li>KJUR.crypto.ECDSA object of public key</li> +1095 * <li>KJUR.crypto.DSA object of public key</li> +1096 * </ul> +1097 * @example +1098 * sig.init(sCertPEM) +1099 */ +1100 this.init = function(key, pass) { +1101 throw "init(key, pass) not supported for this alg:prov=" + +1102 this.algProvName; +1103 }; +1104 +1105 /** +1106 * Initialize this object for verifying with a public key +1107 * @name initVerifyByPublicKey +1108 * @memberOf KJUR.crypto.Signature +1109 * @function +1110 * @param {Object} param RSAKey object of public key or associative array for ECDSA +1111 * @since 1.0.2 +1112 * @deprecated from crypto 1.1.5. please use init() method instead. +1113 * @description +1114 * Public key information will be provided as 'param' parameter and the value will be +1115 * following: +1116 * <ul> +1117 * <li>{@link RSAKey} object for RSA verification</li> +1118 * <li>associative array for ECDSA verification +1119 * (ex. <code>{'ecpubhex': '041f..', 'eccurvename': 'secp256r1'}</code>) +1120 * </li> +1121 * </ul> +1122 * @example +1123 * sig.initVerifyByPublicKey(rsaPrvKey) +1124 */ +1125 this.initVerifyByPublicKey = function(rsaPubKey) { +1126 throw "initVerifyByPublicKey(rsaPubKeyy) not supported for this alg:prov=" + +1127 this.algProvName; +1128 }; +1129 +1130 /** +1131 * Initialize this object for verifying with a certficate +1132 * @name initVerifyByCertificatePEM +1133 * @memberOf KJUR.crypto.Signature +1134 * @function +1135 * @param {String} certPEM PEM formatted string of certificate +1136 * @since 1.0.2 +1137 * @deprecated from crypto 1.1.5. please use init() method instead. +1138 * @description +1139 * @example +1140 * sig.initVerifyByCertificatePEM(certPEM) +1141 */ +1142 this.initVerifyByCertificatePEM = function(certPEM) { +1143 throw "initVerifyByCertificatePEM(certPEM) not supported for this alg:prov=" + +1144 this.algProvName; +1145 }; +1146 +1147 /** +1148 * Initialize this object for signing +1149 * @name initSign +1150 * @memberOf KJUR.crypto.Signature +1151 * @function +1152 * @param {Object} param RSAKey object of public key or associative array for ECDSA +1153 * @deprecated from crypto 1.1.5. please use init() method instead. +1154 * @description +1155 * Private key information will be provided as 'param' parameter and the value will be +1156 * following: +1157 * <ul> +1158 * <li>{@link RSAKey} object for RSA signing</li> +1159 * <li>associative array for ECDSA signing +1160 * (ex. <code>{'ecprvhex': '1d3f..', 'eccurvename': 'secp256r1'}</code>)</li> +1161 * </ul> +1162 * @example +1163 * sig.initSign(prvKey) +1164 */ +1165 this.initSign = function(prvKey) { +1166 throw "initSign(prvKey) not supported for this alg:prov=" + this.algProvName; +1167 }; +1168 +1169 /** +1170 * Updates the data to be signed or verified by a string +1171 * @name updateString +1172 * @memberOf KJUR.crypto.Signature +1173 * @function +1174 * @param {String} str string to use for the update +1175 * @description +1176 * @example +1177 * sig.updateString('aaa') +1178 */ +1179 this.updateString = function(str) { +1180 throw "updateString(str) not supported for this alg:prov=" + this.algProvName; +1181 }; +1182 +1183 /** +1184 * Updates the data to be signed or verified by a hexadecimal string +1185 * @name updateHex +1186 * @memberOf KJUR.crypto.Signature +1187 * @function +1188 * @param {String} hex hexadecimal string to use for the update +1189 * @description +1190 * @example +1191 * sig.updateHex('1f2f3f') +1192 */ +1193 this.updateHex = function(hex) { +1194 throw "updateHex(hex) not supported for this alg:prov=" + this.algProvName; +1195 }; +1196 +1197 /** +1198 * Returns the signature bytes of all data updates as a hexadecimal string +1199 * @name sign +1200 * @memberOf KJUR.crypto.Signature +1201 * @function +1202 * @return the signature bytes as a hexadecimal string +1203 * @description +1204 * @example +1205 * var hSigValue = sig.sign() +1206 */ +1207 this.sign = function() { +1208 throw "sign() not supported for this alg:prov=" + this.algProvName; +1209 }; +1210 +1211 /** +1212 * performs final update on the sign using string, then returns the signature bytes of all data updates as a hexadecimal string +1213 * @name signString +1214 * @memberOf KJUR.crypto.Signature +1215 * @function +1216 * @param {String} str string to final update +1217 * @return the signature bytes of a hexadecimal string +1218 * @description +1219 * @example +1220 * var hSigValue = sig.signString('aaa') +1221 */ +1222 this.signString = function(str) { +1223 throw "digestString(str) not supported for this alg:prov=" + this.algProvName; +1224 }; +1225 +1226 /** +1227 * performs final update on the sign using hexadecimal string, then returns the signature bytes of all data updates as a hexadecimal string +1228 * @name signHex +1229 * @memberOf KJUR.crypto.Signature +1230 * @function +1231 * @param {String} hex hexadecimal string to final update +1232 * @return the signature bytes of a hexadecimal string +1233 * @description +1234 * @example +1235 * var hSigValue = sig.signHex('1fdc33') +1236 */ +1237 this.signHex = function(hex) { +1238 throw "digestHex(hex) not supported for this alg:prov=" + this.algProvName; +1239 }; +1240 +1241 /** +1242 * verifies the passed-in signature. +1243 * @name verify +1244 * @memberOf KJUR.crypto.Signature +1245 * @function +1246 * @param {String} str string to final update +1247 * @return {Boolean} true if the signature was verified, otherwise false +1248 * @description +1249 * @example +1250 * var isValid = sig.verify('1fbcefdca4823a7(snip)') +1251 */ +1252 this.verify = function(hSigVal) { +1253 throw "verify(hSigVal) not supported for this alg:prov=" + this.algProvName; +1254 }; +1255 +1256 this.initParams = params; +1257 +1258 if (params !== undefined) { +1259 if (params['alg'] !== undefined) { +1260 this.algName = params['alg']; +1261 if (params['prov'] === undefined) { +1262 this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]; +1263 } else { +1264 this.provName = params['prov']; +1265 } +1266 this.algProvName = this.algName + ":" + this.provName; +1267 this.setAlgAndProvider(this.algName, this.provName); +1268 this._setAlgNames(); +1269 } +1270 +1271 if (params['psssaltlen'] !== undefined) this.pssSaltLen = params['psssaltlen']; +1272 +1273 if (params['prvkeypem'] !== undefined) { +1274 if (params['prvkeypas'] !== undefined) { +1275 throw "both prvkeypem and prvkeypas parameters not supported"; +1276 } else { +1277 try { +1278 var prvKey = new RSAKey(); +1279 prvKey.readPrivateKeyFromPEMString(params['prvkeypem']); +1280 this.initSign(prvKey); +1281 } catch (ex) { +1282 throw "fatal error to load pem private key: " + ex; +1283 } +1284 } +1285 } +1286 } +1287 }; +1288 +1289 // ====== Cipher class ============================================================ +1290 /** +1291 * Cipher class to encrypt and decrypt data<br/> +1292 * @name KJUR.crypto.Cipher +1293 * @param {Array} params parameters for constructor +1294 * @since jsrsasign 6.2.0 crypto 1.1.10 +1295 * @description +1296 * Here is supported canonicalized cipher algorithm names and its standard names: +1297 * <ul> +1298 * <li>RSA - RSA/ECB/PKCS1Padding (default for RSAKey)</li> +1299 * <li>RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding</li> +1300 * <li>RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)</li> +1301 * <li>RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding</li> +1302 * <li>RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)</li> +1303 * <li>RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)</li> +1304 * </ul> +1305 * NOTE: (*) is not supported in Java JCE.<br/> +1306 * Currently this class supports only RSA encryption and decryption. +1307 * However it is planning to implement also symmetric ciphers near in the future. +1308 * @example +1309 */ +1310 KJUR.crypto.Cipher = function(params) { +1311 }; +1312 +1313 /** +1314 * encrypt raw string by specified key and algorithm<br/> +1315 * @name encrypt +1316 * @memberOf KJUR.crypto.Cipher +1317 * @function +1318 * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key +1319 * @param {String} s input string to encrypt +1320 * @param {String} algName short/long algorithm name for encryption/decryption +1321 * @return {String} hexadecimal encrypted string +1322 * @since jsrsasign 6.2.0 crypto 1.1.10 +1323 * @description +1324 * This static method encrypts raw string with specified key and algorithm. +1325 * @example +1326 * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj) → "1abc2d..." +1327 * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj, "RSAOAEP) → "23ab02..." +1328 */ +1329 KJUR.crypto.Cipher.encrypt = function(s, keyObj, algName) { +1330 if (keyObj instanceof RSAKey && keyObj.isPublic) { +1331 var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName); +1332 if (algName2 === "RSA") return keyObj.encrypt(s); +1333 if (algName2 === "RSAOAEP") return keyObj.encryptOAEP(s, "sha1"); +1334 +1335 var a = algName2.match(/^RSAOAEP(\d+)$/); +1336 if (a !== null) return keyObj.encryptOAEP(s, "sha" + a[1]); +1337 +1338 throw "Cipher.encrypt: unsupported algorithm for RSAKey: " + algName; +1339 } else { +1340 throw "Cipher.encrypt: unsupported key or algorithm"; +1341 } +1342 }; +1343 +1344 /** +1345 * decrypt encrypted hexadecimal string with specified key and algorithm<br/> +1346 * @name encrypt +1347 * @memberOf KJUR.crypto.Cipher +1348 * @function +1349 * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key +1350 * @param {String} s input string to encrypt +1351 * @param {String} algName short/long algorithm name for encryption/decryption +1352 * @return {String} hexadecimal encrypted string +1353 * @since jsrsasign 6.2.0 crypto 1.1.10 +1354 * @description +1355 * This static method decrypts encrypted hexadecimal string with specified key and algorithm. +1356 * @example +1357 * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj) → "1abc2d..." +1358 * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj, "RSAOAEP) → "23ab02..." +1359 */ +1360 KJUR.crypto.Cipher.decrypt = function(hex, keyObj, algName) { +1361 if (keyObj instanceof RSAKey && keyObj.isPrivate) { +1362 var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName); +1363 if (algName2 === "RSA") return keyObj.decrypt(hex); +1364 if (algName2 === "RSAOAEP") return keyObj.decryptOAEP(hex, "sha1"); +1365 +1366 var a = algName2.match(/^RSAOAEP(\d+)$/); +1367 if (a !== null) return keyObj.decryptOAEP(hex, "sha" + a[1]); +1368 +1369 throw "Cipher.decrypt: unsupported algorithm for RSAKey: " + algName; +1370 } else { +1371 throw "Cipher.decrypt: unsupported key or algorithm"; +1372 } +1373 }; +1374 +1375 /** +1376 * get canonicalized encrypt/decrypt algorithm name by key and short/long algorithm name<br/> +1377 * @name getAlgByKeyAndName +1378 * @memberOf KJUR.crypto.Cipher +1379 * @function +1380 * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key +1381 * @param {String} algName short/long algorithm name for encryption/decryption +1382 * @return {String} canonicalized algorithm name for encryption/decryption +1383 * @since jsrsasign 6.2.0 crypto 1.1.10 +1384 * @description +1385 * Here is supported canonicalized cipher algorithm names and its standard names: +1386 * <ul> +1387 * <li>RSA - RSA/ECB/PKCS1Padding (default for RSAKey)</li> +1388 * <li>RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding</li> +1389 * <li>RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)</li> +1390 * <li>RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding</li> +1391 * <li>RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)</li> +1392 * <li>RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)</li> +1393 * </ul> +1394 * NOTE: (*) is not supported in Java JCE. +1395 * @example +1396 * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey) → "RSA" +1397 * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey, "RSAOAEP") → "RSAOAEP" +1398 */ +1399 KJUR.crypto.Cipher.getAlgByKeyAndName = function(keyObj, algName) { +1400 if (keyObj instanceof RSAKey) { +1401 if (":RSA:RSAOAEP:RSAOAEP224:RSAOAEP256:RSAOAEP384:RSAOAEP512:".indexOf(algName) != -1) +1402 return algName; +1403 if (algName === null || algName === undefined) return "RSA"; +1404 throw "getAlgByKeyAndName: not supported algorithm name for RSAKey: " + algName; +1405 } +1406 throw "getAlgByKeyAndName: not supported algorithm name: " + algName; +1407 } +1408 +1409 // ====== Other Utility class ===================================================== +1410 +1411 /** +1412 * static object for cryptographic function utilities +1413 * @name KJUR.crypto.OID +1414 * @class static object for cryptography related OIDs +1415 * @property {Array} oidhex2name key value of hexadecimal OID and its name +1416 * (ex. '2a8648ce3d030107' and 'secp256r1') +1417 * @since crypto 1.1.3 +1418 * @description +1419 */ +1420 KJUR.crypto.OID = new function() { +1421 this.oidhex2name = { +1422 '2a864886f70d010101': 'rsaEncryption', +1423 '2a8648ce3d0201': 'ecPublicKey', +1424 '2a8648ce380401': 'dsa', +1425 '2a8648ce3d030107': 'secp256r1', +1426 '2b8104001f': 'secp192k1', +1427 '2b81040021': 'secp224r1', +1428 '2b8104000a': 'secp256k1', +1429 '2b81040023': 'secp521r1', +1430 '2b81040022': 'secp384r1', +1431 '2a8648ce380403': 'SHA1withDSA', // 1.2.840.10040.4.3 +1432 '608648016503040301': 'SHA224withDSA', // 2.16.840.1.101.3.4.3.1 +1433 '608648016503040302': 'SHA256withDSA', // 2.16.840.1.101.3.4.3.2 +1434 }; +1435 }; +1436
      \ No newline at end of file diff --git a/bower.json b/bower.json index a304bb6a..3cd60dc4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "6.1.4", + "version": "6.2.0", "main": "jsrsasign-latest-all-min.js", "description": "The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES, JWS and JWT in pure JavaScript.", "license": "MIT", diff --git a/crypto-1.1.js b/crypto-1.1.js index 32c62d89..8e7c91ec 100644 --- a/crypto-1.1.js +++ b/crypto-1.1.js @@ -1,4 +1,4 @@ -/*! crypto-1.1.9.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! crypto-1.1.10.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * crypto.js - Cryptographic Algorithm Provider class @@ -16,7 +16,7 @@ * @fileOverview * @name crypto-1.1.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version 1.1.9 (2016-Oct-08) + * @version 1.1.10 (2016-Oct-29) * @since jsrsasign 2.2 * @license MIT License */ @@ -34,6 +34,7 @@ if (typeof KJUR == "undefined" || !KJUR) KJUR = {}; *
        *
      • {@link KJUR.crypto.MessageDigest} - Java JCE(cryptograhic extension) style MessageDigest class
      • *
      • {@link KJUR.crypto.Signature} - Java JCE(cryptograhic extension) style Signature class
      • + *
      • {@link KJUR.crypto.Cipher} - class for encrypting and decrypting data
      • *
      • {@link KJUR.crypto.Util} - cryptographic utility functions and properties
      • *
      * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2. @@ -285,11 +286,14 @@ KJUR.crypto.Util = new function() { }; }; +// === Mac =============================================================== + /** - * MessageDigest class which is very similar to java.security.MessageDigest class + * MessageDigest class which is very similar to java.security.MessageDigest class
      * @name KJUR.crypto.MessageDigest * @class MessageDigest class which is very similar to java.security.MessageDigest class * @param {Array} params parameters for constructor + * @property {Array} HASHLENGTH static Array of resulted byte length of hash (ex. HASHLENGTH["sha1"] == 20) * @description *
      * Currently this supports following algorithm and providers combination: @@ -313,6 +317,10 @@ KJUR.crypto.Util = new function() { * var md = new KJUR.crypto.MessageDigest({alg: "sha256", prov: "sjcl"}); // sjcl supports sha256 only * md.updateString('aaa') * var mdHex = md.digest() + * + * // HASHLENGTH property + * KJUR.crypto.MessageDigest.HASHLENGTH['sha1'] &rarr 20 + * KJUR.crypto.MessageDigest.HASHLENGTH['sha512'] &rarr 64 */ KJUR.crypto.MessageDigest = function(params) { var md = null; @@ -320,21 +328,38 @@ KJUR.crypto.MessageDigest = function(params) { var provName = null; /** - * set hash algorithm and provider + * set hash algorithm and provider
      * @name setAlgAndProvider - * @memberOf KJUR.crypto.MessageDigest + * @memberOf KJUR.crypto.MessageDigest# * @function * @param {String} alg hash algorithm name * @param {String} prov provider name * @description + * This methods set an algorithm and a cryptographic provider.
      + * Here is acceptable algorithm names ignoring cases and hyphens: + *
        + *
      • MD5
      • + *
      • SHA1
      • + *
      • SHA224
      • + *
      • SHA256
      • + *
      • SHA384
      • + *
      • SHA512
      • + *
      • RIPEMD160
      • + *
      + * NOTE: Since jsrsasign 6.2.0 crypto 1.1.10, this method ignores + * upper or lower cases. Also any hyphens (i.e. "-") will be ignored + * so that "SHA1" or "SHA-1" will be acceptable. * @example * // for SHA1 * md.setAlgAndProvider('sha1', 'cryptojs'); + * md.setAlgAndProvider('SHA1'); * // for RIPEMD160 * md.setAlgAndProvider('ripemd160', 'cryptojs'); */ this.setAlgAndProvider = function(alg, prov) { - if (alg != null && prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg]; + alg = KJUR.crypto.MessageDigest.getCanonicalAlgName(alg); + + if (alg !== null && prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg]; // for cryptojs if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(alg) != -1 && @@ -396,7 +421,7 @@ KJUR.crypto.MessageDigest = function(params) { /** * update digest by specified string * @name updateString - * @memberOf KJUR.crypto.MessageDigest + * @memberOf KJUR.crypto.MessageDigest# * @function * @param {String} str string to update * @description @@ -410,7 +435,7 @@ KJUR.crypto.MessageDigest = function(params) { /** * update digest by specified hexadecimal string * @name updateHex - * @memberOf KJUR.crypto.MessageDigest + * @memberOf KJUR.crypto.MessageDigest# * @function * @param {String} hex hexadecimal string to update * @description @@ -437,7 +462,7 @@ KJUR.crypto.MessageDigest = function(params) { /** * performs final update on the digest using string, then completes the digest computation * @name digestString - * @memberOf KJUR.crypto.MessageDigest + * @memberOf KJUR.crypto.MessageDigest# * @function * @param {String} str string to final update * @description @@ -451,7 +476,7 @@ KJUR.crypto.MessageDigest = function(params) { /** * performs final update on the digest using hexadecimal string, then completes the digest computation * @name digestHex - * @memberOf KJUR.crypto.MessageDigest + * @memberOf KJUR.crypto.MessageDigest# * @function * @param {String} hex hexadecimal string to final update * @description @@ -472,6 +497,65 @@ KJUR.crypto.MessageDigest = function(params) { } }; +/** + * get canonical hash algorithm name
      + * @name getCanonicalAlgName + * @memberOf KJUR.crypto.MessageDigest + * @function + * @param {String} alg hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.) + * @return {String} canonical hash algorithm name + * @since jsrsasign 6.2.0 crypto 1.1.10 + * @description + * This static method normalizes from any hash algorithm name such as + * "SHA-1", "SHA1", "MD5", "sha512" to lower case name without hyphens + * such as "sha1". + * @example + * KJUR.crypto.MessageDigest.getCanonicalAlgName("SHA-1") &rarr "sha1" + * KJUR.crypto.MessageDigest.getCanonicalAlgName("MD5") &rarr "md5" + */ +KJUR.crypto.MessageDigest.getCanonicalAlgName = function(alg) { + if (typeof alg === "string") { + alg = alg.toLowerCase(); + alg = alg.replace(/-/, ''); + } + return alg; +}; + +/** + * get resulted hash byte length for specified algorithm name
      + * @name getHashLength + * @memberOf KJUR.crypto.MessageDigest + * @function + * @param {String} alg non-canonicalized hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.) + * @return {Integer} resulted hash byte length + * @since jsrsasign 6.2.0 crypto 1.1.10 + * @description + * This static method returns resulted byte length for specified algorithm name such as "SHA-1". + * @example + * KJUR.crypto.MessageDigest.getHashLength("SHA-1") &rarr 20 + * KJUR.crypto.MessageDigest.getHashLength("sha1") &rarr 20 + */ +KJUR.crypto.MessageDigest.getHashLength = function(alg) { + var MD = KJUR.crypto.MessageDigest + var alg2 = MD.getCanonicalAlgName(alg); + if (MD.HASHLENGTH[alg2] === undefined) + throw "not supported algorithm: " + alg; + return MD.HASHLENGTH[alg2]; +}; + +// described in KJUR.crypto.MessageDigest class (since jsrsasign 6.2.0 crypto 1.1.10) +KJUR.crypto.MessageDigest.HASHLENGTH = { + 'md5': 16, + 'sha1': 20, + 'sha224': 28, + 'sha256': 32, + 'sha384': 48, + 'sha512': 64, + 'ripemd160': 20 +}; + +// === Mac =============================================================== + /** * Mac(Message Authentication Code) class which is very similar to java.security.Mac class * @name KJUR.crypto.Mac @@ -723,6 +807,7 @@ KJUR.crypto.Mac = function(params) { } }; +// ====== Signature class ========================================================= /** * Signature class which is very similar to java.security.Signature class * @name KJUR.crypto.Signature @@ -1201,6 +1286,128 @@ KJUR.crypto.Signature = function(params) { } }; +// ====== Cipher class ============================================================ +/** + * Cipher class to encrypt and decrypt data
      + * @name KJUR.crypto.Cipher + * @param {Array} params parameters for constructor + * @since jsrsasign 6.2.0 crypto 1.1.10 + * @description + * Here is supported canonicalized cipher algorithm names and its standard names: + *
        + *
      • RSA - RSA/ECB/PKCS1Padding (default for RSAKey)
      • + *
      • RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding
      • + *
      • RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)
      • + *
      • RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding
      • + *
      • RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)
      • + *
      • RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)
      • + *
      + * NOTE: (*) is not supported in Java JCE.
      + * Currently this class supports only RSA encryption and decryption. + * However it is planning to implement also symmetric ciphers near in the future. + * @example + */ +KJUR.crypto.Cipher = function(params) { +}; + +/** + * encrypt raw string by specified key and algorithm
      + * @name encrypt + * @memberOf KJUR.crypto.Cipher + * @function + * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key + * @param {String} s input string to encrypt + * @param {String} algName short/long algorithm name for encryption/decryption + * @return {String} hexadecimal encrypted string + * @since jsrsasign 6.2.0 crypto 1.1.10 + * @description + * This static method encrypts raw string with specified key and algorithm. + * @example + * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj) → "1abc2d..." + * KJUR.crypto.Cipher.encrypt("aaa", pubRSAKeyObj, "RSAOAEP) → "23ab02..." + */ +KJUR.crypto.Cipher.encrypt = function(s, keyObj, algName) { + if (keyObj instanceof RSAKey && keyObj.isPublic) { + var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName); + if (algName2 === "RSA") return keyObj.encrypt(s); + if (algName2 === "RSAOAEP") return keyObj.encryptOAEP(s, "sha1"); + + var a = algName2.match(/^RSAOAEP(\d+)$/); + if (a !== null) return keyObj.encryptOAEP(s, "sha" + a[1]); + + throw "Cipher.encrypt: unsupported algorithm for RSAKey: " + algName; + } else { + throw "Cipher.encrypt: unsupported key or algorithm"; + } +}; + +/** + * decrypt encrypted hexadecimal string with specified key and algorithm
      + * @name encrypt + * @memberOf KJUR.crypto.Cipher + * @function + * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key + * @param {String} s input string to encrypt + * @param {String} algName short/long algorithm name for encryption/decryption + * @return {String} hexadecimal encrypted string + * @since jsrsasign 6.2.0 crypto 1.1.10 + * @description + * This static method decrypts encrypted hexadecimal string with specified key and algorithm. + * @example + * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj) → "1abc2d..." + * KJUR.crypto.Cipher.decrypt("aaa", prvRSAKeyObj, "RSAOAEP) → "23ab02..." + */ +KJUR.crypto.Cipher.decrypt = function(hex, keyObj, algName) { + if (keyObj instanceof RSAKey && keyObj.isPrivate) { + var algName2 = KJUR.crypto.Cipher.getAlgByKeyAndName(keyObj, algName); + if (algName2 === "RSA") return keyObj.decrypt(hex); + if (algName2 === "RSAOAEP") return keyObj.decryptOAEP(hex, "sha1"); + + var a = algName2.match(/^RSAOAEP(\d+)$/); + if (a !== null) return keyObj.decryptOAEP(hex, "sha" + a[1]); + + throw "Cipher.decrypt: unsupported algorithm for RSAKey: " + algName; + } else { + throw "Cipher.decrypt: unsupported key or algorithm"; + } +}; + +/** + * get canonicalized encrypt/decrypt algorithm name by key and short/long algorithm name
      + * @name getAlgByKeyAndName + * @memberOf KJUR.crypto.Cipher + * @function + * @param {Object} keyObj RSAKey object or hexadecimal string of symmetric cipher key + * @param {String} algName short/long algorithm name for encryption/decryption + * @return {String} canonicalized algorithm name for encryption/decryption + * @since jsrsasign 6.2.0 crypto 1.1.10 + * @description + * Here is supported canonicalized cipher algorithm names and its standard names: + *
        + *
      • RSA - RSA/ECB/PKCS1Padding (default for RSAKey)
      • + *
      • RSAOAEP - RSA/ECB/OAEPWithSHA-1AndMGF1Padding
      • + *
      • RSAOAEP224 - RSA/ECB/OAEPWithSHA-224AndMGF1Padding(*)
      • + *
      • RSAOAEP256 - RSA/ECB/OAEPWithSHA-256AndMGF1Padding
      • + *
      • RSAOAEP384 - RSA/ECB/OAEPWithSHA-384AndMGF1Padding(*)
      • + *
      • RSAOAEP512 - RSA/ECB/OAEPWithSHA-512AndMGF1Padding(*)
      • + *
      + * NOTE: (*) is not supported in Java JCE. + * @example + * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey) → "RSA" + * KJUR.crypto.Cipher.getAlgByKeyAndName(objRSAKey, "RSAOAEP") → "RSAOAEP" + */ +KJUR.crypto.Cipher.getAlgByKeyAndName = function(keyObj, algName) { + if (keyObj instanceof RSAKey) { + if (":RSA:RSAOAEP:RSAOAEP224:RSAOAEP256:RSAOAEP384:RSAOAEP512:".indexOf(algName) != -1) + return algName; + if (algName === null || algName === undefined) return "RSA"; + throw "getAlgByKeyAndName: not supported algorithm name for RSAKey: " + algName; + } + throw "getAlgByKeyAndName: not supported algorithm name: " + algName; +} + +// ====== Other Utility class ===================================================== + /** * static object for cryptographic function utilities * @name KJUR.crypto.OID @@ -1210,8 +1417,6 @@ KJUR.crypto.Signature = function(params) { * @since crypto 1.1.3 * @description */ - - KJUR.crypto.OID = new function() { this.oidhex2name = { '2a864886f70d010101': 'rsaEncryption', diff --git a/ext/rsa-min.js b/ext/rsa-min.js index bc4d6f83..cc69fe50 100755 --- a/ext/rsa-min.js +++ b/ext/rsa-min.js @@ -1,3 +1,3 @@ /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function parseBigInt(b,a){return new BigInteger(b,a)}function linebrk(c,d){var a="";var b=0;while(b+d=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}var SHA1_SIZE=20;function oaep_pad(l,a,c){if(l.length+2*SHA1_SIZE+2>a){throw"Message too long for RSA"}var h="",d;for(d=0;d0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(e,d){var a=oaep_pad(e,(this.n.bitLength()+7)>>3,d);if(a==null){return null}var f=this.doPublic(a);if(f==null){return null}var b=f.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encryptOAEP=RSAEncryptOAEP;RSAKey.prototype.type="RSA"; \ No newline at end of file +function parseBigInt(b,a){return new BigInteger(b,a)}function linebrk(c,d){var a="";var b=0;while(b+d=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}function oaep_pad(q,a,f,l){var c=KJUR.crypto.MessageDigest;var o=KJUR.crypto.Util;var b=null;if(!f){f="sha1"}if(typeof f==="string"){b=c.getCanonicalAlgName(f);l=c.getHashLength(b);f=function(i){return hextorstr(o.hashString(i,b))}}if(q.length+2*l+2>a){throw"Message too long for RSA"}var k="",e;for(e=0;e0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(f,e,b){var a=oaep_pad(f,(this.n.bitLength()+7)>>3,e,b);if(a==null){return null}var g=this.doPublic(a);if(g==null){return null}var d=g.toString(16);if((d.length&1)==0){return d}else{return"0"+d}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encryptOAEP=RSAEncryptOAEP;RSAKey.prototype.type="RSA"; \ No newline at end of file diff --git a/ext/rsa.js b/ext/rsa.js index ee2f7269..ad98c0aa 100644 --- a/ext/rsa.js +++ b/ext/rsa.js @@ -80,24 +80,42 @@ function oaep_mgf1_arr(seed, len, hash) return mask; } -// PKCS#1 (OAEP) pad input string s to n bytes, and return a bigint -function oaep_pad(s, n, hash, hashLen) -{ - if (!hash) - { - hash = rstr_sha1; - hashLen = 20; +/** + * PKCS#1 (OAEP) pad input string s to n bytes, and return a bigint + * @name oaep_pad + * @param s raw string of message + * @param n key length of RSA key + * @param hash JavaScript function to calculate raw hash value from raw string or algorithm name (ex. "SHA1") + * @param hashLen byte length of resulted hash value (ex. 20 for SHA1) + * @return {BigInteger} BigInteger object of resulted PKCS#1 OAEP padded message + * @description + * This function calculates OAEP padded message from original message.
      + * NOTE: Since jsrsasign 6.2.0, 'hash' argument can accept an algorithm name such as "sha1". + * @example + * oaep_pad("aaa", 128) → big integer object // SHA-1 by default + * oaep_pad("aaa", 128, function(s) {...}, 20); + * oaep_pad("aaa", 128, "sha1"); + */ +function oaep_pad(s, n, hash, hashLen) { + var MD = KJUR.crypto.MessageDigest; + var Util = KJUR.crypto.Util; + var algName = null; + + if (!hash) hash = "sha1"; + + if (typeof hash === "string") { + algName = MD.getCanonicalAlgName(hash); + hashLen = MD.getHashLength(algName); + hash = function(s) { return hextorstr(Util.hashString(s, algName)); }; } - if (s.length + 2 * hashLen + 2 > n) - { + if (s.length + 2 * hashLen + 2 > n) { throw "Message too long for RSA"; } var PS = '', i; - for (i = 0; i < n - s.length - 2 * hashLen - 2; i += 1) - { + for (i = 0; i < n - s.length - 2 * hashLen - 2; i += 1) { PS += '\x00'; } @@ -108,16 +126,14 @@ function oaep_pad(s, n, hash, hashLen) var dbMask = oaep_mgf1_arr(seed, DB.length, hash); var maskedDB = []; - for (i = 0; i < DB.length; i += 1) - { + for (i = 0; i < DB.length; i += 1) { maskedDB[i] = DB.charCodeAt(i) ^ dbMask.charCodeAt(i); } var seedMask = oaep_mgf1_arr(maskedDB, seed.length, hash); var maskedSeed = [0]; - for (i = 0; i < seed.length; i += 1) - { + for (i = 0; i < seed.length; i += 1) { maskedSeed[i + 1] = seed[i] ^ seedMask.charCodeAt(i); } @@ -169,7 +185,7 @@ function RSAEncrypt(text) { // Return the PKCS#1 OAEP RSA encryption of "text" as an even-length hex string function RSAEncryptOAEP(text, hash, hashLen) { - var m = oaep_pad(text, (this.n.bitLength()+7)>>3, hash, hashLen); + var m = oaep_pad(text, (this.n.bitLength() + 7) >> 3, hash, hashLen); if(m == null) return null; var c = this.doPublic(m); if(c == null) return null; diff --git a/ext/rsa2-min.js b/ext/rsa2-min.js index dd4bb11d..fa835aaf 100755 --- a/ext/rsa2-min.js +++ b/ext/rsa2-min.js @@ -1,3 +1,3 @@ /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function pkcs1unpad2(g,j){var a=g.toByteArray();var f=0;while(f=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}var SHA1_SIZE=20;function oaep_unpad(l,b,e){l=l.toByteArray();var f;for(f=0;f0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{alert("Invalid RSA private key")}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{alert("Invalid RSA private key in RSASetPrivateEx")}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(d,b){var e=parseBigInt(d,16);var a=this.doPrivate(e);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; \ No newline at end of file +function pkcs1unpad2(g,j){var a=g.toByteArray();var f=0;while(f=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashString(d,c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{alert("Invalid RSA private key")}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{alert("Invalid RSA private key in RSASetPrivateEx")}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; \ No newline at end of file diff --git a/ext/rsa2.js b/ext/rsa2.js index 3619e3dd..b7adeba3 100644 --- a/ext/rsa2.js +++ b/ext/rsa2.js @@ -50,33 +50,50 @@ function oaep_mgf1_str(seed, len, hash) return mask; } -// Undo PKCS#1 (OAEP) padding and, if valid, return the plaintext -function oaep_unpad(d, n, hash, hashLen) -{ - if (!hash) - { - hash = rstr_sha1; - hashLen = 20; +/** + * Undo PKCS#1 (OAEP) padding and, if valid, return the plaintext + * @name oaep_unpad + * @param {BigInteger} d BigInteger object of OAEP padded message + * @param n byte length of RSA key (i.e. 128 when RSA 1024bit) + * @param hash JavaScript function to calculate raw hash value from raw string or algorithm name (ex. "SHA1") + * @param hashLen byte length of resulted hash value (i.e. 20 for SHA1) + * @return {String} raw string of OAEP unpadded message + * @description + * This function do unpadding OAEP padded message then returns an original message.
      + * NOTE: Since jsrsasign 6.2.0, 'hash' argument can accept an algorithm name such as "sha1". + * @example + * // DEFAULT(SHA1) + * bi1 = oaep_pad("aaa", 128); + * oaep_unpad(bi1, 128) → "aaa" // SHA-1 by default + */ +function oaep_unpad(d, n, hash, hashLen) { + var MD = KJUR.crypto.MessageDigest; + var Util = KJUR.crypto.Util; + var algName = null; + + if (!hash) hash = "sha1"; + + if (typeof hash === "string") { + algName = MD.getCanonicalAlgName(hash); + hashLen = MD.getHashLength(algName); + hash = function(s) { return hextorstr(Util.hashString(s, algName)); }; } d = d.toByteArray(); var i; - for (i = 0; i < d.length; i += 1) - { + for (i = 0; i < d.length; i += 1) { d[i] &= 0xff; } - while (d.length < n) - { + while (d.length < n) { d.unshift(0); } d = String.fromCharCode.apply(String, d); - if (d.length < 2 * hashLen + 2) - { + if (d.length < 2 * hashLen + 2) { throw "Cipher too short"; } @@ -86,25 +103,22 @@ function oaep_unpad(d, n, hash, hashLen) var seedMask = oaep_mgf1_str(maskedDB, hashLen, hash); var seed = [], i; - for (i = 0; i < maskedSeed.length; i += 1) - { + for (i = 0; i < maskedSeed.length; i += 1) { seed[i] = maskedSeed.charCodeAt(i) ^ seedMask.charCodeAt(i); } var dbMask = oaep_mgf1_str(String.fromCharCode.apply(String, seed), - d.length - hashLen, hash); + d.length - hashLen, hash); var DB = []; - for (i = 0; i < maskedDB.length; i += 1) - { + for (i = 0; i < maskedDB.length; i += 1) { DB[i] = maskedDB.charCodeAt(i) ^ dbMask.charCodeAt(i); } DB = String.fromCharCode.apply(String, DB); - if (DB.substr(0, hashLen) !== hash('')) - { + if (DB.substr(0, hashLen) !== hash('')) { throw "Hash mismatch"; } @@ -113,8 +127,7 @@ function oaep_unpad(d, n, hash, hashLen) var first_one = DB.indexOf('\x01'); var last_zero = (first_one != -1) ? DB.substr(0, first_one).lastIndexOf('\x00') : -1; - if (last_zero + 1 != first_one) - { + if (last_zero + 1 != first_one) { throw "Malformed data"; } diff --git a/index.html b/index.html index 94ccf57c..298407c1 100755 --- a/index.html +++ b/index.html @@ -69,6 +69,11 @@

      FEATURES

      NEWS

      +
      2016-Nov-03: +
      +Release 6.2.0 is now available. +Cipher class added. +
      2016-Sep-24:
      Release 6.1.0 is now available. diff --git a/jsrsasign-latest-all-min.js b/jsrsasign-latest-all-min.js index a0ce0d7f..f12cb88b 100644 --- a/jsrsasign-latest-all-min.js +++ b/jsrsasign-latest-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign 6.1.4 (2016-10-16) (c) 2010-2016 Kenji Urushima | kjur.github.com/jsrsasign/license + * jsrsasign 6.2.0 (2016-11-03) (c) 2010-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* @@ -214,10 +214,10 @@ function Arcfour(){this.i=0;this.j=0;this.S=new Array()}function ARC4init(d){var var rng_state;var rng_pool;var rng_pptr;function rng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=(a>>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=new Array();rng_pptr=0;var t;if(window.crypto&&window.crypto.getRandomValues){var ua=new Uint8Array(32);window.crypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}var SHA1_SIZE=20;function oaep_pad(l,a,c){if(l.length+2*SHA1_SIZE+2>a){throw"Message too long for RSA"}var h="",d;for(d=0;d0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(e,d){var a=oaep_pad(e,(this.n.bitLength()+7)>>3,d);if(a==null){return null}var f=this.doPublic(a);if(f==null){return null}var b=f.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encryptOAEP=RSAEncryptOAEP;RSAKey.prototype.type="RSA"; +function parseBigInt(b,a){return new BigInteger(b,a)}function linebrk(c,d){var a="";var b=0;while(b+d=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}function oaep_pad(q,a,f,l){var c=KJUR.crypto.MessageDigest;var o=KJUR.crypto.Util;var b=null;if(!f){f="sha1"}if(typeof f==="string"){b=c.getCanonicalAlgName(f);l=c.getHashLength(b);f=function(i){return hextorstr(o.hashString(i,b))}}if(q.length+2*l+2>a){throw"Message too long for RSA"}var k="",e;for(e=0;e0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(f,e,b){var a=oaep_pad(f,(this.n.bitLength()+7)>>3,e,b);if(a==null){return null}var g=this.doPublic(a);if(g==null){return null}var d=g.toString(16);if((d.length&1)==0){return d}else{return"0"+d}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encryptOAEP=RSAEncryptOAEP;RSAKey.prototype.type="RSA"; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function pkcs1unpad2(g,j){var a=g.toByteArray();var f=0;while(f=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}var SHA1_SIZE=20;function oaep_unpad(l,b,e){l=l.toByteArray();var f;for(f=0;f0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{alert("Invalid RSA private key")}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{alert("Invalid RSA private key in RSASetPrivateEx")}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(d,b){var e=parseBigInt(d,16);var a=this.doPrivate(e);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; +function pkcs1unpad2(g,j){var a=g.toByteArray();var f=0;while(f=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashString(d,c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{alert("Invalid RSA private key")}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{alert("Invalid RSA private key in RSASetPrivateEx")}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ function ECFieldElementFp(b,a){this.x=a;this.q=b}function feFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.x.equals(a.x))}function feFpToBigInteger(){return this.x}function feFpNegate(){return new ECFieldElementFp(this.q,this.x.negate().mod(this.q))}function feFpAdd(a){return new ECFieldElementFp(this.q,this.x.add(a.toBigInteger()).mod(this.q))}function feFpSubtract(a){return new ECFieldElementFp(this.q,this.x.subtract(a.toBigInteger()).mod(this.q))}function feFpMultiply(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger()).mod(this.q))}function feFpSquare(){return new ECFieldElementFp(this.q,this.x.square().mod(this.q))}function feFpDivide(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger().modInverse(this.q)).mod(this.q))}ECFieldElementFp.prototype.equals=feFpEquals;ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger;ECFieldElementFp.prototype.negate=feFpNegate;ECFieldElementFp.prototype.add=feFpAdd;ECFieldElementFp.prototype.subtract=feFpSubtract;ECFieldElementFp.prototype.multiply=feFpMultiply;ECFieldElementFp.prototype.square=feFpSquare;ECFieldElementFp.prototype.divide=feFpDivide;function ECPointFp(c,a,d,b){this.curve=c;this.x=a;this.y=d;if(b==null){this.z=BigInteger.ONE}else{this.z=b}this.zinv=null}function pointFpGetX(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpGetY(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpEquals(a){if(a==this){return true}if(this.isInfinity()){return a.isInfinity()}if(a.isInfinity()){return this.isInfinity()}var c,b;c=a.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(a.z)).mod(this.curve.q);if(!c.equals(BigInteger.ZERO)){return false}b=a.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(a.z)).mod(this.curve.q);return b.equals(BigInteger.ZERO)}function pointFpIsInfinity(){if((this.x==null)&&(this.y==null)){return true}return this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(l){if(this.isInfinity()){return l}if(l.isInfinity()){return this}var p=l.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(l.z)).mod(this.curve.q);var o=l.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(l.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(o)){if(BigInteger.ZERO.equals(p)){return this.twice()}return this.curve.getInfinity()}var j=new BigInteger("3");var e=this.x.toBigInteger();var n=this.y.toBigInteger();var c=l.x.toBigInteger();var k=l.y.toBigInteger();var m=o.square();var i=m.multiply(o);var d=e.multiply(m);var g=p.square().multiply(this.z);var a=g.subtract(d.shiftLeft(1)).multiply(l.z).subtract(i).multiply(o).mod(this.curve.q);var h=d.multiply(j).multiply(p).subtract(n.multiply(i)).subtract(g.multiply(p)).multiply(l.z).add(p.multiply(i)).mod(this.curve.q);var f=i.multiply(this.z).multiply(l.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(h),f)}function pointFpTwice(){if(this.isInfinity()){return this}if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var g=new BigInteger("3");var c=this.x.toBigInteger();var h=this.y.toBigInteger();var e=h.multiply(this.z);var j=e.multiply(h).mod(this.curve.q);var i=this.curve.a.toBigInteger();var k=c.square().multiply(g);if(!BigInteger.ZERO.equals(i)){k=k.add(this.z.square().multiply(i))}k=k.mod(this.curve.q);var b=k.square().subtract(c.shiftLeft(3).multiply(j)).shiftLeft(1).multiply(e).mod(this.curve.q);var f=k.multiply(g).multiply(c).subtract(j.shiftLeft(1)).shiftLeft(2).multiply(j).subtract(k.square().multiply(k)).mod(this.curve.q);var d=e.square().multiply(e).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(b),this.curve.fromBigInteger(f),d)}function pointFpMultiply(b){if(this.isInfinity()){return this}if(b.signum()==0){return this.curve.getInfinity()}var g=b;var f=g.multiply(new BigInteger("3"));var l=this.negate();var d=this;var c;for(c=f.bitLength()-2;c>0;--c){d=d.twice();var a=f.testBit(c);var j=g.testBit(c);if(a!=j){d=d.add(a?this:l)}}return d}function pointFpMultiplyTwo(c,a,b){var d;if(c.bitLength()>b.bitLength()){d=c.bitLength()-1}else{d=b.bitLength()-1}var f=this.curve.getInfinity();var e=this.add(a);while(d>=0){f=f.twice();if(c.testBit(d)){if(b.testBit(d)){f=f.add(e)}else{f=f.add(this)}}else{if(b.testBit(d)){f=f.add(a)}}--d}return f}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(e,d,c){this.q=e;this.a=this.fromBigInteger(d);this.b=this.fromBigInteger(c);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.a.equals(a.a)&&this.b.equals(a.b))}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(a){return new ECFieldElementFp(this.q,a)}function curveFpDecodePointHex(d){switch(parseInt(d.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var a=(d.length-2)/2;var c=d.substr(2,a);var b=d.substr(a+2,a);return new ECPointFp(this,this.fromBigInteger(new BigInteger(c,16)),this.fromBigInteger(new BigInteger(b,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger;ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex; @@ -254,9 +254,9 @@ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!K /*! base64x-1.1.8 (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;ca.length){d=a.length}for(var b=0;bd){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;fd){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--p){q=q.twice2D();q.z=BigInteger.ONE;if(o.testBit(p)){if(n.testBit(p)){q=q.add2D(t)}else{q=q.add2D(s)}}else{if(n.testBit(p)){q=q.add2D(r)}}}return q}this.getBigRandom=function(i){return new BigInteger(i.bitLength(),a).mod(i.subtract(BigInteger.ONE)).add(BigInteger.ONE)};this.setNamedCurve=function(i){this.ecparams=KJUR.crypto.ECParameterDB.getByName(i);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=i};this.setPrivateKeyHex=function(i){this.isPrivate=true;this.prvKeyHex=i};this.setPublicKeyHex=function(i){this.isPublic=true;this.pubKeyHex=i};this.getPublicKeyXYHex=function(){var k=this.pubKeyHex;if(k.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var j=this.ecparams.keylen/4;if(k.length!==2+j*2){throw"malformed public key hex length"}var i={};i.x=k.substr(2,j);i.y=k.substr(2+j);return i};this.getShortNISTPCurveName=function(){var i=this.curveName;if(i==="secp256r1"||i==="NIST P-256"||i==="P-256"||i==="prime256v1"){return"P-256"}if(i==="secp384r1"||i==="NIST P-384"||i==="P-384"){return"P-384"}return null};this.generateKeyPairHex=function(){var k=this.ecparams.n;var n=this.getBigRandom(k);var l=this.ecparams.G.multiply(n);var q=l.getX().toBigInteger();var o=l.getY().toBigInteger();var i=this.ecparams.keylen/4;var m=("0000000000"+n.toString(16)).slice(-i);var r=("0000000000"+q.toString(16)).slice(-i);var p=("0000000000"+o.toString(16)).slice(-i);var j="04"+r+p;this.setPrivateKeyHex(m);this.setPublicKeyHex(j);return{ecprvhex:m,ecpubhex:j}};this.signWithMessageHash=function(i){return this.signHex(i,this.prvKeyHex)};this.signHex=function(o,j){var t=new BigInteger(j,16);var l=this.ecparams.n;var q=new BigInteger(o,16);do{var m=this.getBigRandom(l);var u=this.ecparams.G;var p=u.multiply(m);var i=p.getX().toBigInteger().mod(l)}while(i.compareTo(BigInteger.ZERO)<=0);var v=m.modInverse(l).multiply(q.add(t.multiply(i))).mod(l);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(i,v)};this.sign=function(m,u){var q=u;var j=this.ecparams.n;var p=BigInteger.fromByteArrayUnsigned(m);do{var l=this.getBigRandom(j);var t=this.ecparams.G;var o=t.multiply(l);var i=o.getX().toBigInteger().mod(j)}while(i.compareTo(BigInteger.ZERO)<=0);var v=l.modInverse(j).multiply(p.add(q.multiply(i))).mod(j);return this.serializeSig(i,v)};this.verifyWithMessageHash=function(j,i){return this.verifyHex(j,i,this.pubKeyHex)};this.verifyHex=function(m,i,p){var l,j;var o=KJUR.crypto.ECDSA.parseSigHex(i);l=o.r;j=o.s;var k;k=ECPointFp.decodeFromHex(this.ecparams.curve,p);var n=new BigInteger(m,16);return this.verifyRaw(n,l,j,k)};this.verify=function(o,p,j){var l,i;if(Bitcoin.Util.isArray(p)){var n=this.parseSig(p);l=n.r;i=n.s}else{if("object"===typeof p&&p.r&&p.s){l=p.r;i=p.s}else{throw"Invalid value for signature"}}var k;if(j instanceof ECPointFp){k=j}else{if(Bitcoin.Util.isArray(j)){k=ECPointFp.decodeFrom(this.ecparams.curve,j)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var m=BigInteger.fromByteArrayUnsigned(o);return this.verifyRaw(m,l,i,k)};this.verifyRaw=function(o,i,w,m){var l=this.ecparams.n;var u=this.ecparams.G;if(i.compareTo(BigInteger.ONE)<0||i.compareTo(l)>=0){return false}if(w.compareTo(BigInteger.ONE)<0||w.compareTo(l)>=0){return false}var p=w.modInverse(l);var k=o.multiply(p).mod(l);var j=i.multiply(p).mod(l);var q=u.multiply(k).add(m.multiply(j));var t=q.getX().toBigInteger().mod(l);return t.equals(i)};this.serializeSig=function(k,j){var l=k.toByteArraySigned();var i=j.toByteArraySigned();var m=[];m.push(2);m.push(l.length);m=m.concat(l);m.push(2);m.push(i.length);m=m.concat(i);m.unshift(m.length);m.unshift(48);return m};this.parseSig=function(n){var m;if(n[0]!=48){throw new Error("Signature not a valid DERSequence")}m=2;if(n[m]!=2){throw new Error("First element in signature must be a DERInteger")}var l=n.slice(m+2,m+2+n[m+1]);m+=2+n[m+1];if(n[m]!=2){throw new Error("Second element in signature must be a DERInteger")}var i=n.slice(m+2,m+2+n[m+1]);m+=2+n[m+1];var k=BigInteger.fromByteArrayUnsigned(l);var j=BigInteger.fromByteArrayUnsigned(i);return{r:k,s:j}};this.parseSigCompact=function(m){if(m.length!==65){throw"Signature has the wrong length"}var j=m[0]-27;if(j<0||j>7){throw"Invalid signature type"}var o=this.ecparams.n;var l=BigInteger.fromByteArrayUnsigned(m.slice(1,33)).mod(o);var k=BigInteger.fromByteArrayUnsigned(m.slice(33,65)).mod(o);return{r:l,s:k,i:j}};if(h!==undefined){if(h.curve!==undefined){this.curveName=h.curve}}if(this.curveName===undefined){this.curveName=e}this.setNamedCurve(this.curveName);if(h!==undefined){if(h.prv!==undefined){this.setPrivateKeyHex(h.prv)}if(h.pub!==undefined){this.setPublicKeyHex(h.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(c){if(c.substr(0,2)!="30"){throw"signature is not a ASN.1 sequence"}var b=ASN1HEX.getPosArrayOfChildren_AtObj(c,0);if(b.length!=2){throw"number of signature ASN.1 sequence elements seem wrong"}var g=b[0];var f=b[1];if(c.substr(g,2)!="02"){throw"1st item of sequene of signature is not ASN.1 integer"}if(c.substr(f,2)!="02"){throw"2nd item of sequene of signature is not ASN.1 integer"}var e=ASN1HEX.getHexOfV_AtObj(c,g);var d=ASN1HEX.getHexOfV_AtObj(c,f);return{r:e,s:d}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(c){var d=KJUR.crypto.ECDSA.parseSigHexInHexRS(c);var b=d.r;var a=d.s;if(b.substr(0,2)=="00"&&(((b.length/2)*8)%(16*8))==8){b=b.substr(2)}if(a.substr(0,2)=="00"&&(((a.length/2)*8)%(16*8))==8){a=a.substr(2)}if((((b.length/2)*8)%(16*8))!=0){throw"unknown ECDSA sig r length error"}if((((a.length/2)*8)%(16*8))!=0){throw"unknown ECDSA sig s length error"}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if((((a.length/2)*8)%(16*8))!=0){throw"unknown ECDSA concatinated r-s sig length error"}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(e,c){var b=new KJUR.asn1.DERInteger({bigint:e});var a=new KJUR.asn1.DERInteger({bigint:c});var d=new KJUR.asn1.DERSequence({array:[b,a]});return d.getEncodedHex()}; diff --git a/min/crypto-1.1.min.js b/min/crypto-1.1.min.js index 27cbbfb5..6d9bea0f 100644 --- a/min/crypto-1.1.min.js +++ b/min/crypto-1.1.min.js @@ -1,3 +1,3 @@ -/*! crypto-1.1.9.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! crypto-1.1.10.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;fd){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=new Array();rng_pptr=0;var t;if(window.crypto&&window.crypto.getRandomValues){var ua=new Uint8Array(32);window.crypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}var SHA1_SIZE=20;function oaep_pad(l,a,c){if(l.length+2*SHA1_SIZE+2>a){throw"Message too long for RSA"}var h="",d;for(d=0;d0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(e,d){var a=oaep_pad(e,(this.n.bitLength()+7)>>3,d);if(a==null){return null}var f=this.doPublic(a);if(f==null){return null}var b=f.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encryptOAEP=RSAEncryptOAEP;RSAKey.prototype.type="RSA"; +function parseBigInt(b,a){return new BigInteger(b,a)}function linebrk(c,d){var a="";var b=0;while(b+d=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}function oaep_pad(q,a,f,l){var c=KJUR.crypto.MessageDigest;var o=KJUR.crypto.Util;var b=null;if(!f){f="sha1"}if(typeof f==="string"){b=c.getCanonicalAlgName(f);l=c.getHashLength(b);f=function(i){return hextorstr(o.hashString(i,b))}}if(q.length+2*l+2>a){throw"Message too long for RSA"}var k="",e;for(e=0;e0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(f,e,b){var a=oaep_pad(f,(this.n.bitLength()+7)>>3,e,b);if(a==null){return null}var g=this.doPublic(a);if(g==null){return null}var d=g.toString(16);if((d.length&1)==0){return d}else{return"0"+d}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encryptOAEP=RSAEncryptOAEP;RSAKey.prototype.type="RSA"; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ -function pkcs1unpad2(g,j){var a=g.toByteArray();var f=0;while(f=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}var SHA1_SIZE=20;function oaep_unpad(l,b,e){l=l.toByteArray();var f;for(f=0;f0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{alert("Invalid RSA private key")}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{alert("Invalid RSA private key in RSASetPrivateEx")}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(d,b){var e=parseBigInt(d,16);var a=this.doPrivate(e);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; +function pkcs1unpad2(g,j){var a=g.toByteArray();var f=0;while(f=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashString(d,c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{alert("Invalid RSA private key")}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{alert("Invalid RSA private key in RSASetPrivateEx")}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ function ECFieldElementFp(b,a){this.x=a;this.q=b}function feFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.x.equals(a.x))}function feFpToBigInteger(){return this.x}function feFpNegate(){return new ECFieldElementFp(this.q,this.x.negate().mod(this.q))}function feFpAdd(a){return new ECFieldElementFp(this.q,this.x.add(a.toBigInteger()).mod(this.q))}function feFpSubtract(a){return new ECFieldElementFp(this.q,this.x.subtract(a.toBigInteger()).mod(this.q))}function feFpMultiply(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger()).mod(this.q))}function feFpSquare(){return new ECFieldElementFp(this.q,this.x.square().mod(this.q))}function feFpDivide(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger().modInverse(this.q)).mod(this.q))}ECFieldElementFp.prototype.equals=feFpEquals;ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger;ECFieldElementFp.prototype.negate=feFpNegate;ECFieldElementFp.prototype.add=feFpAdd;ECFieldElementFp.prototype.subtract=feFpSubtract;ECFieldElementFp.prototype.multiply=feFpMultiply;ECFieldElementFp.prototype.square=feFpSquare;ECFieldElementFp.prototype.divide=feFpDivide;function ECPointFp(c,a,d,b){this.curve=c;this.x=a;this.y=d;if(b==null){this.z=BigInteger.ONE}else{this.z=b}this.zinv=null}function pointFpGetX(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpGetY(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpEquals(a){if(a==this){return true}if(this.isInfinity()){return a.isInfinity()}if(a.isInfinity()){return this.isInfinity()}var c,b;c=a.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(a.z)).mod(this.curve.q);if(!c.equals(BigInteger.ZERO)){return false}b=a.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(a.z)).mod(this.curve.q);return b.equals(BigInteger.ZERO)}function pointFpIsInfinity(){if((this.x==null)&&(this.y==null)){return true}return this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(l){if(this.isInfinity()){return l}if(l.isInfinity()){return this}var p=l.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(l.z)).mod(this.curve.q);var o=l.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(l.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(o)){if(BigInteger.ZERO.equals(p)){return this.twice()}return this.curve.getInfinity()}var j=new BigInteger("3");var e=this.x.toBigInteger();var n=this.y.toBigInteger();var c=l.x.toBigInteger();var k=l.y.toBigInteger();var m=o.square();var i=m.multiply(o);var d=e.multiply(m);var g=p.square().multiply(this.z);var a=g.subtract(d.shiftLeft(1)).multiply(l.z).subtract(i).multiply(o).mod(this.curve.q);var h=d.multiply(j).multiply(p).subtract(n.multiply(i)).subtract(g.multiply(p)).multiply(l.z).add(p.multiply(i)).mod(this.curve.q);var f=i.multiply(this.z).multiply(l.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(h),f)}function pointFpTwice(){if(this.isInfinity()){return this}if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var g=new BigInteger("3");var c=this.x.toBigInteger();var h=this.y.toBigInteger();var e=h.multiply(this.z);var j=e.multiply(h).mod(this.curve.q);var i=this.curve.a.toBigInteger();var k=c.square().multiply(g);if(!BigInteger.ZERO.equals(i)){k=k.add(this.z.square().multiply(i))}k=k.mod(this.curve.q);var b=k.square().subtract(c.shiftLeft(3).multiply(j)).shiftLeft(1).multiply(e).mod(this.curve.q);var f=k.multiply(g).multiply(c).subtract(j.shiftLeft(1)).shiftLeft(2).multiply(j).subtract(k.square().multiply(k)).mod(this.curve.q);var d=e.square().multiply(e).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(b),this.curve.fromBigInteger(f),d)}function pointFpMultiply(b){if(this.isInfinity()){return this}if(b.signum()==0){return this.curve.getInfinity()}var g=b;var f=g.multiply(new BigInteger("3"));var l=this.negate();var d=this;var c;for(c=f.bitLength()-2;c>0;--c){d=d.twice();var a=f.testBit(c);var j=g.testBit(c);if(a!=j){d=d.add(a?this:l)}}return d}function pointFpMultiplyTwo(c,a,b){var d;if(c.bitLength()>b.bitLength()){d=c.bitLength()-1}else{d=b.bitLength()-1}var f=this.curve.getInfinity();var e=this.add(a);while(d>=0){f=f.twice();if(c.testBit(d)){if(b.testBit(d)){f=f.add(e)}else{f=f.add(this)}}else{if(b.testBit(d)){f=f.add(a)}}--d}return f}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(e,d,c){this.q=e;this.a=this.fromBigInteger(d);this.b=this.fromBigInteger(c);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.a.equals(a.a)&&this.b.equals(a.b))}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(a){return new ECFieldElementFp(this.q,a)}function curveFpDecodePointHex(d){switch(parseInt(d.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var a=(d.length-2)/2;var c=d.substr(2,a);var b=d.substr(a+2,a);return new ECPointFp(this,this.fromBigInteger(new BigInteger(c,16)),this.fromBigInteger(new BigInteger(b,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger;ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex; @@ -259,9 +259,9 @@ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!K /*! base64x-1.1.8 (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ var KJUR;if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.lang=="undefined"||!KJUR.lang){KJUR.lang={}}KJUR.lang.String=function(){};function Base64x(){}function stoBA(d){var b=new Array();for(var c=0;ca.length){d=a.length}for(var b=0;bd){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;fd){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--p){q=q.twice2D();q.z=BigInteger.ONE;if(o.testBit(p)){if(n.testBit(p)){q=q.add2D(t)}else{q=q.add2D(s)}}else{if(n.testBit(p)){q=q.add2D(r)}}}return q}this.getBigRandom=function(i){return new BigInteger(i.bitLength(),a).mod(i.subtract(BigInteger.ONE)).add(BigInteger.ONE)};this.setNamedCurve=function(i){this.ecparams=KJUR.crypto.ECParameterDB.getByName(i);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=i};this.setPrivateKeyHex=function(i){this.isPrivate=true;this.prvKeyHex=i};this.setPublicKeyHex=function(i){this.isPublic=true;this.pubKeyHex=i};this.getPublicKeyXYHex=function(){var k=this.pubKeyHex;if(k.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var j=this.ecparams.keylen/4;if(k.length!==2+j*2){throw"malformed public key hex length"}var i={};i.x=k.substr(2,j);i.y=k.substr(2+j);return i};this.getShortNISTPCurveName=function(){var i=this.curveName;if(i==="secp256r1"||i==="NIST P-256"||i==="P-256"||i==="prime256v1"){return"P-256"}if(i==="secp384r1"||i==="NIST P-384"||i==="P-384"){return"P-384"}return null};this.generateKeyPairHex=function(){var k=this.ecparams.n;var n=this.getBigRandom(k);var l=this.ecparams.G.multiply(n);var q=l.getX().toBigInteger();var o=l.getY().toBigInteger();var i=this.ecparams.keylen/4;var m=("0000000000"+n.toString(16)).slice(-i);var r=("0000000000"+q.toString(16)).slice(-i);var p=("0000000000"+o.toString(16)).slice(-i);var j="04"+r+p;this.setPrivateKeyHex(m);this.setPublicKeyHex(j);return{ecprvhex:m,ecpubhex:j}};this.signWithMessageHash=function(i){return this.signHex(i,this.prvKeyHex)};this.signHex=function(o,j){var t=new BigInteger(j,16);var l=this.ecparams.n;var q=new BigInteger(o,16);do{var m=this.getBigRandom(l);var u=this.ecparams.G;var p=u.multiply(m);var i=p.getX().toBigInteger().mod(l)}while(i.compareTo(BigInteger.ZERO)<=0);var v=m.modInverse(l).multiply(q.add(t.multiply(i))).mod(l);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(i,v)};this.sign=function(m,u){var q=u;var j=this.ecparams.n;var p=BigInteger.fromByteArrayUnsigned(m);do{var l=this.getBigRandom(j);var t=this.ecparams.G;var o=t.multiply(l);var i=o.getX().toBigInteger().mod(j)}while(i.compareTo(BigInteger.ZERO)<=0);var v=l.modInverse(j).multiply(p.add(q.multiply(i))).mod(j);return this.serializeSig(i,v)};this.verifyWithMessageHash=function(j,i){return this.verifyHex(j,i,this.pubKeyHex)};this.verifyHex=function(m,i,p){var l,j;var o=KJUR.crypto.ECDSA.parseSigHex(i);l=o.r;j=o.s;var k;k=ECPointFp.decodeFromHex(this.ecparams.curve,p);var n=new BigInteger(m,16);return this.verifyRaw(n,l,j,k)};this.verify=function(o,p,j){var l,i;if(Bitcoin.Util.isArray(p)){var n=this.parseSig(p);l=n.r;i=n.s}else{if("object"===typeof p&&p.r&&p.s){l=p.r;i=p.s}else{throw"Invalid value for signature"}}var k;if(j instanceof ECPointFp){k=j}else{if(Bitcoin.Util.isArray(j)){k=ECPointFp.decodeFrom(this.ecparams.curve,j)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var m=BigInteger.fromByteArrayUnsigned(o);return this.verifyRaw(m,l,i,k)};this.verifyRaw=function(o,i,w,m){var l=this.ecparams.n;var u=this.ecparams.G;if(i.compareTo(BigInteger.ONE)<0||i.compareTo(l)>=0){return false}if(w.compareTo(BigInteger.ONE)<0||w.compareTo(l)>=0){return false}var p=w.modInverse(l);var k=o.multiply(p).mod(l);var j=i.multiply(p).mod(l);var q=u.multiply(k).add(m.multiply(j));var t=q.getX().toBigInteger().mod(l);return t.equals(i)};this.serializeSig=function(k,j){var l=k.toByteArraySigned();var i=j.toByteArraySigned();var m=[];m.push(2);m.push(l.length);m=m.concat(l);m.push(2);m.push(i.length);m=m.concat(i);m.unshift(m.length);m.unshift(48);return m};this.parseSig=function(n){var m;if(n[0]!=48){throw new Error("Signature not a valid DERSequence")}m=2;if(n[m]!=2){throw new Error("First element in signature must be a DERInteger")}var l=n.slice(m+2,m+2+n[m+1]);m+=2+n[m+1];if(n[m]!=2){throw new Error("Second element in signature must be a DERInteger")}var i=n.slice(m+2,m+2+n[m+1]);m+=2+n[m+1];var k=BigInteger.fromByteArrayUnsigned(l);var j=BigInteger.fromByteArrayUnsigned(i);return{r:k,s:j}};this.parseSigCompact=function(m){if(m.length!==65){throw"Signature has the wrong length"}var j=m[0]-27;if(j<0||j>7){throw"Invalid signature type"}var o=this.ecparams.n;var l=BigInteger.fromByteArrayUnsigned(m.slice(1,33)).mod(o);var k=BigInteger.fromByteArrayUnsigned(m.slice(33,65)).mod(o);return{r:l,s:k,i:j}};if(h!==undefined){if(h.curve!==undefined){this.curveName=h.curve}}if(this.curveName===undefined){this.curveName=e}this.setNamedCurve(this.curveName);if(h!==undefined){if(h.prv!==undefined){this.setPrivateKeyHex(h.prv)}if(h.pub!==undefined){this.setPublicKeyHex(h.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(c){if(c.substr(0,2)!="30"){throw"signature is not a ASN.1 sequence"}var b=ASN1HEX.getPosArrayOfChildren_AtObj(c,0);if(b.length!=2){throw"number of signature ASN.1 sequence elements seem wrong"}var g=b[0];var f=b[1];if(c.substr(g,2)!="02"){throw"1st item of sequene of signature is not ASN.1 integer"}if(c.substr(f,2)!="02"){throw"2nd item of sequene of signature is not ASN.1 integer"}var e=ASN1HEX.getHexOfV_AtObj(c,g);var d=ASN1HEX.getHexOfV_AtObj(c,f);return{r:e,s:d}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(c){var d=KJUR.crypto.ECDSA.parseSigHexInHexRS(c);var b=d.r;var a=d.s;if(b.substr(0,2)=="00"&&(((b.length/2)*8)%(16*8))==8){b=b.substr(2)}if(a.substr(0,2)=="00"&&(((a.length/2)*8)%(16*8))==8){a=a.substr(2)}if((((b.length/2)*8)%(16*8))!=0){throw"unknown ECDSA sig r length error"}if((((a.length/2)*8)%(16*8))!=0){throw"unknown ECDSA sig s length error"}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if((((a.length/2)*8)%(16*8))!=0){throw"unknown ECDSA concatinated r-s sig length error"}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(e,c){var b=new KJUR.asn1.DERInteger({bigint:e});var a=new KJUR.asn1.DERInteger({bigint:c});var d=new KJUR.asn1.DERSequence({array:[b,a]});return d.getEncodedHex()}; @@ -302,6 +302,7 @@ exports.DSA = KJUR.crypto.DSA; exports.Signature = KJUR.crypto.Signature; exports.MessageDigest = KJUR.crypto.MessageDigest; exports.Mac = KJUR.crypto.Mac; +exports.Cipher = KJUR.crypto.Cipher; exports.KEYUTIL = KEYUTIL; exports.ASN1HEX = ASN1HEX; exports.X509 = X509; @@ -337,7 +338,13 @@ exports.newline_toUnix = newline_toUnix; exports.newline_toDos = newline_toDos; exports.intarystrtohex = intarystrtohex; exports.strdiffidx = strdiffidx; +exports.hextob64 = hextob64; +exports.hextob64nl = hextob64nl; +exports.b64nltohex = b64nltohex; +exports.hextoArrayBuffer = hextoArrayBuffer; +exports.ArrayBuffertohex = ArrayBuffertohex; +// name spaces exports.KJUR = KJUR; exports.crypto = KJUR.crypto; exports.asn1 = KJUR.asn1; diff --git a/npm/package.json b/npm/package.json index 9cead18e..a47b1941 100755 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "jsrsasign", - "version": "6.1.4", + "version": "6.2.0", "description": "opensource free pure JavaScript cryptographic library supports RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp and CAdES and JSON Web Signature(JWS)/Token(JWT)/Key(JWK).", "main": "lib/jsrsasign.js", "scripts": { @@ -11,6 +11,7 @@ "url": "https://github.com/kjur/jsrsasign.git" }, "keywords": [ + "crypto", "cryptography", "Cipher", "RSA", "ECDSA", "DSA", "RSAPSS", "PKCS#1", "PKCS#5", "PKCS#8", "private key", "public key", "CSR", "PKCS#10", diff --git a/test/index.html b/test/index.html index 3e4bada7..781332f1 100755 --- a/test/index.html +++ b/test/index.html @@ -28,9 +28,11 @@
    • qunit-do-asn1x509-newcrt.html
    • qunit-do-asn1x509.html
    • qunit-do-base64x.html
    • +
    • qunit-do-crypto-cipher.html
    • qunit-do-crypto-ecdsa.html
    • qunit-do-crypto-mac.html
    • qunit-do-crypto-mac2.html
    • +
    • qunit-do-crypto-md.html
    • qunit-do-crypto-pss.html
    • qunit-do-crypto-sigini.html
    • qunit-do-crypto-siginidsa.html
    • diff --git a/test/qunit-do-crypto-cipher.html b/test/qunit-do-crypto-cipher.html new file mode 100644 index 00000000..6c8ee6d6 --- /dev/null +++ b/test/qunit-do-crypto-cipher.html @@ -0,0 +1,72 @@ + + + +QUnit for KJUR.crypto.Cipher + + + + + + + + + + + + + +
      +
      test markup
      +QUnit for +INDEX | + +

      © 2016 Kenji Urushima

      + + + diff --git a/test/qunit-do-crypto-md.html b/test/qunit-do-crypto-md.html new file mode 100644 index 00000000..6b858a0b --- /dev/null +++ b/test/qunit-do-crypto-md.html @@ -0,0 +1,62 @@ + + + +QUnit for KJUR.crypto.MessageDigest + + + + + + + + + + + + + +
      +
      test markup
      +QUnit for +INDEX | + +

      © 2016 Kenji Urushima

      + + +