From 77a87f5617bb45179c9776baa80a0bfa767fe57a Mon Sep 17 00:00:00 2001 From: Kenji Urushima Date: Sun, 22 Jan 2017 19:03:08 +0900 Subject: [PATCH] 7.1.0 release --- ChangeLog.txt | 39 + api/files.html | 20 +- api/symbols/ASN1HEX.html | 82 +- api/symbols/KEYUTIL.html | 31 +- api/symbols/KJUR.crypto.DSA.html | 391 ++- api/symbols/KJUR.crypto.ECDSA.html | 286 +- api/symbols/RSAKey.html | 479 ++- api/symbols/X509.html | 77 +- api/symbols/src/asn1cades-1.0.js.html | 8 +- api/symbols/src/asn1cms-1.0.js.html | 14 +- api/symbols/src/asn1csr-1.0.js.html | 8 +- api/symbols/src/asn1hex-1.1.js.html | 49 +- api/symbols/src/asn1x509-1.0.js.html | 18 +- api/symbols/src/dsa-2.0.js.html | 581 ++-- api/symbols/src/ecdsa-modified-1.0.js.html | 1360 ++++---- api/symbols/src/keyutil-1.0.js.html | 3522 ++++++++++---------- api/symbols/src/rsapem-1.1.js.html | 328 +- api/symbols/src/x509-1.1.js.html | 1833 +++++----- asn1cades-1.0.js | 8 +- asn1cms-1.0.js | 14 +- asn1csr-1.0.js | 8 +- asn1hex-1.1.js | 47 +- asn1x509-1.0.js | 18 +- bower.json | 2 +- dsa-2.0.js | 579 ++-- ecdsa-modified-1.0.js | 180 +- ext/rsa-min.js | 2 +- ext/rsa.js | 25 +- ext/rsa2-min.js | 2 +- ext/rsa2.js | 1 + jsrsasign-latest-all-min.js | 50 +- keyutil-1.0.js | 292 +- min/asn1cades-1.0.min.js | 4 +- min/asn1cms-1.0.min.js | 4 +- min/asn1csr-1.0.min.js | 4 +- min/asn1hex-1.1.min.js | 4 +- min/asn1x509-1.0.min.js | 4 +- min/dsa-2.0.min.js | 4 +- min/ecdsa-modified-1.0.min.js | 4 +- min/keyutil-1.0.min.js | 4 +- min/pkcs5pkey-1.0.min.js | 4 +- min/rsapem-1.1.min.js | 4 +- min/x509-1.1.min.js | 4 +- npm/lib/jsrsasign.js | 50 +- npm/package.json | 2 +- rsapem-1.1.js | 288 +- sample-rsasign.html | 45 +- test/index.html | 3 + test/qunit-do-asn1hex-dump.html | 2 +- test/qunit-do-asn1hex.html | 23 +- test/qunit-do-crypto.html | 2 +- test/qunit-do-dsa.html | 52 + test/qunit-do-ecdsamod-unsupport.html | 99 + test/qunit-do-ecdsamod.html | 74 +- test/qunit-do-keyutil-dsa.html | 67 +- test/qunit-do-keyutil-ec.html | 135 + test/qunit-do-keyutil-eprv.html | 1 - test/qunit-do-keyutil-rsa.html | 198 ++ test/qunit-do-keyutil.html | 6 +- test/qunit-do-rsapem.html | 48 +- test/qunit-do-x509-ext.html | 16 +- test/qunit-do-x509.html | 6 +- tool_asn1dumper.html | 2 +- tool_httpscfg.html | 33 +- x509-1.1.js | 91 +- 65 files changed, 7230 insertions(+), 4411 deletions(-) create mode 100755 test/qunit-do-ecdsamod-unsupport.html create mode 100755 test/qunit-do-keyutil-ec.html create mode 100755 test/qunit-do-keyutil-rsa.html diff --git a/ChangeLog.txt b/ChangeLog.txt index 6a36dc0b..897d3587 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,45 @@ ChangeLog for jsrsasign +* Changes from 7.0.0 to 7.1.0 (2017-Jan-21) + - minor update for loading private/public key + - support added: PKCS#5 DSA/ECC hexacedimal string of private key + - keyutil 1.0.14 to 1.1.0 + - BUGFIX: KEYUTIL.getKey for PKCS#5 PEM ECC private key + was not set curve name properly and now it's fixed. + (issue #227). + - make KEYUTIL.getHexFromPEM deprecated + - move from KEYUTIL.getHexFromPEM to ASN1HEX.pemToHex + - pkcs5pkey 1.0.7 to 1.1.0 + - make PKCS5PKEY.getHexFromPEM deprecated + - move from getHexFromPEM to ASN1HEX.pemToHex + - rsapem 1.1.1 to 1.1.2 + - refactoring codes + - readPKCS5PubKeyHex added + - readPKCS8PubKeyHex added + - readCertPubKeyHex added + - ecdsa-modified 1.0.5 to 1.1.0 + - readCertPubKeyHex added + - dsa 2.0.1 to 2.1.0 + - setPrivateHex, setPublicHex added + - readPKCS5PrvKeyHex added + - readPKCS8PrvKeyHex added + - readPKCS8PubKeyHex added + - readCertPubKeyHex added + - asn1hex 1.1.8 to 1.1.9 + - ASN1HEX.pemToHex added + - move from {KEYUTIL,PKCS5PRV}.getHexFromPEM, + X509.pemToHex to ASN1HEX.pemToHex + - x509 1.1.10 to 1.1.11 + - now X509.pemToHex deprecated and is planed to + remove in jsrsasign 8.0.0. + - asn1cades 1.0.0 to 1.0.1 + - move to ASN1HEX.pemToHex + - asn1cms 1.0.2 to 1.0.3 + - move from KEYUTIL.getHexFromPEM to ASN1HEX.pemToHex + - asn1csr 1.0.2 to 1.0.3 + - move from KEYUTIL.getHexFromPEM to ASN1HEX.pemToHex + * Changes from 6.2.3 to 7.0.0 (2016-Dec-26) - LGPL license for openpgpjs was removed. - asn1hex 1.1.7 to 1.1.8 diff --git a/api/files.html b/api/files.html index e0b1a946..6706dfa8 100644 --- a/api/files.html +++ b/api/files.html @@ -462,7 +462,7 @@

asn1cades-1.0.js

Version:
-
1.0.0 (2014-May-28)
+
1.0.1 (2017-Jan-14)
@@ -481,7 +481,7 @@

asn1cms-1.0.js

Version:
-
1.0.2 (2014-Jun-07)
+
1.0.3 (2017-Jan-14)
@@ -500,7 +500,7 @@

asn1csr-1.0.js

Version:
-
1.0.2 (2016-Nov-26)
+
1.0.3 (2017-Jan-14)
@@ -519,7 +519,7 @@

asn1hex-1.1.js

Version:
-
asn1hex 1.1.8 (2016-Dec-03)
+
asn1hex 1.1.9 (2017-Jan-14)
@@ -576,7 +576,7 @@

asn1x509-1.0.js

Version:
-
1.0.19 (2016-Nov-26)
+
1.0.20 (2017-Jan-14)
@@ -633,7 +633,7 @@

dsa-2.0.js

Version:
-
dsa 2.0.0 (2016-Dec-24)
+
dsa 2.1.0 (2017-Jan-21)
@@ -652,7 +652,7 @@

ecdsa-modified-1.0.jsVersion: -
1.0.5 (2016-Aug-11)
+
1.1.0 (2017-Jan-21)
@@ -728,7 +728,7 @@

keyutil-1.0.js

Version:
-
keyutil 1.0.14 (2016-Oct-08)
+
keyutil 1.1.0 (2017-Jan-14)
@@ -785,7 +785,7 @@

rsapem-1.1.js

Version:
-
1.1
+
1.2.0 (2017-Jan-21)
@@ -823,7 +823,7 @@

x509-1.1.js

Version:
-
x509 1.1.10 (2016-Nov-19)
+
x509 1.1.11 (2017-Jan-21)
diff --git a/api/symbols/ASN1HEX.html b/api/symbols/ASN1HEX.html index 5b827eb1..4833147f 100644 --- a/api/symbols/ASN1HEX.html +++ b/api/symbols/ASN1HEX.html @@ -648,6 +648,17 @@

+ + <static>   + +
ASN1HEX.pemToHex(s, sHead) +
+
get hexacedimal string from PEM format data
+This static method gets a hexacedimal string of contents +from PEM format data.
+ + + @@ -796,7 +807,7 @@

INTEGER 01 INTEGER 02 // 5) ASN.1 DUMP FOR X.509 CERTIFICATE -ASN1HEX.dump(X509.pemToHex(certPEM)) +ASN1HEX.dump(ASN1HEX.pemToHex(certPEM)) ↓ SEQUENCE SEQUENCE @@ -1695,6 +1706,75 @@

+
+ + +
<static> + + {String} + ASN1HEX.pemToHex(s, sHead) + +
+
+ get hexacedimal string from PEM format data
+This static method gets a hexacedimal string of contents +from PEM format data. You can explicitly specify PEM header +by sHead argument. +Any space characters such as white space or new line +will be omitted.
+NOTE: Now KEYUTIL.getHexFromPEM and X509.pemToHex +have been deprecated since jsrsasign 7.0.1. +Please use this method instead. + + +
+ + + +
ASN1HEX.pemToHex("-----BEGIN PUBLIC KEY...") → "3082..."
+ASN1HEX.pemToHex("-----BEGIN CERTIFICATE...", "CERTIFICATE") → "3082..."
+ASN1HEX.pemToHex(" \r\n-----BEGIN DSA PRIVATE KEY...") → "3082..."
+ + + + +
+
Parameters:
+ +
+ {String} s + +
+
PEM formatted string
+ +
+ {String} sHead + +
+
PEM header string without BEGIN/END(OPTION)
+ +
+ + + +
+
Since:
+
jsrsasign 7.0.1 asn1hex 1.1.9
+
+ + + + +
+
Returns:
+ +
{String} hexadecimal string data of PEM contents
+ +
+ + + + diff --git a/api/symbols/KEYUTIL.html b/api/symbols/KEYUTIL.html index 1a33d053..4716a21f 100644 --- a/api/symbols/KEYUTIL.html +++ b/api/symbols/KEYUTIL.html @@ -568,7 +568,7 @@

KEYUTIL.getHexFromPEM(sPEM, sHead)
-
get hexacedimal string of PEM format
+
(DEPRECATED) get hexacedimal string of PEM format
@@ -635,7 +635,7 @@

KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex)
-
get RSAKey/ECDSA private key object from HEX plain PEM PKCS#8 private key
+
get RSAKey/DSA/ECDSA private key object from HEX plain PEM PKCS#8 private key
@@ -1293,7 +1293,7 @@

- get hexacedimal string of PEM format + (DEPRECATED) get hexacedimal string of PEM format
@@ -1319,6 +1319,13 @@

+
+
Deprecated:
+
+ from keyutil 1.1.0 jsrsasign 7.0.1. please move to ASN1HEX.pemToHex +
+
+
Since:
@@ -1741,7 +1748,7 @@
EXAMPLE
- get RSAKey/ECDSA private key object from HEX plain PEM PKCS#8 private key + get RSAKey/DSA/ECDSA private key object from HEX plain PEM PKCS#8 private key
@@ -1773,7 +1780,7 @@
EXAMPLE
Returns:
-
{Object} RSAKey or KJUR.crypto.ECDSA private key object
+
{Object} RSAKey or KJUR.crypto.{DSA,ECDSA} private key object
@@ -2851,6 +2858,13 @@
EXAMPLE
+
+
Deprecated:
+
+ since jsrsasign 7.1.0 keyutil 1.1.0 +
+
+
Since:
@@ -2911,6 +2925,13 @@
EXAMPLE
+
+
Deprecated:
+
+ since jsrsasign 7.1.0 keyutil 1.1.0 +
+
+
Since:
diff --git a/api/symbols/KJUR.crypto.DSA.html b/api/symbols/KJUR.crypto.DSA.html index d06fe550..0b4d61cf 100644 --- a/api/symbols/KJUR.crypto.DSA.html +++ b/api/symbols/KJUR.crypto.DSA.html @@ -471,7 +471,8 @@

KJUR.crypto.DSA()
class for DSA signing and verification -

CAUTION: Most of the case, you don't need to use this class.

+

+CAUTION: Most of the case, you don't need to use this class. @@ -504,12 +505,57 @@

+ +   + +
readCertPubKeyHex(h, nthPKI) +
+
read an ASN.1 hexadecimal string of X.509 DSA public key certificate
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#1/5 plain DSA private key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key
+ + +  
setPrivate(p, q, g, y, x)
-
set DSA private key by key parameters
+
set DSA private key by key parameters of BigInteger object
+ + + + +   + +
setPrivateHex(hP, hQ, hG, hY, hX) +
+
set DSA private key by key parameters of hexadecimal string
@@ -518,7 +564,16 @@

setPublic(p, q, g, y)
-
set DSA public key by key parameters
+
set DSA public key by key parameters of BigInteger object
+ + + + +   + +
setPublicHex(hP, hQ, hG, hY) +
+
set DSA public key by key parameters of hexadecimal string
@@ -562,7 +617,17 @@

class for DSA signing and verification -

CAUTION: Most of the case, you don't need to use this class. Please use KJUR.crypto.Signature class instead.

NOTE: Until jsrsasign 6.2.3, DSA class have used codes from openpgpjs library 1.0.0 licenced under LGPL licence. To avoid license issue dsa-2.0.js was re-written with my own codes in jsrsasign 7.0.0. Some random number generators used in dsa-2.0.js was newly defined in KJUR.crypto.Util class. Now all of LGPL codes are removed.

+

+CAUTION: Most of the case, you don't need to use this class. +Please use KJUR.crypto.Signature class instead. +

+

+NOTE: Until jsrsasign 6.2.3, DSA class have used codes from openpgpjs library 1.0.0 +licenced under LGPL licence. To avoid license issue dsa-2.0.js was re-written with +my own codes in jsrsasign 7.0.0. +Some random number generators used in dsa-2.0.js was newly defined +in KJUR.crypto.Util class. Now all of LGPL codes are removed. +

@@ -641,6 +706,180 @@

+
+ + +
+ + + readCertPubKeyHex(h, nthPKI) + +
+
+ read an ASN.1 hexadecimal string of X.509 DSA public key certificate
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of X.509 DSA public key certificate
+ +
+ {Integer} nthPKI + +
+
nth index of publicKeyInfo. (DEFAULT: 6 for X509v3)
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 dsa 2.1.0
+
+

+ + + + + + +
+ + +
+ + + readPKCS5PrvKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#1/5 plain DSA private key
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#1/5 DSA private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 dsa 2.1.0
+
+ + + + + + + +
+ + +
+ + + readPKCS8PrvKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#8 DSA private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 dsa 2.1.0
+
+ + + + + + + +
+ + +
+ + + readPKCS8PubKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#8 DSA private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 dsa 2.1.0
+
+ + + + + + +
@@ -651,7 +890,7 @@

- set DSA private key by key parameters + set DSA private key by key parameters of BigInteger object
@@ -666,25 +905,25 @@

{BigInteger} p -
prime P
+
prime P parameter
{BigInteger} q
-
sub prime Q
+
sub prime Q parameter
{BigInteger} g
-
base G
+
base G parameter
{BigInteger} y
-
public key Y
+
public key Y or null
{BigInteger} x @@ -707,6 +946,72 @@

+
+ + +
+ + + setPrivateHex(hP, hQ, hG, hY, hX) + +
+
+ set DSA private key by key parameters of hexadecimal string + + +
+ + + + +
+
Parameters:
+ +
+ {String} hP + +
+
prime P parameter
+ +
+ {String} hQ + +
+
sub prime Q parameter
+ +
+ {String} hG + +
+
base G parameter
+ +
+ {String} hY + +
+
public key Y or null
+ +
+ {String} hX + +
+
private key X
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 dsa 2.1.0
+
+ + + + + + +
@@ -717,7 +1022,7 @@

- set DSA public key by key parameters + set DSA public key by key parameters of BigInteger object
@@ -732,19 +1037,19 @@

{BigInteger} p

-
prime P
+
prime P parameter
{BigInteger} q
-
sub prime Q
+
sub prime Q parameter
{BigInteger} g
-
base G
+
base G parameter
{BigInteger} y @@ -767,6 +1072,66 @@

+
+ + +
+ + + setPublicHex(hP, hQ, hG, hY) + +
+
+ set DSA public key by key parameters of hexadecimal string + + +
+ + + + +
+
Parameters:
+ +
+ {String} hP + +
+
prime P parameter
+ +
+ {String} hQ + +
+
sub prime Q parameter
+ +
+ {String} hG + +
+
base G parameter
+ +
+ {String} hY + +
+
public key Y
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 dsa 2.1.0
+
+ + + + + + +
diff --git a/api/symbols/KJUR.crypto.ECDSA.html b/api/symbols/KJUR.crypto.ECDSA.html index 2d95e26d..dbb01452 100644 --- a/api/symbols/KJUR.crypto.ECDSA.html +++ b/api/symbols/KJUR.crypto.ECDSA.html @@ -533,6 +533,18 @@

+ + <static>   + +
KJUR.crypto.ECDSA.getName(s) +
+
static method to get normalized EC curve name from curve name or hexadecimal OID value +This static method returns normalized EC curve name +which is supported in jsrsasign +from curve name or hexadecimal OID value.
+ + + <static>   @@ -578,6 +590,42 @@

+ +   + +
readCertPubKeyHex(h, nthPKI) +
+
read an ASN.1 hexadecimal string of X.509 ECC public key certificate
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#1/5 plain ECC private key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#8 plain ECC private key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#8 ECC public key
+ + + <static>   @@ -854,6 +902,66 @@

+
+ + +
<static> + + {String} + KJUR.crypto.ECDSA.getName(s) + +
+
+ static method to get normalized EC curve name from curve name or hexadecimal OID value +This static method returns normalized EC curve name +which is supported in jsrsasign +from curve name or hexadecimal OID value. +When curve is not supported in jsrsasign, this method returns null. +Normalized name will be "secp*" in jsrsasign. + + +
+ + + +
KJUR.crypto.ECDSA.getName("2b8104000a") → "secp256k1"
+KJUR.crypto.ECDSA.getName("NIST P-256") → "secp256r1"
+KJUR.crypto.ECDSA.getName("P-521") → undefined // not supported
+ + + + +
+
Parameters:
+ +
+ {String} s + +
+
curve name (ex. P-256) or hexadecimal OID value (ex. 2a86...)
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 ecdsa-modified 1.1.0
+
+ + + + +
+
Returns:
+ +
{String} normalized EC curve name (ex. secp256r1)
+ +
+ + + +
@@ -881,7 +989,7 @@

Since:
-
ecdsa-modified 1.0.5
+
ecdsa-modified 1.0.5 jsrsasign 5.0.14
@@ -924,7 +1032,7 @@

Since:
-
ecdsa-modified 1.0.5
+
ecdsa-modified 1.0.5 jsrsasign 5.0.14
@@ -1107,6 +1215,180 @@

+
+ + +
+ + + readCertPubKeyHex(h, nthPKI) + +
+
+ read an ASN.1 hexadecimal string of X.509 ECC public key certificate
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of X.509 ECC public key certificate
+ +
+ {Integer} nthPKI + +
+
nth index of publicKeyInfo. (DEFAULT: 6 for X509v3)
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 ecdsa-modified 1.1.0
+
+ + + + + + + +
+ + +
+ + + readPKCS5PrvKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#1/5 plain ECC private key
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#1/5 ECC private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 ecdsa-modified 1.1.0
+
+ + + + + + + +
+ + +
+ + + readPKCS8PrvKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#8 plain ECC private key
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#8 ECC private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 ecdsa-modified 1.1.0
+
+ + + + + + + +
+ + +
+ + + readPKCS8PubKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#8 ECC public key
+ + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#8 ECC public key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 ecdsa-modified 1.1.0
+
+ + + + + + +
diff --git a/api/symbols/RSAKey.html b/api/symbols/RSAKey.html index dd1ce57d..0f078530 100644 --- a/api/symbols/RSAKey.html +++ b/api/symbols/RSAKey.html @@ -494,12 +494,84 @@

+ + <static>   + +
RSAKey.getHexValueArrayOfChildrenFromHex(sPEMPrivateKey) +
+
static method to get array of hex field values from hexadecimal PKCS#5 RSA private key.
+ + + + + <static>   + +
RSAKey.getPosArrayOfChildrenFromHex(sPEMPrivateKey) +
+
static method to get array of field positions from hexadecimal PKCS#5 RSA private key.
+ + + + + <static>   + +
RSAKey.pemToBase64(sPEMPrivateKey) +
+
static method to extract Base64 string from PKCS#5 PEM RSA private key.
+ + + + +   + +
readCertPubKeyHex(h, nthPKI) +
+
read an ASN.1 hexadecimal string of X.509 RSA public key certificate
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#1/5 plain RSA private key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#5 RSA public key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#8 plain RSA private key
+ + + + +   + + +
read an ASN.1 hexadecimal string of PKCS#8 RSA public key
+ + +   -
read RSA private key from a ASN.1 hexadecimal string
+
(DEPRECATED) read RSA private key from a ASN.1 hexadecimal string
@@ -508,7 +580,7 @@

-
read PKCS#1 private key from a string
+
read PKCS#1 private key from a string
@@ -632,6 +704,396 @@

Method Detail + +
<static> + + {Array} + RSAKey.getHexValueArrayOfChildrenFromHex(sPEMPrivateKey) + +
+
+ static method to get array of hex field values from hexadecimal PKCS#5 RSA private key.
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + +
RSAKey.getHexValueArrayOfChildrenFromHex("3082...") → ["00", "3b42...", ...]
+ + + + +
+
Parameters:
+ +
+ {String} sPEMPrivateKey + +
+
PEM PKCS#1/5 s private key string
+ +
+ + + + + +
+
Returns:
+ +
{Array} array of field hex value
+ +
+ + + + +
+ + +
<static> + + {Array} + RSAKey.getPosArrayOfChildrenFromHex(sPEMPrivateKey) + +
+
+ static method to get array of field positions from hexadecimal PKCS#5 RSA private key.
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + +
RSAKey.getPosArrayOfChildrenFromHex("3082...") → [8, 32, ...]
+ + + + +
+
Parameters:
+ +
+ {String} sPEMPrivateKey + +
+
PEM PKCS#1/5 s private key string
+ +
+ + + + + +
+
Returns:
+ +
{Array} array of field positions
+ +
+ + + + +
+ + +
<static> + + {String} + RSAKey.pemToBase64(sPEMPrivateKey) + +
+
+ static method to extract Base64 string from PKCS#5 PEM RSA private key.
+removing PEM header, PEM footer and space characters including +new lines from PEM formatted RSA private key string. + +
+ Defined in: rsapem-1.1.js. + + +
+ + + +
RSAKey.pemToBase64("----BEGIN PRIVATE KEY-...") → "MIICW..."
+ + + + +
+
Parameters:
+ +
+ {String} sPEMPrivateKey + +
+
PEM PKCS#1/5 s private key string
+ +
+ + + + + +
+
Returns:
+ +
{String} Base64 string of private key
+ +
+ + + + +
+ + +
+ + + readCertPubKeyHex(h, nthPKI) + +
+
+ read an ASN.1 hexadecimal string of X.509 RSA public key certificate
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of X.509 RSA public key certificate
+ +
+ {Integer} nthPKI + +
+
nth index of publicKeyInfo. (DEFAULT: 6 for X509v3)
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 rsapem 1.2.0
+
+ + + + + + + +
+ + +
+ + + readPKCS5PrvKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#1/5 plain RSA private key
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#1/5 plain RSA private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 rsapem 1.2.0
+
+ + + + + + +
+
See:
+ +
former method
+ +
+ + +
+ + +
+ + + readPKCS5PubKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#5 RSA public key
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#5 public key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 rsapem 1.2.0
+
+ + + + + + + +
+ + +
+ + + readPKCS8PrvKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#8 plain RSA private key
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#8 plain RSA private key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 rsapem 1.2.0
+
+ + + + + + + +
+ + +
+ + + readPKCS8PubKeyHex(h) + +
+
+ read an ASN.1 hexadecimal string of PKCS#8 RSA public key
+ +
+ Defined in: rsapem-1.1.js. + + +
+ + + + +
+
Parameters:
+ +
+ {String} h + +
+
hexadecimal string of PKCS#8 public key
+ +
+ + + +
+
Since:
+
jsrsasign 7.1.0 rsapem 1.2.0
+
+ + + + + + + +
+
@@ -640,7 +1102,7 @@

- read RSA private key from a ASN.1 hexadecimal string + (DEPRECATED) read RSA private key from a ASN.1 hexadecimal string

Defined in: rsapem-1.1.js. @@ -663,10 +1125,17 @@

+
+
Deprecated:
+
+ since jsrsasign 7.1.0 rsapem 1.2.0, please use RSAKey.readPKCS5PrvKeyHex instead. +
+
+
Since:
-
1.1.1
+
rsapem 1.1.1
@@ -685,7 +1154,7 @@

- read PKCS#1 private key from a string + read PKCS#1 private key from a string

Defined in: rsapem-1.1.js. diff --git a/api/symbols/X509.html b/api/symbols/X509.html index dcc19344..4d9cd727 100644 --- a/api/symbols/X509.html +++ b/api/symbols/X509.html @@ -733,12 +733,21 @@

+ + <static>   + + +
get RSA/DSA/ECDSA public key object from X.509 certificate hexadecimal string
+ + + <static>  
X509.getPublicKeyFromCertPEM(sCertPEM)
-
get RSAKey/ECDSA public key object from PEM certificate string +
get RSA/DSA/ECDSA public key object from PEM certificate string NOTE: DSA is also supported since x509 1.1.2.
@@ -917,7 +926,8 @@

X509.pemToHex(sCertPEM)
-
get a hexa decimal string from PEM certificate string
+
get a hexa decimal string from PEM certificate string +CAUTION: now X509.pemToHex deprecated and is planed to remove in jsrsasign 8.0.0.
@@ -994,7 +1004,7 @@

  • reading PEM certificate - X509#readCertPEM
  • get all certificate information - X509#getInfo
  • get Base64 from PEM certificate - X509.pemToBase64
  • -
  • get hexadecimal string from PEM certificate - X509.pemToHex
  • +
  • get hexadecimal string from PEM certificate - X509.pemToHex (DEPRECATED)
  • @@ -2090,6 +2100,55 @@

    +
    + + +
    <static> + + + X509.getPublicKeyFromCertHex(h) + +
    +
    + get RSA/DSA/ECDSA public key object from X.509 certificate hexadecimal string
    + + +
    + + + + +
    +
    Parameters:
    + +
    + {String} h + +
    +
    hexadecimal string of X.509 certificate for RSA/ECDSA/DSA public key
    + +
    + + + +
    +
    Since:
    +
    jsrasign 7.1.0 x509 1.1.11
    +
    + + + + +
    +
    Returns:
    + +
    returns RSAKey/KJUR.crypto.{ECDSA,DSA} object of public key
    + +
    + + + +
    @@ -2100,7 +2159,7 @@

    - get RSAKey/ECDSA public key object from PEM certificate string + get RSA/DSA/ECDSA public key object from PEM certificate string NOTE: DSA is also supported since x509 1.1.2. @@ -2637,7 +2696,7 @@

    -
    hCert = X509.pemToHex(certGithubPEM);
    +					
    hCert = ASN1HEX.pemToHex(certGithubPEM);
     a = X509.getV3ExtInfoListOfCertHex(hCert);
     // Then a will be an array of like following:
     [{posTLV: 1952, oid: "2.5.29.35", critical: false, posV: 1968},
    @@ -2973,6 +3032,7 @@ 

    get a hexa decimal string from PEM certificate string +CAUTION: now X509.pemToHex deprecated and is planed to remove in jsrsasign 8.0.0.
    @@ -2996,6 +3056,13 @@

    +
    +
    Deprecated:
    +
    + from x509 1.1.11 jsrsasign 7.0.1. please move to ASN1HEX.pemToHex +
    +
    + diff --git a/api/symbols/src/asn1cades-1.0.js.html b/api/symbols/src/asn1cades-1.0.js.html index 549fe727..0021bc0f 100644 --- a/api/symbols/src/asn1cades-1.0.js.html +++ b/api/symbols/src/asn1cades-1.0.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 /*! asn1cades-1.0.0.js (c) 2013-2014 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! asn1cades-1.0.1.js (c) 2014-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * asn1cades.js - ASN.1 DER encoder classes for RFC 5126 CAdES long term signature
       5  *
    -  6  * Copyright (c) 2014 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2014-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license
    @@ -23,7 +23,7 @@
      16  * @fileOverview
      17  * @name asn1cades-1.0.js
      18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version 1.0.0 (2014-May-28)
    + 19  * @version 1.0.1 (2017-Jan-14)
      20  * @since jsrsasign 4.7.0
      21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      22  */
    @@ -520,7 +520,7 @@
     513     this.setByCertPEM = function(certPEM) {
     514         if (certPEM.indexOf("-----BEGIN ") == -1)
     515             throw "certPEM not to seem PEM format";
    -516         var hex = X509.pemToHex(certPEM);
    +516         var hex = ASN1HEX.pemToHex(certPEM);
     517         var hash = KJUR.crypto.Util.hashHex(hex, this.alg);
     518         this.dOtherHash = 
     519             new nD.OtherHashAlgAndValue({alg: this.alg, hash: hash});
    diff --git a/api/symbols/src/asn1cms-1.0.js.html b/api/symbols/src/asn1cms-1.0.js.html
    index 356165d3..fb213321 100644
    --- a/api/symbols/src/asn1cms-1.0.js.html
    +++ b/api/symbols/src/asn1cms-1.0.js.html
    @@ -5,12 +5,12 @@
     	.STRN {color: #393;}
     	.REGX {color: #339;}
     	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
    -	
      1 /*! asn1cms-1.0.2.js (c) 2013-2014 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! asn1cms-1.0.3.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * asn1cms.js - ASN.1 DER encoder classes for Cryptographic Message Syntax(CMS)
       5  *
    -  6  * Copyright (c) 2014 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license
    @@ -23,7 +23,7 @@
      16  * @fileOverview
      17  * @name asn1cms-1.0.js
      18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version 1.0.2 (2014-Jun-07)
    + 19  * @version 1.0.3 (2017-Jan-14)
      20  * @since jsrsasign 4.2.4
      21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      22  */
    @@ -271,7 +271,7 @@
     264     this.setCerts = function(listPEM) {
     265         var list = [];
     266         for (var i = 0; i < listPEM.length; i++) {
    -267             var hex = KEYUTIL.getHexFromPEM(listPEM[i]);
    +267             var hex = ASN1HEX.pemToHex(listPEM[i]);
     268             var certHashHex = nY.Util.hashHex(hex, 'sha1');
     269             var dCertHash = new nA.DEROctetString({hex: certHashHex});
     270             dCertHash.getEncodedHex();
    @@ -341,7 +341,7 @@
     334     this.setCerts = function(listPEM, hashAlg) {
     335         var list = [];
     336         for (var i = 0; i < listPEM.length; i++) {
    -337             var hex = KEYUTIL.getHexFromPEM(listPEM[i]);
    +337             var hex = ASN1HEX.pemToHex(listPEM[i]);
     338 
     339             var a = [];
     340             if (hashAlg != "sha256")
    @@ -412,7 +412,7 @@
     405      * @since asn1cms 1.0.1
     406      */
     407     this.setByCertPEM = function(certPEM) {
    -408         var certHex = KEYUTIL.getHexFromPEM(certPEM);
    +408         var certHex = ASN1HEX.pemToHex(certPEM);
     409         var x = new X509();
     410         x.hex = certHex;
     411         var issuerTLVHex = x.getIssuerHex();
    @@ -844,7 +844,7 @@
     837     this.signerInfoList = [new nC.SignerInfo()];
     838 
     839     this.addCertificatesByPEM = function(certPEM) {
    -840         var hex = KEYUTIL.getHexFromPEM(certPEM);
    +840         var hex = ASN1HEX.pemToHex(certPEM);
     841         var o = new nA.ASN1Object();
     842         o.hTLV = hex;
     843         this.certificateList.push(o);
    diff --git a/api/symbols/src/asn1csr-1.0.js.html b/api/symbols/src/asn1csr-1.0.js.html
    index 1a5c6d8f..5e14769c 100644
    --- a/api/symbols/src/asn1csr-1.0.js.html
    +++ b/api/symbols/src/asn1csr-1.0.js.html
    @@ -5,12 +5,12 @@
     	.STRN {color: #393;}
     	.REGX {color: #339;}
     	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
    -	
      1 /*! asn1csr-1.0.2.js (c) 2015-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! asn1csr-1.0.3.js (c) 2015-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * asn1csr.js - ASN.1 DER encoder classes for PKCS#10 CSR
       5  *
    -  6  * Copyright (c) 2015-2016 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2015-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license
    @@ -23,7 +23,7 @@
      16  * @fileOverview
      17  * @name asn1csr-1.0.js
      18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version 1.0.2 (2016-Nov-26)
    + 19  * @version 1.0.3 (2017-Jan-14)
      20  * @since jsrsasign 4.9.0
      21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      22  */
    @@ -420,7 +420,7 @@
     413     if (sPEM.indexOf("-----BEGIN CERTIFICATE REQUEST") == -1)
     414 	throw "argument is not PEM file";
     415 
    -416     var hex = KEYUTIL.getHexFromPEM(sPEM, "CERTIFICATE REQUEST");
    +416     var hex = ASN1HEX.pemToHex(sPEM, "CERTIFICATE REQUEST");
     417 
     418     result.subject.hex = ASN1HEX.getDecendantHexTLVByNthList(hex, 0, [0, 1]);
     419     result.subject.name = X509.hex2dn(result.subject.hex);
    diff --git a/api/symbols/src/asn1hex-1.1.js.html b/api/symbols/src/asn1hex-1.1.js.html
    index 5ba81dbe..382bc684 100644
    --- a/api/symbols/src/asn1hex-1.1.js.html
    +++ b/api/symbols/src/asn1hex-1.1.js.html
    @@ -5,12 +5,12 @@
     	.STRN {color: #393;}
     	.REGX {color: #339;}
     	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
    -	
      1 /*! asn1hex-1.1.8.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! asn1hex-1.1.9.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * asn1hex.js - Hexadecimal represented ASN.1 string library
       5  *
    -  6  * Copyright (c) 2010-2016 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2010-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license/
    @@ -23,7 +23,7 @@
      16  * @fileOverview
      17  * @name asn1hex-1.1.js
      18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version asn1hex 1.1.8 (2016-Dec-03)
    + 19  * @version asn1hex 1.1.9 (2017-Jan-14)
      20  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      21  */
      22 
    @@ -468,7 +468,7 @@
     461  *   INTEGER 01
     462  *   INTEGER 02
     463  * // 5) ASN.1 DUMP FOR X.509 CERTIFICATE
    -464  * ASN1HEX.dump(X509.pemToHex(certPEM))
    +464  * ASN1HEX.dump(ASN1HEX.pemToHex(certPEM))
     465  * ↓
     466  * SEQUENCE
     467  *   SEQUENCE
    @@ -655,4 +655,43 @@
     648 
     649     return false;
     650 };
    -651 
    \ No newline at end of file +651 +652
    /** +653 * get hexacedimal string from PEM format data<br/> +654 * @name pemToHex +655 * @memberOf ASN1HEX +656 * @function +657 * @param {String} s PEM formatted string +658 * @param {String} sHead PEM header string without BEGIN/END(OPTION) +659 * @return {String} hexadecimal string data of PEM contents +660 * @since jsrsasign 7.0.1 asn1hex 1.1.9 +661 * @description +662 * This static method gets a hexacedimal string of contents +663 * from PEM format data. You can explicitly specify PEM header +664 * by sHead argument. +665 * Any space characters such as white space or new line +666 * will be omitted.<br/> +667 * NOTE: Now {@link KEYUTIL.getHexFromPEM} and {@link X509.pemToHex} +668 * have been deprecated since jsrsasign 7.0.1. +669 * Please use this method instead. +670 * @example +671 * ASN1HEX.pemToHex("-----BEGIN PUBLIC KEY...") → "3082..." +672 * ASN1HEX.pemToHex("-----BEGIN CERTIFICATE...", "CERTIFICATE") → "3082..." +673 * ASN1HEX.pemToHex(" \r\n-----BEGIN DSA PRIVATE KEY...") → "3082..." +674 */ +675 ASN1HEX.pemToHex = function(s, sHead) { +676 if (s.indexOf("-----BEGIN ") == -1) +677 throw "can't find PEM header: " + sHead; +678 +679 if (sHead !== undefined) { +680 s = s.replace("-----BEGIN " + sHead + "-----", ""); +681 s = s.replace("-----END " + sHead + "-----", ""); +682 } else { +683 s = s.replace(/-----BEGIN [^-]+-----/, ''); +684 s = s.replace(/-----END [^-]+-----/, ''); +685 } +686 var sB64 = s.replace(/\s+/g, ''); +687 var dataHex = b64tohex(sB64); +688 return dataHex; +689 }; +690
    \ No newline at end of file diff --git a/api/symbols/src/asn1x509-1.0.js.html b/api/symbols/src/asn1x509-1.0.js.html index 3cdf70b9..af80cc2f 100644 --- a/api/symbols/src/asn1x509-1.0.js.html +++ b/api/symbols/src/asn1x509-1.0.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 /*! asn1x509-1.0.19.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! asn1x509-1.0.20.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * asn1x509.js - ASN.1 DER encoder classes for X.509 certificate
       5  *
    -  6  * Copyright (c) 2013-2016 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license
    @@ -23,7 +23,7 @@
      16  * @fileOverview
      17  * @name asn1x509-1.0.js
      18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version 1.0.19 (2016-Nov-26)
    + 19  * @version 1.0.20 (2017-Jan-14)
      20  * @since jsrsasign 2.1
      21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      22  */
    @@ -1481,12 +1481,12 @@
     1474 
     1475         if (params.certissuer !== undefined) {
     1476             var x = new X509();
    -1477             x.hex = X509.pemToHex(params.certissuer);
    +1477             x.hex = ASN1HEX.pemToHex(params.certissuer);
     1478             this.hTLV = x.getIssuerHex();
     1479         }
     1480         if (params.certsubject !== undefined) {
     1481             var x = new X509();
    -1482             x.hex = X509.pemToHex(params.certsubject);
    +1482             x.hex = ASN1HEX.pemToHex(params.certsubject);
     1483             this.hTLV = x.getSubjectHex();
     1484         }
     1485     }
    @@ -1854,10 +1854,10 @@
     1847             var rsaB64 = s.replace(/\s+/g, '');
     1848             var rsaWA = CryptoJS.enc.Base64.parse(rsaB64);
     1849             var rsaP8Hex = CryptoJS.enc.Hex.stringify(rsaWA);
    -1850             var a = _rsapem_getHexValueArrayOfChildrenFromHex(rsaP8Hex);
    +1850             var a = RSAKey.getHexValueArrayOfChildrenFromHex(rsaP8Hex);
     1851             var hBitStrVal = a[1];
     1852             var rsaHex = hBitStrVal.substr(2);
    -1853             var a3 = _rsapem_getHexValueArrayOfChildrenFromHex(rsaHex);
    +1853             var a3 = RSAKey.getHexValueArrayOfChildrenFromHex(rsaHex);
     1854             var rsaKey = new RSAKey();
     1855             rsaKey.setPublic(a3[0], a3[1]);
     1856             this.setRSAKey(rsaKey);
    @@ -2129,7 +2129,7 @@
     2122             }
     2123 
     2124 	    if (certStr.indexOf("-----BEGIN ") != -1) {
    -2125 		certHex = X509.pemToHex(certStr);
    +2125 		certHex = ASN1HEX.pemToHex(certStr);
     2126 	    }
     2127 
     2128 	    if (certHex == null) throw "certissuer param not cert";
    @@ -2149,7 +2149,7 @@
     2142 		certHex == certStr;
     2143             }
     2144 	    if (certStr.indexOf("-----BEGIN ") != -1) {
    -2145 		certHex = X509.pemToHex(certStr);
    +2145 		certHex = ASN1HEX.pemToHex(certStr);
     2146 	    }
     2147 	    if (certHex == null) throw "certsubj param not cert";
     2148 	    var x = new X509();
    diff --git a/api/symbols/src/dsa-2.0.js.html b/api/symbols/src/dsa-2.0.js.html
    index b449b771..bdfe5a5e 100644
    --- a/api/symbols/src/dsa-2.0.js.html
    +++ b/api/symbols/src/dsa-2.0.js.html
    @@ -5,210 +5,377 @@
     	.STRN {color: #393;}
     	.REGX {color: #339;}
     	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
    -	
      1 /*! dsa-2.0.0.js (c) 2016 Kenji Urushimma | kjur.github.com/jsrsasign/license
    -  2  */
    -  3 /*
    -  4  * dsa.js - new DSA class
    -  5  *
    -  6  * Copyright (c) 2016 Kenji Urushima (kenji.urushima@gmail.com)
    -  7  *
    -  8  * This software is licensed under the terms of the MIT License.
    -  9  * http://kjur.github.com/jsrsasign/license
    - 10  *
    - 11  * The above copyright and license notice shall be 
    - 12  * included in all copies or substantial portions of the Software.
    - 13  */
    - 14 
    - 15 /**
    - 16  * @fileOverview
    - 17  * @name dsa-2.0.js
    - 18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version dsa 2.0.0 (2016-Dec-24)
    - 20  * @since jsrsasign 7.0.0
    - 21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
    - 22  */
    - 23 
    - 24 if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
    - 25 if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
    - 26 
    - 27 /**
    - 28  * class for DSA signing and verification
    - 29  * @name KJUR.crypto.DSA
    - 30  * @class class for DSA signing and verifcation
    - 31  * @since jsrsasign 7.0.0 dsa 2.0.0
    - 32  * @description
    - 33  * <p>
    - 34  * CAUTION: Most of the case, you don't need to use this class.
    - 35  * Please use {@link KJUR.crypto.Signature} class instead.
    - 36  * </p>
    - 37  * <p>
    - 38  * NOTE: Until jsrsasign 6.2.3, DSA class have used codes from openpgpjs library 1.0.0
    - 39  * licenced under LGPL licence. To avoid license issue dsa-2.0.js was re-written with
    - 40  * my own codes in jsrsasign 7.0.0. 
    - 41  * Some random number generators used in dsa-2.0.js was newly defined
    - 42  * in KJUR.crypto.Util class. Now all of LGPL codes are removed.
    - 43  * </p>
    - 44  */
    - 45 KJUR.crypto.DSA = function() {
    - 46     this.p = null;
    - 47     this.q = null;
    - 48     this.g = null;
    - 49     this.y = null;
    - 50     this.x = null;
    - 51     this.type = "DSA";
    - 52 
    - 53     //===========================
    - 54     // PUBLIC METHODS
    - 55     //===========================
    - 56 
    - 57     /**
    - 58      * set DSA private key by key parameters
    - 59      * @name setPrivate
    - 60      * @memberOf KJUR.crypto.DSA#
    - 61      * @function
    - 62      * @param {BigInteger} p prime P
    - 63      * @param {BigInteger} q sub prime Q
    - 64      * @param {BigInteger} g base G
    - 65      * @param {BigInteger} y public key Y
    - 66      * @param {BigInteger} x private key X
    - 67      * @since jsrsasign 7.0.0 dsa 2.0.0
    - 68      */
    - 69     this.setPrivate = function(p, q, g, y, x) {
    - 70 	this.isPrivate = true;
    - 71 	this.p = p;
    - 72 	this.q = q;
    - 73 	this.g = g;
    - 74 	this.y = y;
    - 75 	this.x = x;
    - 76     };
    - 77 
    - 78     /**
    - 79      * set DSA public key by key parameters
    - 80      * @name setPublic
    - 81      * @memberOf KJUR.crypto.DSA#
    - 82      * @function
    - 83      * @param {BigInteger} p prime P
    - 84      * @param {BigInteger} q sub prime Q
    - 85      * @param {BigInteger} g base G
    - 86      * @param {BigInteger} y public key Y
    - 87      * @since jsrsasign 7.0.0 dsa 2.0.0
    - 88      */
    - 89     this.setPublic = function(p, q, g, y) {
    - 90 	this.isPublic = true;
    - 91 	this.p = p;
    - 92 	this.q = q;
    - 93 	this.g = g;
    - 94 	this.y = y;
    - 95 	this.x = null;
    - 96     };
    - 97 
    - 98     /**
    - 99      * sign to hashed message by this DSA private key object
    -100      * @name signWithMessageHash
    -101      * @memberOf KJUR.crypto.DSA#
    -102      * @function
    -103      * @param {String} sHashHex hexadecimal string of hashed message
    -104      * @return {String} hexadecimal string of ASN.1 encoded DSA signature value
    -105      * @since jsrsasign 7.0.0 dsa 2.0.0
    -106      */
    -107     this.signWithMessageHash = function(sHashHex) {
    -108 	var p = this.p; // parameter p
    -109 	var q = this.q; // parameter q
    -110 	var g = this.g; // parameter g
    -111 	var y = this.y; // public key (p q g y)
    -112 	var x = this.x; // private key
    -113 
    -114 	// NIST FIPS 186-4 4.5 DSA Per-Message Secret Number (p18)
    -115 	// 1. get random k where 0 < k < q
    -116 	var k = KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE),
    -117 							     q.subtract(BigInteger.ONE));
    -118 
    -119 	// NIST FIPS 186-4 4.6 DSA Signature Generation (p19)
    -120 	// 2. get z where the left most min(N, outlen) bits of Hash(M)
    -121 	var hZ = sHashHex.substr(0, q.bitLength() / 4);
    -122 	var z = new BigInteger(hZ, 16);
    -123 
    -124 	// 3. get r where (g^k mod p) mod q, r != 0
    -125 	var r = (g.modPow(k,p)).mod(q); 
    -126 
    -127 	// 4. get s where k^-1 (z + xr) mod q, s != 0
    -128 	var s = (k.modInverse(q).multiply(z.add(x.multiply(r)))).mod(q);
    -129 
    -130 	// 5. signature (r, s)
    -131 	var result = KJUR.asn1.ASN1Util.jsonToASN1HEX({
    -132 	    "seq": [{"int": {"bigint": r}}, {"int": {"bigint": s}}] 
    -133 	});
    -134 	return result;
    -135     };
    -136 
    -137     /**
    -138      * verify signature by this DSA public key object
    -139      * @name verifyWithMessageHash
    -140      * @memberOf KJUR.crypto.DSA#
    -141      * @function
    -142      * @param {String} sHashHex hexadecimal string of hashed message
    -143      * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value
    -144      * @return {Boolean} true if the signature is valid otherwise false.
    -145      * @since jsrsasign 7.0.0 dsa 2.0.0
    -146      */
    -147     this.verifyWithMessageHash = function(sHashHex, hSigVal) {
    -148 	var p = this.p; // parameter p
    -149 	var q = this.q; // parameter q
    -150 	var g = this.g; // parameter g
    -151 	var y = this.y; // public key (p q g y)
    -152 
    -153 	// 1. parse ASN.1 signature (r, s)
    -154 	var rs = this.parseASN1Signature(hSigVal);
    -155         var r = rs[0];
    -156         var s = rs[1];
    -157 
    -158 	// NIST FIPS 186-4 4.6 DSA Signature Generation (p19)
    -159 	// 2. get z where the left most min(N, outlen) bits of Hash(M)
    -160 	var hZ = sHashHex.substr(0, q.bitLength() / 4);
    -161 	var z = new BigInteger(hZ, 16);
    -162 
    -163 	// NIST FIPS 186-4 4.7 DSA Signature Validation (p19)
    -164 	// 3.1. 0 < r < q
    -165 	if (BigInteger.ZERO.compareTo(r) > 0 || r.compareTo(q) > 0)
    -166 	    throw "invalid DSA signature";
    -167 
    -168 	// 3.2. 0 < s < q
    -169 	if (BigInteger.ZERO.compareTo(s) > 0 || s.compareTo(q) > 0)
    -170 	    throw "invalid DSA signature";
    -171 
    -172 	// 4. get w where w = s^-1 mod q
    -173 	var w = s.modInverse(q);
    -174 
    -175 	// 5. get u1 where u1 = z w mod q
    -176 	var u1 = z.multiply(w).mod(q);
    -177 
    -178 	// 6. get u2 where u2 = r w mod q
    -179 	var u2 = r.multiply(w).mod(q);
    -180 
    -181 	// 7. get v where v = ((g^u1 y^u2) mod p) mod q
    -182 	var v = g.modPow(u1,p).multiply(y.modPow(u2,p)).mod(p).mod(q);
    -183 
    -184 	// 8. signature is valid when v == r
    -185 	return v.compareTo(r) == 0;
    -186     };
    -187 
    -188     /**
    -189      * parse hexadecimal ASN.1 DSA signature value
    -190      * @name parseASN1Signature
    -191      * @memberOf KJUR.crypto.DSA#
    -192      * @function
    -193      * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value
    -194      * @return {Array} array [r, s] of DSA signature value. Both r and s are BigInteger.
    -195      * @since jsrsasign 7.0.0 dsa 2.0.0
    -196      */
    -197     this.parseASN1Signature = function(hSigVal) {
    -198 	try {
    -199 	    var r = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [0], "02"), 16);
    -200 	    var s = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [1], "02"), 16);
    -201 	    return [r, s];
    -202 	} catch (ex) {
    -203 	    throw "malformed ASN.1 DSA signature";
    -204 	}
    -205     }
    -206 }
    -207 
    \ No newline at end of file +
      1 /*! dsa-2.1.0.js (c) 2016-2017 Kenji Urushimma | kjur.github.com/jsrsasign/license
    +  2  */
    +  3 /*
    +  4  * dsa.js - new DSA class
    +  5  *
    +  6  * Copyright (c) 2016-2017 Kenji Urushima (kenji.urushima@gmail.com)
    +  7  *
    +  8  * This software is licensed under the terms of the MIT License.
    +  9  * http://kjur.github.com/jsrsasign/license
    + 10  *
    + 11  * The above copyright and license notice shall be 
    + 12  * included in all copies or substantial portions of the Software.
    + 13  */
    + 14 
    + 15 /**
    + 16  * @fileOverview
    + 17  * @name dsa-2.0.js
    + 18  * @author Kenji Urushima kenji.urushima@gmail.com
    + 19  * @version dsa 2.1.0 (2017-Jan-21)
    + 20  * @since jsrsasign 7.0.0
    + 21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
    + 22  */
    + 23 
    + 24 if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
    + 25 if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
    + 26 
    + 27 /**
    + 28  * class for DSA signing and verification
    + 29  * @name KJUR.crypto.DSA
    + 30  * @class class for DSA signing and verifcation
    + 31  * @since jsrsasign 7.0.0 dsa 2.0.0
    + 32  * @description
    + 33  * <p>
    + 34  * CAUTION: Most of the case, you don't need to use this class.
    + 35  * Please use {@link KJUR.crypto.Signature} class instead.
    + 36  * </p>
    + 37  * <p>
    + 38  * NOTE: Until jsrsasign 6.2.3, DSA class have used codes from openpgpjs library 1.0.0
    + 39  * licenced under LGPL licence. To avoid license issue dsa-2.0.js was re-written with
    + 40  * my own codes in jsrsasign 7.0.0. 
    + 41  * Some random number generators used in dsa-2.0.js was newly defined
    + 42  * in KJUR.crypto.Util class. Now all of LGPL codes are removed.
    + 43  * </p>
    + 44  */
    + 45 KJUR.crypto.DSA = function() {
    + 46     this.p = null;
    + 47     this.q = null;
    + 48     this.g = null;
    + 49     this.y = null;
    + 50     this.x = null;
    + 51     this.type = "DSA";
    + 52     this.isPrivate = false;
    + 53     this.isPublic = false;
    + 54 
    + 55     //===========================
    + 56     // PUBLIC METHODS
    + 57     //===========================
    + 58 
    + 59     /**
    + 60      * set DSA private key by key parameters of BigInteger object
    + 61      * @name setPrivate
    + 62      * @memberOf KJUR.crypto.DSA#
    + 63      * @function
    + 64      * @param {BigInteger} p prime P parameter
    + 65      * @param {BigInteger} q sub prime Q parameter
    + 66      * @param {BigInteger} g base G parameter
    + 67      * @param {BigInteger} y public key Y or null
    + 68      * @param {BigInteger} x private key X
    + 69      * @since jsrsasign 7.0.0 dsa 2.0.0
    + 70      */
    + 71     this.setPrivate = function(p, q, g, y, x) {
    + 72 	this.isPrivate = true;
    + 73 	this.p = p;
    + 74 	this.q = q;
    + 75 	this.g = g;
    + 76 	this.y = y;
    + 77 	this.x = x;
    + 78     };
    + 79 
    + 80     /**
    + 81      * set DSA private key by key parameters of hexadecimal string
    + 82      * @name setPrivateHex
    + 83      * @memberOf KJUR.crypto.DSA#
    + 84      * @function
    + 85      * @param {String} hP prime P parameter
    + 86      * @param {String} hQ sub prime Q parameter
    + 87      * @param {String} hG base G parameter
    + 88      * @param {String} hY public key Y or null
    + 89      * @param {String} hX private key X
    + 90      * @since jsrsasign 7.1.0 dsa 2.1.0
    + 91      */
    + 92     this.setPrivateHex = function(hP, hQ, hG, hY, hX) {
    + 93 	var biP, biQ, biG, biY, biX;
    + 94         biP = new BigInteger(hP, 16);
    + 95         biQ = new BigInteger(hQ, 16);
    + 96         biG = new BigInteger(hG, 16);
    + 97 	if (typeof hY === "string" && hY.length > 1) {
    + 98             biY = new BigInteger(hY, 16);
    + 99 	} else {
    +100 	    biY = null;
    +101 	}
    +102         biX = new BigInteger(hX, 16);
    +103         this.setPrivate(biP, biQ, biG, biY, biX);
    +104     };
    +105 
    +106     /**
    +107      * set DSA public key by key parameters of BigInteger object
    +108      * @name setPublic
    +109      * @memberOf KJUR.crypto.DSA#
    +110      * @function
    +111      * @param {BigInteger} p prime P parameter
    +112      * @param {BigInteger} q sub prime Q parameter
    +113      * @param {BigInteger} g base G parameter
    +114      * @param {BigInteger} y public key Y
    +115      * @since jsrsasign 7.0.0 dsa 2.0.0
    +116      */
    +117     this.setPublic = function(p, q, g, y) {
    +118 	this.isPublic = true;
    +119 	this.p = p;
    +120 	this.q = q;
    +121 	this.g = g;
    +122 	this.y = y;
    +123 	this.x = null;
    +124     };
    +125 
    +126     /**
    +127      * set DSA public key by key parameters of hexadecimal string
    +128      * @name setPublicHex
    +129      * @memberOf KJUR.crypto.DSA#
    +130      * @function
    +131      * @param {String} hP prime P parameter
    +132      * @param {String} hQ sub prime Q parameter
    +133      * @param {String} hG base G parameter
    +134      * @param {String} hY public key Y
    +135      * @since jsrsasign 7.1.0 dsa 2.1.0
    +136      */
    +137     this.setPublicHex = function(hP, hQ, hG, hY) {
    +138 	var biP, biQ, biG, biY;
    +139         biP = new BigInteger(hP, 16);
    +140         biQ = new BigInteger(hQ, 16);
    +141         biG = new BigInteger(hG, 16);
    +142         biY = new BigInteger(hY, 16);
    +143         this.setPublic(biP, biQ, biG, biY);
    +144     };
    +145 
    +146     /**
    +147      * sign to hashed message by this DSA private key object
    +148      * @name signWithMessageHash
    +149      * @memberOf KJUR.crypto.DSA#
    +150      * @function
    +151      * @param {String} sHashHex hexadecimal string of hashed message
    +152      * @return {String} hexadecimal string of ASN.1 encoded DSA signature value
    +153      * @since jsrsasign 7.0.0 dsa 2.0.0
    +154      */
    +155     this.signWithMessageHash = function(sHashHex) {
    +156 	var p = this.p; // parameter p
    +157 	var q = this.q; // parameter q
    +158 	var g = this.g; // parameter g
    +159 	var y = this.y; // public key (p q g y)
    +160 	var x = this.x; // private key
    +161 
    +162 	// NIST FIPS 186-4 4.5 DSA Per-Message Secret Number (p18)
    +163 	// 1. get random k where 0 < k < q
    +164 	var k = KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE),
    +165 							     q.subtract(BigInteger.ONE));
    +166 
    +167 	// NIST FIPS 186-4 4.6 DSA Signature Generation (p19)
    +168 	// 2. get z where the left most min(N, outlen) bits of Hash(M)
    +169 	var hZ = sHashHex.substr(0, q.bitLength() / 4);
    +170 	var z = new BigInteger(hZ, 16);
    +171 
    +172 	// 3. get r where (g^k mod p) mod q, r != 0
    +173 	var r = (g.modPow(k,p)).mod(q); 
    +174 
    +175 	// 4. get s where k^-1 (z + xr) mod q, s != 0
    +176 	var s = (k.modInverse(q).multiply(z.add(x.multiply(r)))).mod(q);
    +177 
    +178 	// 5. signature (r, s)
    +179 	var result = KJUR.asn1.ASN1Util.jsonToASN1HEX({
    +180 	    "seq": [{"int": {"bigint": r}}, {"int": {"bigint": s}}] 
    +181 	});
    +182 	return result;
    +183     };
    +184 
    +185     /**
    +186      * verify signature by this DSA public key object
    +187      * @name verifyWithMessageHash
    +188      * @memberOf KJUR.crypto.DSA#
    +189      * @function
    +190      * @param {String} sHashHex hexadecimal string of hashed message
    +191      * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value
    +192      * @return {Boolean} true if the signature is valid otherwise false.
    +193      * @since jsrsasign 7.0.0 dsa 2.0.0
    +194      */
    +195     this.verifyWithMessageHash = function(sHashHex, hSigVal) {
    +196 	var p = this.p; // parameter p
    +197 	var q = this.q; // parameter q
    +198 	var g = this.g; // parameter g
    +199 	var y = this.y; // public key (p q g y)
    +200 
    +201 	// 1. parse ASN.1 signature (r, s)
    +202 	var rs = this.parseASN1Signature(hSigVal);
    +203         var r = rs[0];
    +204         var s = rs[1];
    +205 
    +206 	// NIST FIPS 186-4 4.6 DSA Signature Generation (p19)
    +207 	// 2. get z where the left most min(N, outlen) bits of Hash(M)
    +208 	var hZ = sHashHex.substr(0, q.bitLength() / 4);
    +209 	var z = new BigInteger(hZ, 16);
    +210 
    +211 	// NIST FIPS 186-4 4.7 DSA Signature Validation (p19)
    +212 	// 3.1. 0 < r < q
    +213 	if (BigInteger.ZERO.compareTo(r) > 0 || r.compareTo(q) > 0)
    +214 	    throw "invalid DSA signature";
    +215 
    +216 	// 3.2. 0 < s < q
    +217 	if (BigInteger.ZERO.compareTo(s) > 0 || s.compareTo(q) > 0)
    +218 	    throw "invalid DSA signature";
    +219 
    +220 	// 4. get w where w = s^-1 mod q
    +221 	var w = s.modInverse(q);
    +222 
    +223 	// 5. get u1 where u1 = z w mod q
    +224 	var u1 = z.multiply(w).mod(q);
    +225 
    +226 	// 6. get u2 where u2 = r w mod q
    +227 	var u2 = r.multiply(w).mod(q);
    +228 
    +229 	// 7. get v where v = ((g^u1 y^u2) mod p) mod q
    +230 	var v = g.modPow(u1,p).multiply(y.modPow(u2,p)).mod(p).mod(q);
    +231 
    +232 	// 8. signature is valid when v == r
    +233 	return v.compareTo(r) == 0;
    +234     };
    +235 
    +236     /**
    +237      * parse hexadecimal ASN.1 DSA signature value
    +238      * @name parseASN1Signature
    +239      * @memberOf KJUR.crypto.DSA#
    +240      * @function
    +241      * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value
    +242      * @return {Array} array [r, s] of DSA signature value. Both r and s are BigInteger.
    +243      * @since jsrsasign 7.0.0 dsa 2.0.0
    +244      */
    +245     this.parseASN1Signature = function(hSigVal) {
    +246 	try {
    +247 	    var r = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [0], "02"), 16);
    +248 	    var s = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [1], "02"), 16);
    +249 	    return [r, s];
    +250 	} catch (ex) {
    +251 	    throw "malformed ASN.1 DSA signature";
    +252 	}
    +253     }
    +254 
    +255     /**
    +256      * read an ASN.1 hexadecimal string of PKCS#1/5 plain DSA private key<br/>
    +257      * @name readPKCS5PrvKeyHex
    +258      * @memberOf KJUR.crypto.DSA#
    +259      * @function
    +260      * @param {String} h hexadecimal string of PKCS#1/5 DSA private key
    +261      * @since jsrsasign 7.1.0 dsa 2.1.0
    +262      */
    +263     this.readPKCS5PrvKeyHex = function(h) {
    +264 	var hP, hQ, hG, hY, hX;
    +265 	var _ASN1HEX = ASN1HEX;
    +266 	var _getVbyList = _ASN1HEX.getVbyList;
    +267 
    +268 	if (_ASN1HEX.isASN1HEX(h) === false)
    +269 	    throw "not ASN.1 hex string";
    +270 
    +271 	try {
    +272 	    hP = _getVbyList(h, 0, [1], "02");
    +273 	    hQ = _getVbyList(h, 0, [2], "02");
    +274 	    hG = _getVbyList(h, 0, [3], "02");
    +275 	    hY = _getVbyList(h, 0, [4], "02");
    +276 	    hX = _getVbyList(h, 0, [5], "02");
    +277 	} catch(ex) {
    +278 	    console.log("EXCEPTION:" + ex);
    +279 	    throw "malformed PKCS#1/5 plain DSA private key";
    +280 	}
    +281 
    +282 	this.setPrivateHex(hP, hQ, hG, hY, hX);
    +283     };
    +284 
    +285     /**
    +286      * read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key<br/>
    +287      * @name readPKCS8PrvKeyHex
    +288      * @memberOf KJUR.crypto.DSA#
    +289      * @function
    +290      * @param {String} h hexadecimal string of PKCS#8 DSA private key
    +291      * @since jsrsasign 7.1.0 dsa 2.1.0
    +292      */
    +293     this.readPKCS8PrvKeyHex = function(h) {
    +294 	var hP, hQ, hG, hX;
    +295 	var _ASN1HEX = ASN1HEX;
    +296 	var _getVbyList = _ASN1HEX.getVbyList;
    +297 
    +298 	if (_ASN1HEX.isASN1HEX(h) === false)
    +299 	    throw "not ASN.1 hex string";
    +300 
    +301 	try {
    +302 	    hP = _getVbyList(h, 0, [1, 1, 0], "02");
    +303 	    hQ = _getVbyList(h, 0, [1, 1, 1], "02");
    +304 	    hG = _getVbyList(h, 0, [1, 1, 2], "02");
    +305 	    hX = _getVbyList(h, 0, [2, 0], "02");
    +306 	} catch(ex) {
    +307 	    console.log("EXCEPTION:" + ex);
    +308 	    throw "malformed PKCS#8 plain DSA private key";
    +309 	}
    +310 
    +311 	this.setPrivateHex(hP, hQ, hG, null, hX);
    +312     };
    +313 
    +314     /**
    +315      * read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key<br/>
    +316      * @name readPKCS8PubKeyHex
    +317      * @memberOf KJUR.crypto.DSA#
    +318      * @function
    +319      * @param {String} h hexadecimal string of PKCS#8 DSA private key
    +320      * @since jsrsasign 7.1.0 dsa 2.1.0
    +321      */
    +322     this.readPKCS8PubKeyHex = function(h) {
    +323 	var hP, hQ, hG, hY;
    +324 	var _ASN1HEX = ASN1HEX;
    +325 	var _getVbyList = _ASN1HEX.getVbyList;
    +326 
    +327 	if (_ASN1HEX.isASN1HEX(h) === false)
    +328 	    throw "not ASN.1 hex string";
    +329 
    +330 	try {
    +331 	    hP = _getVbyList(h, 0, [0, 1, 0], "02");
    +332 	    hQ = _getVbyList(h, 0, [0, 1, 1], "02");
    +333 	    hG = _getVbyList(h, 0, [0, 1, 2], "02");
    +334 	    hY = _getVbyList(h, 0, [1, 0], "02");
    +335 	} catch(ex) {
    +336 	    console.log("EXCEPTION:" + ex);
    +337 	    throw "malformed PKCS#8 DSA public key";
    +338 	}
    +339 
    +340 	this.setPublicHex(hP, hQ, hG, hY);
    +341     };
    +342 
    +343     /**
    +344      * read an ASN.1 hexadecimal string of X.509 DSA public key certificate<br/>
    +345      * @name readCertPubKeyHex
    +346      * @memberOf KJUR.crypto.DSA#
    +347      * @function
    +348      * @param {String} h hexadecimal string of X.509 DSA public key certificate
    +349      * @param {Integer} nthPKI nth index of publicKeyInfo. (DEFAULT: 6 for X509v3)
    +350      * @since jsrsasign 7.1.0 dsa 2.1.0
    +351      */
    +352     this.readCertPubKeyHex = function(h, nthPKI) {
    +353 	if (nthPKI !== 5) nthPKI = 6;
    +354 	var hP, hQ, hG, hY;
    +355 	var _ASN1HEX = ASN1HEX;
    +356 	var _getVbyList = _ASN1HEX.getVbyList;
    +357 
    +358 	if (_ASN1HEX.isASN1HEX(h) === false)
    +359 	    throw "not ASN.1 hex string";
    +360 
    +361 	try {
    +362 	    hP = _getVbyList(h, 0, [0, nthPKI, 0, 1, 0], "02");
    +363 	    hQ = _getVbyList(h, 0, [0, nthPKI, 0, 1, 1], "02");
    +364 	    hG = _getVbyList(h, 0, [0, nthPKI, 0, 1, 2], "02");
    +365 	    hY = _getVbyList(h, 0, [0, nthPKI, 1, 0], "02");
    +366 	} catch(ex) {
    +367 	    console.log("EXCEPTION:" + ex);
    +368 	    throw "malformed X.509 certificate DSA public key";
    +369 	}
    +370 
    +371 	this.setPublicHex(hP, hQ, hG, hY);
    +372     };
    +373 }
    +374 
    \ No newline at end of file diff --git a/api/symbols/src/ecdsa-modified-1.0.js.html b/api/symbols/src/ecdsa-modified-1.0.js.html index c410782a..a9d2060f 100644 --- a/api/symbols/src/ecdsa-modified-1.0.js.html +++ b/api/symbols/src/ecdsa-modified-1.0.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 /*! ecdsa-modified-1.0.5.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE
    +	
      1 /*! ecdsa-modified-1.1.0.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE
       2  */
       3 /*
       4  * ecdsa-modified.js - modified Bitcoin.ECDSA class
       5  * 
    -  6  * Copyright (c) 2013-2016 Stefan Thomas (github.com/justmoon)
    +  6  * Copyright (c) 2013-2017 Stefan Thomas (github.com/justmoon)
       7  *                         Kenji Urushima (kenji.urushima@gmail.com)
       8  * LICENSE
       9  *   https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE
    @@ -20,7 +20,7 @@
      13  * @fileOverview
      14  * @name ecdsa-modified-1.0.js
      15  * @author Stefan Thomas (github.com/justmoon) and Kenji Urushima (kenji.urushima@gmail.com)
    - 16  * @version 1.0.5 (2016-Aug-11)
    + 16  * @version 1.1.0 (2017-Jan-21)
      17  * @since jsrsasign 4.0
      18  * @license <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE">MIT License</a>
      19  */
    @@ -59,605 +59,775 @@
      52     var P_OVER_FOUR = null;
      53 
      54     this.type = "EC";
    - 55 
    - 56     function implShamirsTrick(P, k, Q, l) {
    - 57 	var m = Math.max(k.bitLength(), l.bitLength());
    - 58 	var Z = P.add2D(Q);
    - 59 	var R = P.curve.getInfinity();
    - 60 
    - 61 	for (var i = m - 1; i >= 0; --i) {
    - 62 	    R = R.twice2D();
    - 63 
    - 64 	    R.z = BigInteger.ONE;
    + 55     this.isPrivate = false;
    + 56     this.isPublic = false;
    + 57 
    + 58     function implShamirsTrick(P, k, Q, l) {
    + 59 	var m = Math.max(k.bitLength(), l.bitLength());
    + 60 	var Z = P.add2D(Q);
    + 61 	var R = P.curve.getInfinity();
    + 62 
    + 63 	for (var i = m - 1; i >= 0; --i) {
    + 64 	    R = R.twice2D();
      65 
    - 66 	    if (k.testBit(i)) {
    - 67 		if (l.testBit(i)) {
    - 68 		    R = R.add2D(Z);
    - 69 		} else {
    - 70 		    R = R.add2D(P);
    - 71 		}
    - 72 	    } else {
    - 73 		if (l.testBit(i)) {
    - 74 		    R = R.add2D(Q);
    - 75 		}
    - 76 	    }
    - 77 	}
    - 78 	
    - 79 	return R;
    - 80     };
    - 81 
    - 82     //===========================
    - 83     // PUBLIC METHODS
    + 66 	    R.z = BigInteger.ONE;
    + 67 
    + 68 	    if (k.testBit(i)) {
    + 69 		if (l.testBit(i)) {
    + 70 		    R = R.add2D(Z);
    + 71 		} else {
    + 72 		    R = R.add2D(P);
    + 73 		}
    + 74 	    } else {
    + 75 		if (l.testBit(i)) {
    + 76 		    R = R.add2D(Q);
    + 77 		}
    + 78 	    }
    + 79 	}
    + 80 	
    + 81 	return R;
    + 82     };
    + 83 
      84     //===========================
    - 85     this.getBigRandom = function (limit) {
    - 86 	return new BigInteger(limit.bitLength(), rng)
    - 87 	.mod(limit.subtract(BigInteger.ONE))
    - 88 	.add(BigInteger.ONE)
    - 89 	;
    - 90     };
    - 91 
    - 92     this.setNamedCurve = function(curveName) {
    - 93 	this.ecparams = KJUR.crypto.ECParameterDB.getByName(curveName);
    - 94 	this.prvKeyHex = null;
    - 95 	this.pubKeyHex = null;
    - 96 	this.curveName = curveName;
    - 97     };
    - 98 
    - 99     this.setPrivateKeyHex = function(prvKeyHex) {
    -100         this.isPrivate = true;
    -101 	this.prvKeyHex = prvKeyHex;
    -102     };
    -103 
    -104     this.setPublicKeyHex = function(pubKeyHex) {
    -105         this.isPublic = true;
    -106 	this.pubKeyHex = pubKeyHex;
    -107     };
    -108 
    -109     /**
    -110      * get X and Y hexadecimal string value of public key
    -111      * @name getPublicKeyXYHex
    -112      * @memberOf KJUR.crypto.ECDSA
    -113      * @function
    -114      * @return {Array} associative array of x and y value of public key
    -115      * @since ecdsa-modified 1.0.5
    -116      * @example
    -117      * ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1', 'pub': pubHex});
    -118      * ec.getPublicKeyXYHex() → { x: '01bacf...', y: 'c3bc22...' }
    -119      */
    -120     this.getPublicKeyXYHex = function() {
    -121 	var h = this.pubKeyHex;
    -122 	if (h.substr(0, 2) !== "04")
    -123 	    throw "this method supports uncompressed format(04) only";
    -124 
    -125 	var charlen = this.ecparams.keylen / 4;
    -126 	if (h.length !== 2 + charlen * 2)
    -127 	    throw "malformed public key hex length";
    -128 
    -129 	var result = {};
    -130 	result.x = h.substr(2, charlen);
    -131 	result.y = h.substr(2 + charlen);
    -132 	return result;
    -133     };
    -134 
    -135     /**
    -136      * get NIST curve short name such as "P-256" or "P-384"
    -137      * @name getShortNISTPCurveName
    -138      * @memberOf KJUR.crypto.ECDSA
    -139      * @function
    -140      * @return {String} short NIST P curve name such as "P-256" or "P-384" if it's NIST P curve otherwise null;
    -141      * @since ecdsa-modified 1.0.5
    -142      * @example
    -143      * ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1', 'pub': pubHex});
    -144      * ec.getShortPCurveName() → "P-256";
    -145      */
    -146     this.getShortNISTPCurveName = function() {
    -147 	var s = this.curveName;
    -148 	if (s === "secp256r1" || s === "NIST P-256" ||
    -149 	    s === "P-256" || s === "prime256v1")
    -150 	    return "P-256";
    -151 	if (s === "secp384r1" || s === "NIST P-384" || s === "P-384")
    -152 	    return "P-384";
    -153 	return null;
    -154     };
    -155 
    -156     /**
    -157      * generate a EC key pair
    -158      * @name generateKeyPairHex
    -159      * @memberOf KJUR.crypto.ECDSA
    -160      * @function
    -161      * @return {Array} associative array of hexadecimal string of private and public key
    -162      * @since ecdsa-modified 1.0.1
    -163      * @example
    -164      * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    -165      * var keypair = ec.generateKeyPairHex();
    -166      * var pubhex = keypair.ecpubhex; // hexadecimal string of EC public key
    -167      * var prvhex = keypair.ecprvhex; // hexadecimal string of EC private key (=d)
    -168      */
    -169     this.generateKeyPairHex = function() {
    -170 	var biN = this.ecparams['n'];
    -171 	var biPrv = this.getBigRandom(biN);
    -172 	var epPub = this.ecparams['G'].multiply(biPrv);
    -173 	var biX = epPub.getX().toBigInteger();
    -174 	var biY = epPub.getY().toBigInteger();
    -175 
    -176 	var charlen = this.ecparams['keylen'] / 4;
    -177 	var hPrv = ("0000000000" + biPrv.toString(16)).slice(- charlen);
    -178 	var hX   = ("0000000000" + biX.toString(16)).slice(- charlen);
    -179 	var hY   = ("0000000000" + biY.toString(16)).slice(- charlen);
    -180 	var hPub = "04" + hX + hY;
    -181 
    -182 	this.setPrivateKeyHex(hPrv);
    -183 	this.setPublicKeyHex(hPub);
    -184 	return {'ecprvhex': hPrv, 'ecpubhex': hPub};
    -185     };
    -186 
    -187     this.signWithMessageHash = function(hashHex) {
    -188 	return this.signHex(hashHex, this.prvKeyHex);
    -189     };
    -190 
    -191     /**
    -192      * signing to message hash
    -193      * @name signHex
    -194      * @memberOf KJUR.crypto.ECDSA
    -195      * @function
    -196      * @param {String} hashHex hexadecimal string of hash value of signing message
    -197      * @param {String} privHex hexadecimal string of EC private key
    -198      * @return {String} hexadecimal string of ECDSA signature
    -199      * @since ecdsa-modified 1.0.1
    -200      * @example
    -201      * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    -202      * var sigValue = ec.signHex(hash, prvKey);
    -203      */
    -204     this.signHex = function (hashHex, privHex) {
    -205 	var d = new BigInteger(privHex, 16);
    -206 	var n = this.ecparams['n'];
    -207 	var e = new BigInteger(hashHex, 16);
    -208 
    -209 	do {
    -210 	    var k = this.getBigRandom(n);
    -211 	    var G = this.ecparams['G'];
    -212 	    var Q = G.multiply(k);
    -213 	    var r = Q.getX().toBigInteger().mod(n);
    -214 	} while (r.compareTo(BigInteger.ZERO) <= 0);
    -215 
    -216 	var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
    + 85     // PUBLIC METHODS
    + 86     //===========================
    + 87     this.getBigRandom = function (limit) {
    + 88 	return new BigInteger(limit.bitLength(), rng)
    + 89 	.mod(limit.subtract(BigInteger.ONE))
    + 90 	.add(BigInteger.ONE)
    + 91 	;
    + 92     };
    + 93 
    + 94     this.setNamedCurve = function(curveName) {
    + 95 	this.ecparams = KJUR.crypto.ECParameterDB.getByName(curveName);
    + 96 	this.prvKeyHex = null;
    + 97 	this.pubKeyHex = null;
    + 98 	this.curveName = curveName;
    + 99     };
    +100 
    +101     this.setPrivateKeyHex = function(prvKeyHex) {
    +102         this.isPrivate = true;
    +103 	this.prvKeyHex = prvKeyHex;
    +104     };
    +105 
    +106     this.setPublicKeyHex = function(pubKeyHex) {
    +107         this.isPublic = true;
    +108 	this.pubKeyHex = pubKeyHex;
    +109     };
    +110 
    +111     /**
    +112      * get X and Y hexadecimal string value of public key
    +113      * @name getPublicKeyXYHex
    +114      * @memberOf KJUR.crypto.ECDSA
    +115      * @function
    +116      * @return {Array} associative array of x and y value of public key
    +117      * @since ecdsa-modified 1.0.5 jsrsasign 5.0.14
    +118      * @example
    +119      * ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1', 'pub': pubHex});
    +120      * ec.getPublicKeyXYHex() → { x: '01bacf...', y: 'c3bc22...' }
    +121      */
    +122     this.getPublicKeyXYHex = function() {
    +123 	var h = this.pubKeyHex;
    +124 	if (h.substr(0, 2) !== "04")
    +125 	    throw "this method supports uncompressed format(04) only";
    +126 
    +127 	var charlen = this.ecparams.keylen / 4;
    +128 	if (h.length !== 2 + charlen * 2)
    +129 	    throw "malformed public key hex length";
    +130 
    +131 	var result = {};
    +132 	result.x = h.substr(2, charlen);
    +133 	result.y = h.substr(2 + charlen);
    +134 	return result;
    +135     };
    +136 
    +137     /**
    +138      * get NIST curve short name such as "P-256" or "P-384"
    +139      * @name getShortNISTPCurveName
    +140      * @memberOf KJUR.crypto.ECDSA
    +141      * @function
    +142      * @return {String} short NIST P curve name such as "P-256" or "P-384" if it's NIST P curve otherwise null;
    +143      * @since ecdsa-modified 1.0.5 jsrsasign 5.0.14
    +144      * @example
    +145      * ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1', 'pub': pubHex});
    +146      * ec.getShortPCurveName() → "P-256";
    +147      */
    +148     this.getShortNISTPCurveName = function() {
    +149 	var s = this.curveName;
    +150 	if (s === "secp256r1" || s === "NIST P-256" ||
    +151 	    s === "P-256" || s === "prime256v1")
    +152 	    return "P-256";
    +153 	if (s === "secp384r1" || s === "NIST P-384" || s === "P-384")
    +154 	    return "P-384";
    +155 	return null;
    +156     };
    +157 
    +158     /**
    +159      * generate a EC key pair
    +160      * @name generateKeyPairHex
    +161      * @memberOf KJUR.crypto.ECDSA
    +162      * @function
    +163      * @return {Array} associative array of hexadecimal string of private and public key
    +164      * @since ecdsa-modified 1.0.1
    +165      * @example
    +166      * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    +167      * var keypair = ec.generateKeyPairHex();
    +168      * var pubhex = keypair.ecpubhex; // hexadecimal string of EC public key
    +169      * var prvhex = keypair.ecprvhex; // hexadecimal string of EC private key (=d)
    +170      */
    +171     this.generateKeyPairHex = function() {
    +172 	var biN = this.ecparams['n'];
    +173 	var biPrv = this.getBigRandom(biN);
    +174 	var epPub = this.ecparams['G'].multiply(biPrv);
    +175 	var biX = epPub.getX().toBigInteger();
    +176 	var biY = epPub.getY().toBigInteger();
    +177 
    +178 	var charlen = this.ecparams['keylen'] / 4;
    +179 	var hPrv = ("0000000000" + biPrv.toString(16)).slice(- charlen);
    +180 	var hX   = ("0000000000" + biX.toString(16)).slice(- charlen);
    +181 	var hY   = ("0000000000" + biY.toString(16)).slice(- charlen);
    +182 	var hPub = "04" + hX + hY;
    +183 
    +184 	this.setPrivateKeyHex(hPrv);
    +185 	this.setPublicKeyHex(hPub);
    +186 	return {'ecprvhex': hPrv, 'ecpubhex': hPub};
    +187     };
    +188 
    +189     this.signWithMessageHash = function(hashHex) {
    +190 	return this.signHex(hashHex, this.prvKeyHex);
    +191     };
    +192 
    +193     /**
    +194      * signing to message hash
    +195      * @name signHex
    +196      * @memberOf KJUR.crypto.ECDSA
    +197      * @function
    +198      * @param {String} hashHex hexadecimal string of hash value of signing message
    +199      * @param {String} privHex hexadecimal string of EC private key
    +200      * @return {String} hexadecimal string of ECDSA signature
    +201      * @since ecdsa-modified 1.0.1
    +202      * @example
    +203      * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    +204      * var sigValue = ec.signHex(hash, prvKey);
    +205      */
    +206     this.signHex = function (hashHex, privHex) {
    +207 	var d = new BigInteger(privHex, 16);
    +208 	var n = this.ecparams['n'];
    +209 	var e = new BigInteger(hashHex, 16);
    +210 
    +211 	do {
    +212 	    var k = this.getBigRandom(n);
    +213 	    var G = this.ecparams['G'];
    +214 	    var Q = G.multiply(k);
    +215 	    var r = Q.getX().toBigInteger().mod(n);
    +216 	} while (r.compareTo(BigInteger.ZERO) <= 0);
     217 
    -218 	return KJUR.crypto.ECDSA.biRSSigToASN1Sig(r, s);
    -219     };
    -220 
    -221     this.sign = function (hash, priv) {
    -222 	var d = priv;
    -223 	var n = this.ecparams['n'];
    -224 	var e = BigInteger.fromByteArrayUnsigned(hash);
    -225 
    -226 	do {
    -227 	    var k = this.getBigRandom(n);
    -228 	    var G = this.ecparams['G'];
    -229 	    var Q = G.multiply(k);
    -230 	    var r = Q.getX().toBigInteger().mod(n);
    -231 	} while (r.compareTo(BigInteger.ZERO) <= 0);
    -232 
    -233 	var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
    -234 	return this.serializeSig(r, s);
    -235     };
    -236 
    -237     this.verifyWithMessageHash = function(hashHex, sigHex) {
    -238 	return this.verifyHex(hashHex, sigHex, this.pubKeyHex);
    -239     };
    -240 
    -241     /**
    -242      * verifying signature with message hash and public key
    -243      * @name verifyHex
    -244      * @memberOf KJUR.crypto.ECDSA
    -245      * @function
    -246      * @param {String} hashHex hexadecimal string of hash value of signing message
    -247      * @param {String} sigHex hexadecimal string of signature value
    -248      * @param {String} pubkeyHex hexadecimal string of public key
    -249      * @return {Boolean} true if the signature is valid, otherwise false
    -250      * @since ecdsa-modified 1.0.1
    -251      * @example
    -252      * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    -253      * var result = ec.verifyHex(msgHashHex, sigHex, pubkeyHex);
    -254      */
    -255     this.verifyHex = function(hashHex, sigHex, pubkeyHex) {
    -256 	var r,s;
    -257 
    -258 	var obj = KJUR.crypto.ECDSA.parseSigHex(sigHex);
    -259 	r = obj.r;
    -260 	s = obj.s;
    -261 
    -262 	var Q;
    -263 	Q = ECPointFp.decodeFromHex(this.ecparams['curve'], pubkeyHex);
    -264 	var e = new BigInteger(hashHex, 16);
    -265 
    -266 	return this.verifyRaw(e, r, s, Q);
    -267     };
    -268 
    -269     this.verify = function (hash, sig, pubkey) {
    -270 	var r,s;
    -271 	if (Bitcoin.Util.isArray(sig)) {
    -272 	    var obj = this.parseSig(sig);
    -273 	    r = obj.r;
    -274 	    s = obj.s;
    -275 	} else if ("object" === typeof sig && sig.r && sig.s) {
    -276 	    r = sig.r;
    -277 	    s = sig.s;
    -278 	} else {
    -279 	    throw "Invalid value for signature";
    -280 	}
    -281 
    -282 	var Q;
    -283 	if (pubkey instanceof ECPointFp) {
    -284 	    Q = pubkey;
    -285 	} else if (Bitcoin.Util.isArray(pubkey)) {
    -286 	    Q = ECPointFp.decodeFrom(this.ecparams['curve'], pubkey);
    -287 	} else {
    -288 	    throw "Invalid format for pubkey value, must be byte array or ECPointFp";
    -289 	}
    -290 	var e = BigInteger.fromByteArrayUnsigned(hash);
    -291 
    -292 	return this.verifyRaw(e, r, s, Q);
    -293     };
    -294 
    -295     this.verifyRaw = function (e, r, s, Q) {
    -296 	var n = this.ecparams['n'];
    -297 	var G = this.ecparams['G'];
    -298 
    -299 	if (r.compareTo(BigInteger.ONE) < 0 ||
    -300 	    r.compareTo(n) >= 0)
    -301 	    return false;
    -302 
    -303 	if (s.compareTo(BigInteger.ONE) < 0 ||
    -304 	    s.compareTo(n) >= 0)
    -305 	    return false;
    -306 
    -307 	var c = s.modInverse(n);
    +218 	var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
    +219 
    +220 	return KJUR.crypto.ECDSA.biRSSigToASN1Sig(r, s);
    +221     };
    +222 
    +223     this.sign = function (hash, priv) {
    +224 	var d = priv;
    +225 	var n = this.ecparams['n'];
    +226 	var e = BigInteger.fromByteArrayUnsigned(hash);
    +227 
    +228 	do {
    +229 	    var k = this.getBigRandom(n);
    +230 	    var G = this.ecparams['G'];
    +231 	    var Q = G.multiply(k);
    +232 	    var r = Q.getX().toBigInteger().mod(n);
    +233 	} while (r.compareTo(BigInteger.ZERO) <= 0);
    +234 
    +235 	var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
    +236 	return this.serializeSig(r, s);
    +237     };
    +238 
    +239     this.verifyWithMessageHash = function(hashHex, sigHex) {
    +240 	return this.verifyHex(hashHex, sigHex, this.pubKeyHex);
    +241     };
    +242 
    +243     /**
    +244      * verifying signature with message hash and public key
    +245      * @name verifyHex
    +246      * @memberOf KJUR.crypto.ECDSA
    +247      * @function
    +248      * @param {String} hashHex hexadecimal string of hash value of signing message
    +249      * @param {String} sigHex hexadecimal string of signature value
    +250      * @param {String} pubkeyHex hexadecimal string of public key
    +251      * @return {Boolean} true if the signature is valid, otherwise false
    +252      * @since ecdsa-modified 1.0.1
    +253      * @example
    +254      * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    +255      * var result = ec.verifyHex(msgHashHex, sigHex, pubkeyHex);
    +256      */
    +257     this.verifyHex = function(hashHex, sigHex, pubkeyHex) {
    +258 	var r,s;
    +259 
    +260 	var obj = KJUR.crypto.ECDSA.parseSigHex(sigHex);
    +261 	r = obj.r;
    +262 	s = obj.s;
    +263 
    +264 	var Q;
    +265 	Q = ECPointFp.decodeFromHex(this.ecparams['curve'], pubkeyHex);
    +266 	var e = new BigInteger(hashHex, 16);
    +267 
    +268 	return this.verifyRaw(e, r, s, Q);
    +269     };
    +270 
    +271     this.verify = function (hash, sig, pubkey) {
    +272 	var r,s;
    +273 	if (Bitcoin.Util.isArray(sig)) {
    +274 	    var obj = this.parseSig(sig);
    +275 	    r = obj.r;
    +276 	    s = obj.s;
    +277 	} else if ("object" === typeof sig && sig.r && sig.s) {
    +278 	    r = sig.r;
    +279 	    s = sig.s;
    +280 	} else {
    +281 	    throw "Invalid value for signature";
    +282 	}
    +283 
    +284 	var Q;
    +285 	if (pubkey instanceof ECPointFp) {
    +286 	    Q = pubkey;
    +287 	} else if (Bitcoin.Util.isArray(pubkey)) {
    +288 	    Q = ECPointFp.decodeFrom(this.ecparams['curve'], pubkey);
    +289 	} else {
    +290 	    throw "Invalid format for pubkey value, must be byte array or ECPointFp";
    +291 	}
    +292 	var e = BigInteger.fromByteArrayUnsigned(hash);
    +293 
    +294 	return this.verifyRaw(e, r, s, Q);
    +295     };
    +296 
    +297     this.verifyRaw = function (e, r, s, Q) {
    +298 	var n = this.ecparams['n'];
    +299 	var G = this.ecparams['G'];
    +300 
    +301 	if (r.compareTo(BigInteger.ONE) < 0 ||
    +302 	    r.compareTo(n) >= 0)
    +303 	    return false;
    +304 
    +305 	if (s.compareTo(BigInteger.ONE) < 0 ||
    +306 	    s.compareTo(n) >= 0)
    +307 	    return false;
     308 
    -309 	var u1 = e.multiply(c).mod(n);
    -310 	var u2 = r.multiply(c).mod(n);
    -311 
    -312 	// TODO(!!!): For some reason Shamir's trick isn't working with
    -313 	// signed message verification!? Probably an implementation
    -314 	// error!
    -315 	//var point = implShamirsTrick(G, u1, Q, u2);
    -316 	var point = G.multiply(u1).add(Q.multiply(u2));
    -317 
    -318 	var v = point.getX().toBigInteger().mod(n);
    +309 	var c = s.modInverse(n);
    +310 
    +311 	var u1 = e.multiply(c).mod(n);
    +312 	var u2 = r.multiply(c).mod(n);
    +313 
    +314 	// TODO(!!!): For some reason Shamir's trick isn't working with
    +315 	// signed message verification!? Probably an implementation
    +316 	// error!
    +317 	//var point = implShamirsTrick(G, u1, Q, u2);
    +318 	var point = G.multiply(u1).add(Q.multiply(u2));
     319 
    -320 	return v.equals(r);
    -321     };
    -322 
    -323     /**
    -324      * Serialize a signature into DER format.
    -325      *
    -326      * Takes two BigIntegers representing r and s and returns a byte array.
    -327      */
    -328     this.serializeSig = function (r, s) {
    -329 	var rBa = r.toByteArraySigned();
    -330 	var sBa = s.toByteArraySigned();
    -331 
    -332 	var sequence = [];
    -333 	sequence.push(0x02); // INTEGER
    -334 	sequence.push(rBa.length);
    -335 	sequence = sequence.concat(rBa);
    -336 
    -337 	sequence.push(0x02); // INTEGER
    -338 	sequence.push(sBa.length);
    -339 	sequence = sequence.concat(sBa);
    -340 
    -341 	sequence.unshift(sequence.length);
    -342 	sequence.unshift(0x30); // SEQUENCE
    -343 	return sequence;
    -344     };
    -345 
    -346     /**
    -347      * Parses a byte array containing a DER-encoded signature.
    -348      *
    -349      * This function will return an object of the form:
    +320 	var v = point.getX().toBigInteger().mod(n);
    +321 
    +322 	return v.equals(r);
    +323     };
    +324 
    +325     /**
    +326      * Serialize a signature into DER format.
    +327      *
    +328      * Takes two BigIntegers representing r and s and returns a byte array.
    +329      */
    +330     this.serializeSig = function (r, s) {
    +331 	var rBa = r.toByteArraySigned();
    +332 	var sBa = s.toByteArraySigned();
    +333 
    +334 	var sequence = [];
    +335 	sequence.push(0x02); // INTEGER
    +336 	sequence.push(rBa.length);
    +337 	sequence = sequence.concat(rBa);
    +338 
    +339 	sequence.push(0x02); // INTEGER
    +340 	sequence.push(sBa.length);
    +341 	sequence = sequence.concat(sBa);
    +342 
    +343 	sequence.unshift(sequence.length);
    +344 	sequence.unshift(0x30); // SEQUENCE
    +345 	return sequence;
    +346     };
    +347 
    +348     /**
    +349      * Parses a byte array containing a DER-encoded signature.
     350      *
    -351      * {
    -352      *   r: BigInteger,
    -353      *   s: BigInteger
    -354      * }
    -355      */
    -356     this.parseSig = function (sig) {
    -357 	var cursor;
    -358 	if (sig[0] != 0x30)
    -359 	    throw new Error("Signature not a valid DERSequence");
    -360 
    -361 	cursor = 2;
    -362 	if (sig[cursor] != 0x02)
    -363 	    throw new Error("First element in signature must be a DERInteger");;
    -364 	var rBa = sig.slice(cursor+2, cursor+2+sig[cursor+1]);
    -365 
    -366 	cursor += 2+sig[cursor+1];
    -367 	if (sig[cursor] != 0x02)
    -368 	    throw new Error("Second element in signature must be a DERInteger");
    -369 	var sBa = sig.slice(cursor+2, cursor+2+sig[cursor+1]);
    -370 
    -371 	cursor += 2+sig[cursor+1];
    +351      * This function will return an object of the form:
    +352      *
    +353      * {
    +354      *   r: BigInteger,
    +355      *   s: BigInteger
    +356      * }
    +357      */
    +358     this.parseSig = function (sig) {
    +359 	var cursor;
    +360 	if (sig[0] != 0x30)
    +361 	    throw new Error("Signature not a valid DERSequence");
    +362 
    +363 	cursor = 2;
    +364 	if (sig[cursor] != 0x02)
    +365 	    throw new Error("First element in signature must be a DERInteger");;
    +366 	var rBa = sig.slice(cursor+2, cursor+2+sig[cursor+1]);
    +367 
    +368 	cursor += 2+sig[cursor+1];
    +369 	if (sig[cursor] != 0x02)
    +370 	    throw new Error("Second element in signature must be a DERInteger");
    +371 	var sBa = sig.slice(cursor+2, cursor+2+sig[cursor+1]);
     372 
    -373 	//if (cursor != sig.length)
    -374 	//  throw new Error("Extra bytes in signature");
    -375 
    -376 	var r = BigInteger.fromByteArrayUnsigned(rBa);
    -377 	var s = BigInteger.fromByteArrayUnsigned(sBa);
    -378 
    -379 	return {r: r, s: s};
    -380     };
    -381 
    -382     this.parseSigCompact = function (sig) {
    -383 	if (sig.length !== 65) {
    -384 	    throw "Signature has the wrong length";
    -385 	}
    -386 
    -387 	// Signature is prefixed with a type byte storing three bits of
    -388 	// information.
    -389 	var i = sig[0] - 27;
    -390 	if (i < 0 || i > 7) {
    -391 	    throw "Invalid signature type";
    -392 	}
    -393 
    -394 	var n = this.ecparams['n'];
    -395 	var r = BigInteger.fromByteArrayUnsigned(sig.slice(1, 33)).mod(n);
    -396 	var s = BigInteger.fromByteArrayUnsigned(sig.slice(33, 65)).mod(n);
    -397 
    -398 	return {r: r, s: s, i: i};
    -399     };
    -400 
    -401     /*
    -402      * Recover a public key from a signature.
    -403      *
    -404      * See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
    -405      * Key Recovery Operation".
    -406      *
    -407      * http://www.secg.org/download/aid-780/sec1-v2.pdf
    -408      */
    -409     /*
    -410     recoverPubKey: function (r, s, hash, i) {
    -411 	// The recovery parameter i has two bits.
    -412 	i = i & 3;
    -413 
    -414 	// The less significant bit specifies whether the y coordinate
    -415 	// of the compressed point is even or not.
    -416 	var isYEven = i & 1;
    -417 
    -418 	// The more significant bit specifies whether we should use the
    -419 	// first or second candidate key.
    -420 	var isSecondKey = i >> 1;
    -421 
    -422 	var n = this.ecparams['n'];
    -423 	var G = this.ecparams['G'];
    -424 	var curve = this.ecparams['curve'];
    -425 	var p = curve.getQ();
    -426 	var a = curve.getA().toBigInteger();
    -427 	var b = curve.getB().toBigInteger();
    -428 
    -429 	// We precalculate (p + 1) / 4 where p is if the field order
    -430 	if (!P_OVER_FOUR) {
    -431 	    P_OVER_FOUR = p.add(BigInteger.ONE).divide(BigInteger.valueOf(4));
    -432 	}
    -433 
    -434 	// 1.1 Compute x
    -435 	var x = isSecondKey ? r.add(n) : r;
    -436 
    -437 	// 1.3 Convert x to point
    -438 	var alpha = x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(p);
    -439 	var beta = alpha.modPow(P_OVER_FOUR, p);
    -440 
    -441 	var xorOdd = beta.isEven() ? (i % 2) : ((i+1) % 2);
    -442 	// If beta is even, but y isn't or vice versa, then convert it,
    -443 	// otherwise we're done and y == beta.
    -444 	var y = (beta.isEven() ? !isYEven : isYEven) ? beta : p.subtract(beta);
    -445 
    -446 	// 1.4 Check that nR is at infinity
    -447 	var R = new ECPointFp(curve,
    -448 			      curve.fromBigInteger(x),
    -449 			      curve.fromBigInteger(y));
    -450 	R.validate();
    +373 	cursor += 2+sig[cursor+1];
    +374 
    +375 	//if (cursor != sig.length)
    +376 	//  throw new Error("Extra bytes in signature");
    +377 
    +378 	var r = BigInteger.fromByteArrayUnsigned(rBa);
    +379 	var s = BigInteger.fromByteArrayUnsigned(sBa);
    +380 
    +381 	return {r: r, s: s};
    +382     };
    +383 
    +384     this.parseSigCompact = function (sig) {
    +385 	if (sig.length !== 65) {
    +386 	    throw "Signature has the wrong length";
    +387 	}
    +388 
    +389 	// Signature is prefixed with a type byte storing three bits of
    +390 	// information.
    +391 	var i = sig[0] - 27;
    +392 	if (i < 0 || i > 7) {
    +393 	    throw "Invalid signature type";
    +394 	}
    +395 
    +396 	var n = this.ecparams['n'];
    +397 	var r = BigInteger.fromByteArrayUnsigned(sig.slice(1, 33)).mod(n);
    +398 	var s = BigInteger.fromByteArrayUnsigned(sig.slice(33, 65)).mod(n);
    +399 
    +400 	return {r: r, s: s, i: i};
    +401     };
    +402 
    +403     /**
    +404      * read an ASN.1 hexadecimal string of PKCS#1/5 plain ECC private key<br/>
    +405      * @name readPKCS5PrvKeyHex
    +406      * @memberOf KJUR.crypto.ECDSA#
    +407      * @function
    +408      * @param {String} h hexadecimal string of PKCS#1/5 ECC private key
    +409      * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0
    +410      */
    +411     this.readPKCS5PrvKeyHex = function(h) {
    +412 	var _ASN1HEX = ASN1HEX;
    +413 	var _getName = KJUR.crypto.ECDSA.getName;
    +414 	var _getVbyList = _ASN1HEX.getVbyList;
    +415 
    +416 	if (_ASN1HEX.isASN1HEX(h) === false)
    +417 	    throw "not ASN.1 hex string";
    +418 
    +419 	var hCurve, hPrv, hPub;
    +420 	try {
    +421 	    hCurve = _getVbyList(h, 0, [2, 0], "06");
    +422 	    hPrv   = _getVbyList(h, 0, [1], "04");
    +423 	    try {
    +424 		hPub = _getVbyList(h, 0, [3, 0], "03").substr(2);
    +425 	    } catch(ex) {};
    +426 	} catch(ex) {
    +427 	    throw "malformed PKCS#1/5 plain ECC private key";
    +428 	}
    +429 
    +430 	this.curveName = _getName(hCurve);
    +431 	if (this.curveName === undefined) throw "unsupported curve name";
    +432 
    +433 	this.setNamedCurve(this.curveName);
    +434 	this.setPublicKeyHex(hPub);
    +435 	this.setPrivateKeyHex(hPrv);
    +436         this.isPublic = false;
    +437     };
    +438 
    +439     /**
    +440      * read an ASN.1 hexadecimal string of PKCS#8 plain ECC private key<br/>
    +441      * @name readPKCS8PrvKeyHex
    +442      * @memberOf KJUR.crypto.ECDSA#
    +443      * @function
    +444      * @param {String} h hexadecimal string of PKCS#8 ECC private key
    +445      * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0
    +446      */
    +447     this.readPKCS8PrvKeyHex = function(h) {
    +448 	var _ASN1HEX = ASN1HEX;
    +449 	var _getName = KJUR.crypto.ECDSA.getName;
    +450 	var _getVbyList = _ASN1HEX.getVbyList;
     451 
    -452 	// 1.5 Compute e from M
    -453 	var e = BigInteger.fromByteArrayUnsigned(hash);
    -454 	var eNeg = BigInteger.ZERO.subtract(e).mod(n);
    -455 
    -456 	// 1.6 Compute Q = r^-1 (sR - eG)
    -457 	var rInv = r.modInverse(n);
    -458 	var Q = implShamirsTrick(R, s, G, eNeg).multiply(rInv);
    -459 
    -460 	Q.validate();
    -461 	if (!this.verifyRaw(e, r, s, Q)) {
    -462 	    throw "Pubkey recovery unsuccessful";
    -463 	}
    -464 
    -465 	var pubKey = new Bitcoin.ECKey();
    -466 	pubKey.pub = Q;
    -467 	return pubKey;
    -468     },
    -469     */
    -470 
    -471     /*
    -472      * Calculate pubkey extraction parameter.
    -473      *
    -474      * When extracting a pubkey from a signature, we have to
    -475      * distinguish four different cases. Rather than putting this
    -476      * burden on the verifier, Bitcoin includes a 2-bit value with the
    -477      * signature.
    -478      *
    -479      * This function simply tries all four cases and returns the value
    -480      * that resulted in a successful pubkey recovery.
    -481      */
    -482     /*
    -483     calcPubkeyRecoveryParam: function (address, r, s, hash) {
    -484 	for (var i = 0; i < 4; i++) {
    -485 	    try {
    -486 		var pubkey = Bitcoin.ECDSA.recoverPubKey(r, s, hash, i);
    -487 		if (pubkey.getBitcoinAddress().toString() == address) {
    -488 		    return i;
    -489 		}
    -490 	    } catch (e) {}
    -491 	}
    -492 	throw "Unable to find valid recovery factor";
    -493     }
    -494     */
    -495 
    -496     if (params !== undefined) {
    -497 	if (params['curve'] !== undefined) {
    -498 	    this.curveName = params['curve'];
    +452 	if (_ASN1HEX.isASN1HEX(h) === false)
    +453 	    throw "not ASN.1 hex string";
    +454 
    +455 	var hECOID, hCurve, hPrv, hPub;
    +456 	try {
    +457 	    hECOID = _getVbyList(h, 0, [1, 0], "06");
    +458 	    hCurve = _getVbyList(h, 0, [1, 1], "06");
    +459 	    hPrv   = _getVbyList(h, 0, [2, 0, 1], "04");
    +460 	    try {
    +461 		hPub = _getVbyList(h, 0, [2, 0, 2, 0], "03").substr(2);
    +462 	    } catch(ex) {};
    +463 	} catch(ex) {
    +464 	    throw "malformed PKCS#8 plain ECC private key";
    +465 	}
    +466 
    +467 	this.curveName = _getName(hCurve);
    +468 	if (this.curveName === undefined) throw "unsupported curve name";
    +469 
    +470 	this.setNamedCurve(this.curveName);
    +471 	this.setPublicKeyHex(hPub);
    +472 	this.setPrivateKeyHex(hPrv);
    +473         this.isPublic = false;
    +474     };
    +475 
    +476     /**
    +477      * read an ASN.1 hexadecimal string of PKCS#8 ECC public key<br/>
    +478      * @name readPKCS8PubKeyHex
    +479      * @memberOf KJUR.crypto.ECDSA#
    +480      * @function
    +481      * @param {String} h hexadecimal string of PKCS#8 ECC public key
    +482      * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0
    +483      */
    +484     this.readPKCS8PubKeyHex = function(h) {
    +485 	var _ASN1HEX = ASN1HEX;
    +486 	var _getName = KJUR.crypto.ECDSA.getName;
    +487 	var _getVbyList = _ASN1HEX.getVbyList;
    +488 
    +489 	if (_ASN1HEX.isASN1HEX(h) === false)
    +490 	    throw "not ASN.1 hex string";
    +491 
    +492 	var hECOID, hCurve, hPub;
    +493 	try {
    +494 	    hECOID = _getVbyList(h, 0, [0, 0], "06");
    +495 	    hCurve = _getVbyList(h, 0, [0, 1], "06");
    +496 	    hPub = _getVbyList(h, 0, [1], "03").substr(2);
    +497 	} catch(ex) {
    +498 	    throw "malformed PKCS#8 ECC public key";
     499 	}
    -500     }
    -501     if (this.curveName === undefined) this.curveName = curveName;
    -502     this.setNamedCurve(this.curveName);
    -503     if (params !== undefined) {
    -504 	if (params['prv'] !== undefined) this.setPrivateKeyHex(params['prv']);
    -505 	if (params['pub'] !== undefined) this.setPublicKeyHex(params['pub']);
    -506     }
    -507 };
    -508 
    -509 /**
    -510  * parse ASN.1 DER encoded ECDSA signature
    -511  * @name parseSigHex
    -512  * @memberOf KJUR.crypto.ECDSA
    -513  * @function
    -514  * @static
    -515  * @param {String} sigHex hexadecimal string of ECDSA signature value
    -516  * @return {Array} associative array of signature field r and s of BigInteger
    -517  * @since ecdsa-modified 1.0.1
    -518  * @example
    -519  * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    -520  * var sig = ec.parseSigHex('30...');
    -521  * var biR = sig.r; // BigInteger object for 'r' field of signature.
    -522  * var biS = sig.s; // BigInteger object for 's' field of signature.
    -523  */
    -524 KJUR.crypto.ECDSA.parseSigHex = function(sigHex) {
    -525     var p = KJUR.crypto.ECDSA.parseSigHexInHexRS(sigHex);
    -526     var biR = new BigInteger(p.r, 16);
    -527     var biS = new BigInteger(p.s, 16);
    -528     
    -529     return {'r': biR, 's': biS};
    -530 };
    -531 
    -532 /**
    -533  * parse ASN.1 DER encoded ECDSA signature
    -534  * @name parseSigHexInHexRS
    -535  * @memberOf KJUR.crypto.ECDSA
    -536  * @function
    -537  * @static
    -538  * @param {String} sigHex hexadecimal string of ECDSA signature value
    -539  * @return {Array} associative array of signature field r and s in hexadecimal
    -540  * @since ecdsa-modified 1.0.3
    -541  * @example
    -542  * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    -543  * var sig = ec.parseSigHexInHexRS('30...');
    -544  * var hR = sig.r; // hexadecimal string for 'r' field of signature.
    -545  * var hS = sig.s; // hexadecimal string for 's' field of signature.
    -546  */
    -547 KJUR.crypto.ECDSA.parseSigHexInHexRS = function(sigHex) {
    -548     // 1. ASN.1 Sequence Check
    -549     if (sigHex.substr(0, 2) != "30")
    -550 	throw "signature is not a ASN.1 sequence";
    -551 
    -552     // 2. Items of ASN.1 Sequence Check
    -553     var a = ASN1HEX.getPosArrayOfChildren_AtObj(sigHex, 0);
    -554     if (a.length != 2)
    -555 	throw "number of signature ASN.1 sequence elements seem wrong";
    -556     
    -557     // 3. Integer check
    -558     var iTLV1 = a[0];
    -559     var iTLV2 = a[1];
    -560     if (sigHex.substr(iTLV1, 2) != "02")
    -561 	throw "1st item of sequene of signature is not ASN.1 integer";
    -562     if (sigHex.substr(iTLV2, 2) != "02")
    -563 	throw "2nd item of sequene of signature is not ASN.1 integer";
    -564 
    -565     // 4. getting value
    -566     var hR = ASN1HEX.getHexOfV_AtObj(sigHex, iTLV1);
    -567     var hS = ASN1HEX.getHexOfV_AtObj(sigHex, iTLV2);
    -568     
    -569     return {'r': hR, 's': hS};
    -570 };
    -571 
    -572 /**
    -573  * convert hexadecimal ASN.1 encoded signature to concatinated signature
    -574  * @name asn1SigToConcatSig
    -575  * @memberOf KJUR.crypto.ECDSA
    -576  * @function
    -577  * @static
    -578  * @param {String} asn1Hex hexadecimal string of ASN.1 encoded ECDSA signature value
    -579  * @return {String} r-s concatinated format of ECDSA signature value
    -580  * @since ecdsa-modified 1.0.3
    -581  */
    -582 KJUR.crypto.ECDSA.asn1SigToConcatSig = function(asn1Sig) {
    -583     var pSig = KJUR.crypto.ECDSA.parseSigHexInHexRS(asn1Sig);
    -584     var hR = pSig.r;
    -585     var hS = pSig.s;
    -586 
    -587     if (hR.substr(0, 2) == "00" && (((hR.length / 2) * 8) % (16 * 8)) == 8) 
    -588 	hR = hR.substr(2);
    -589 
    -590     if (hS.substr(0, 2) == "00" && (((hS.length / 2) * 8) % (16 * 8)) == 8) 
    -591 	hS = hS.substr(2);
    -592 
    -593     if ((((hR.length / 2) * 8) % (16 * 8)) != 0)
    -594 	throw "unknown ECDSA sig r length error";
    +500 
    +501 	this.curveName = _getName(hCurve);
    +502 	if (this.curveName === null) throw "unsupported curve name";
    +503 
    +504 	this.setNamedCurve(this.curveName);
    +505 	this.setPublicKeyHex(hPub);
    +506     };
    +507 
    +508     /**
    +509      * read an ASN.1 hexadecimal string of X.509 ECC public key certificate<br/>
    +510      * @name readCertPubKeyHex
    +511      * @memberOf KJUR.crypto.ECDSA#
    +512      * @function
    +513      * @param {String} h hexadecimal string of X.509 ECC public key certificate
    +514      * @param {Integer} nthPKI nth index of publicKeyInfo. (DEFAULT: 6 for X509v3)
    +515      * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0
    +516      */
    +517     this.readCertPubKeyHex = function(h, nthPKI) {
    +518 	if (nthPKI !== 5) nthPKI = 6;
    +519 	var _ASN1HEX = ASN1HEX;
    +520 	var _getName = KJUR.crypto.ECDSA.getName;
    +521 	var _getVbyList = _ASN1HEX.getVbyList;
    +522 
    +523 	if (_ASN1HEX.isASN1HEX(h) === false)
    +524 	    throw "not ASN.1 hex string";
    +525 
    +526 	var hCurve, hPub;
    +527 	try {
    +528 	    hCurve = _getVbyList(h, 0, [0, nthPKI, 0, 1], "06");
    +529 	    hPub = _getVbyList(h, 0, [0, nthPKI, 1], "03").substr(2);
    +530 	} catch(ex) {
    +531 	    throw "malformed X.509 certificate ECC public key";
    +532 	}
    +533 
    +534 	this.curveName = _getName(hCurve);
    +535 	if (this.curveName === null) throw "unsupported curve name";
    +536 
    +537 	this.setNamedCurve(this.curveName);
    +538 	this.setPublicKeyHex(hPub);
    +539     };
    +540 
    +541     /*
    +542      * Recover a public key from a signature.
    +543      *
    +544      * See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
    +545      * Key Recovery Operation".
    +546      *
    +547      * http://www.secg.org/download/aid-780/sec1-v2.pdf
    +548      */
    +549     /*
    +550     recoverPubKey: function (r, s, hash, i) {
    +551 	// The recovery parameter i has two bits.
    +552 	i = i & 3;
    +553 
    +554 	// The less significant bit specifies whether the y coordinate
    +555 	// of the compressed point is even or not.
    +556 	var isYEven = i & 1;
    +557 
    +558 	// The more significant bit specifies whether we should use the
    +559 	// first or second candidate key.
    +560 	var isSecondKey = i >> 1;
    +561 
    +562 	var n = this.ecparams['n'];
    +563 	var G = this.ecparams['G'];
    +564 	var curve = this.ecparams['curve'];
    +565 	var p = curve.getQ();
    +566 	var a = curve.getA().toBigInteger();
    +567 	var b = curve.getB().toBigInteger();
    +568 
    +569 	// We precalculate (p + 1) / 4 where p is if the field order
    +570 	if (!P_OVER_FOUR) {
    +571 	    P_OVER_FOUR = p.add(BigInteger.ONE).divide(BigInteger.valueOf(4));
    +572 	}
    +573 
    +574 	// 1.1 Compute x
    +575 	var x = isSecondKey ? r.add(n) : r;
    +576 
    +577 	// 1.3 Convert x to point
    +578 	var alpha = x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(p);
    +579 	var beta = alpha.modPow(P_OVER_FOUR, p);
    +580 
    +581 	var xorOdd = beta.isEven() ? (i % 2) : ((i+1) % 2);
    +582 	// If beta is even, but y isn't or vice versa, then convert it,
    +583 	// otherwise we're done and y == beta.
    +584 	var y = (beta.isEven() ? !isYEven : isYEven) ? beta : p.subtract(beta);
    +585 
    +586 	// 1.4 Check that nR is at infinity
    +587 	var R = new ECPointFp(curve,
    +588 			      curve.fromBigInteger(x),
    +589 			      curve.fromBigInteger(y));
    +590 	R.validate();
    +591 
    +592 	// 1.5 Compute e from M
    +593 	var e = BigInteger.fromByteArrayUnsigned(hash);
    +594 	var eNeg = BigInteger.ZERO.subtract(e).mod(n);
     595 
    -596     if ((((hS.length / 2) * 8) % (16 * 8)) != 0)
    -597 	throw "unknown ECDSA sig s length error";
    -598 
    -599     return hR + hS;
    -600 };
    -601 
    -602 /**
    -603  * convert hexadecimal concatinated signature to ASN.1 encoded signature
    -604  * @name concatSigToASN1Sig
    -605  * @memberOf KJUR.crypto.ECDSA
    -606  * @function
    -607  * @static
    -608  * @param {String} concatSig r-s concatinated format of ECDSA signature value
    -609  * @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value
    -610  * @since ecdsa-modified 1.0.3
    -611  */
    -612 KJUR.crypto.ECDSA.concatSigToASN1Sig = function(concatSig) {
    -613     if ((((concatSig.length / 2) * 8) % (16 * 8)) != 0)
    -614 	throw "unknown ECDSA concatinated r-s sig  length error";
    -615 
    -616     var hR = concatSig.substr(0, concatSig.length / 2);
    -617     var hS = concatSig.substr(concatSig.length / 2);
    -618     return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(hR, hS);
    -619 };
    -620 
    -621 /**
    -622  * convert hexadecimal R and S value of signature to ASN.1 encoded signature
    -623  * @name hexRSSigToASN1Sig
    -624  * @memberOf KJUR.crypto.ECDSA
    -625  * @function
    -626  * @static
    -627  * @param {String} hR hexadecimal string of R field of ECDSA signature value
    -628  * @param {String} hS hexadecimal string of S field of ECDSA signature value
    -629  * @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value
    -630  * @since ecdsa-modified 1.0.3
    -631  */
    -632 KJUR.crypto.ECDSA.hexRSSigToASN1Sig = function(hR, hS) {
    -633     var biR = new BigInteger(hR, 16);
    -634     var biS = new BigInteger(hS, 16);
    -635     return KJUR.crypto.ECDSA.biRSSigToASN1Sig(biR, biS);
    -636 };
    -637 
    -638 /**
    -639  * convert R and S BigInteger object of signature to ASN.1 encoded signature
    -640  * @name biRSSigToASN1Sig
    -641  * @memberOf KJUR.crypto.ECDSA
    -642  * @function
    -643  * @static
    -644  * @param {BigInteger} biR BigInteger object of R field of ECDSA signature value
    -645  * @param {BigInteger} biS BIgInteger object of S field of ECDSA signature value
    -646  * @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value
    -647  * @since ecdsa-modified 1.0.3
    -648  */
    -649 KJUR.crypto.ECDSA.biRSSigToASN1Sig = function(biR, biS) {
    -650     var derR = new KJUR.asn1.DERInteger({'bigint': biR});
    -651     var derS = new KJUR.asn1.DERInteger({'bigint': biS});
    -652     var derSeq = new KJUR.asn1.DERSequence({'array': [derR, derS]});
    -653     return derSeq.getEncodedHex();
    -654 };
    -655 
    -656 
    \ No newline at end of file +596 // 1.6 Compute Q = r^-1 (sR - eG) +597 var rInv = r.modInverse(n); +598 var Q = implShamirsTrick(R, s, G, eNeg).multiply(rInv); +599 +600 Q.validate(); +601 if (!this.verifyRaw(e, r, s, Q)) { +602 throw "Pubkey recovery unsuccessful"; +603 } +604 +605 var pubKey = new Bitcoin.ECKey(); +606 pubKey.pub = Q; +607 return pubKey; +608 }, +609 */
    +610 +611 /* +612 * Calculate pubkey extraction parameter. +613 * +614 * When extracting a pubkey from a signature, we have to +615 * distinguish four different cases. Rather than putting this +616 * burden on the verifier, Bitcoin includes a 2-bit value with the +617 * signature. +618 * +619 * This function simply tries all four cases and returns the value +620 * that resulted in a successful pubkey recovery. +621 */ +622 /* +623 calcPubkeyRecoveryParam: function (address, r, s, hash) { +624 for (var i = 0; i < 4; i++) { +625 try { +626 var pubkey = Bitcoin.ECDSA.recoverPubKey(r, s, hash, i); +627 if (pubkey.getBitcoinAddress().toString() == address) { +628 return i; +629 } +630 } catch (e) {} +631 } +632 throw "Unable to find valid recovery factor"; +633 } +634 */ +635 +636 if (params !== undefined) { +637 if (params['curve'] !== undefined) { +638 this.curveName = params['curve']; +639 } +640 } +641 if (this.curveName === undefined) this.curveName = curveName; +642 this.setNamedCurve(this.curveName); +643 if (params !== undefined) { +644 if (params.prv !== undefined) this.setPrivateKeyHex(params.prv); +645 if (params.pub !== undefined) this.setPublicKeyHex(params.pub); +646 } +647 }; +648 +649 /** +650 * parse ASN.1 DER encoded ECDSA signature +651 * @name parseSigHex +652 * @memberOf KJUR.crypto.ECDSA +653 * @function +654 * @static +655 * @param {String} sigHex hexadecimal string of ECDSA signature value +656 * @return {Array} associative array of signature field r and s of BigInteger +657 * @since ecdsa-modified 1.0.1 +658 * @example +659 * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'}); +660 * var sig = ec.parseSigHex('30...'); +661 * var biR = sig.r; // BigInteger object for 'r' field of signature. +662 * var biS = sig.s; // BigInteger object for 's' field of signature. +663 */ +664 KJUR.crypto.ECDSA.parseSigHex = function(sigHex) { +665 var p = KJUR.crypto.ECDSA.parseSigHexInHexRS(sigHex); +666 var biR = new BigInteger(p.r, 16); +667 var biS = new BigInteger(p.s, 16); +668 +669 return {'r': biR, 's': biS}; +670 }; +671 +672 /** +673 * parse ASN.1 DER encoded ECDSA signature +674 * @name parseSigHexInHexRS +675 * @memberOf KJUR.crypto.ECDSA +676 * @function +677 * @static +678 * @param {String} sigHex hexadecimal string of ECDSA signature value +679 * @return {Array} associative array of signature field r and s in hexadecimal +680 * @since ecdsa-modified 1.0.3 +681 * @example +682 * var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'}); +683 * var sig = ec.parseSigHexInHexRS('30...'); +684 * var hR = sig.r; // hexadecimal string for 'r' field of signature. +685 * var hS = sig.s; // hexadecimal string for 's' field of signature. +686 */ +687 KJUR.crypto.ECDSA.parseSigHexInHexRS = function(sigHex) { +688 // 1. ASN.1 Sequence Check +689 if (sigHex.substr(0, 2) != "30") +690 throw "signature is not a ASN.1 sequence"; +691 +692 // 2. Items of ASN.1 Sequence Check +693 var a = ASN1HEX.getPosArrayOfChildren_AtObj(sigHex, 0); +694 if (a.length != 2) +695 throw "number of signature ASN.1 sequence elements seem wrong"; +696 +697 // 3. Integer check +698 var iTLV1 = a[0]; +699 var iTLV2 = a[1]; +700 if (sigHex.substr(iTLV1, 2) != "02") +701 throw "1st item of sequene of signature is not ASN.1 integer"; +702 if (sigHex.substr(iTLV2, 2) != "02") +703 throw "2nd item of sequene of signature is not ASN.1 integer"; +704 +705 // 4. getting value +706 var hR = ASN1HEX.getHexOfV_AtObj(sigHex, iTLV1); +707 var hS = ASN1HEX.getHexOfV_AtObj(sigHex, iTLV2); +708 +709 return {'r': hR, 's': hS}; +710 }; +711 +712 /** +713 * convert hexadecimal ASN.1 encoded signature to concatinated signature +714 * @name asn1SigToConcatSig +715 * @memberOf KJUR.crypto.ECDSA +716 * @function +717 * @static +718 * @param {String} asn1Hex hexadecimal string of ASN.1 encoded ECDSA signature value +719 * @return {String} r-s concatinated format of ECDSA signature value +720 * @since ecdsa-modified 1.0.3 +721 */ +722 KJUR.crypto.ECDSA.asn1SigToConcatSig = function(asn1Sig) { +723 var pSig = KJUR.crypto.ECDSA.parseSigHexInHexRS(asn1Sig); +724 var hR = pSig.r; +725 var hS = pSig.s; +726 +727 if (hR.substr(0, 2) == "00" && (((hR.length / 2) * 8) % (16 * 8)) == 8) +728 hR = hR.substr(2); +729 +730 if (hS.substr(0, 2) == "00" && (((hS.length / 2) * 8) % (16 * 8)) == 8) +731 hS = hS.substr(2); +732 +733 if ((((hR.length / 2) * 8) % (16 * 8)) != 0) +734 throw "unknown ECDSA sig r length error"; +735 +736 if ((((hS.length / 2) * 8) % (16 * 8)) != 0) +737 throw "unknown ECDSA sig s length error"; +738 +739 return hR + hS; +740 }; +741 +742 /** +743 * convert hexadecimal concatinated signature to ASN.1 encoded signature +744 * @name concatSigToASN1Sig +745 * @memberOf KJUR.crypto.ECDSA +746 * @function +747 * @static +748 * @param {String} concatSig r-s concatinated format of ECDSA signature value +749 * @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value +750 * @since ecdsa-modified 1.0.3 +751 */ +752 KJUR.crypto.ECDSA.concatSigToASN1Sig = function(concatSig) { +753 if ((((concatSig.length / 2) * 8) % (16 * 8)) != 0) +754 throw "unknown ECDSA concatinated r-s sig length error"; +755 +756 var hR = concatSig.substr(0, concatSig.length / 2); +757 var hS = concatSig.substr(concatSig.length / 2); +758 return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(hR, hS); +759 }; +760 +761 /** +762 * convert hexadecimal R and S value of signature to ASN.1 encoded signature +763 * @name hexRSSigToASN1Sig +764 * @memberOf KJUR.crypto.ECDSA +765 * @function +766 * @static +767 * @param {String} hR hexadecimal string of R field of ECDSA signature value +768 * @param {String} hS hexadecimal string of S field of ECDSA signature value +769 * @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value +770 * @since ecdsa-modified 1.0.3 +771 */ +772 KJUR.crypto.ECDSA.hexRSSigToASN1Sig = function(hR, hS) { +773 var biR = new BigInteger(hR, 16); +774 var biS = new BigInteger(hS, 16); +775 return KJUR.crypto.ECDSA.biRSSigToASN1Sig(biR, biS); +776 }; +777 +778 /** +779 * convert R and S BigInteger object of signature to ASN.1 encoded signature +780 * @name biRSSigToASN1Sig +781 * @memberOf KJUR.crypto.ECDSA +782 * @function +783 * @static +784 * @param {BigInteger} biR BigInteger object of R field of ECDSA signature value +785 * @param {BigInteger} biS BIgInteger object of S field of ECDSA signature value +786 * @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value +787 * @since ecdsa-modified 1.0.3 +788 */ +789 KJUR.crypto.ECDSA.biRSSigToASN1Sig = function(biR, biS) { +790 var derR = new KJUR.asn1.DERInteger({'bigint': biR}); +791 var derS = new KJUR.asn1.DERInteger({'bigint': biS}); +792 var derSeq = new KJUR.asn1.DERSequence({'array': [derR, derS]}); +793 return derSeq.getEncodedHex(); +794 }; +795 +796 /** +797 * static method to get normalized EC curve name from curve name or hexadecimal OID value +798 * @name getName +799 * @memberOf KJUR.crypto.ECDSA +800 * @function +801 * @static +802 * @param {String} s curve name (ex. P-256) or hexadecimal OID value (ex. 2a86...) +803 * @return {String} normalized EC curve name (ex. secp256r1) +804 * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0 +805 * @description +806 * This static method returns normalized EC curve name +807 * which is supported in jsrsasign +808 * from curve name or hexadecimal OID value. +809 * When curve is not supported in jsrsasign, this method returns null. +810 * Normalized name will be "secp*" in jsrsasign. +811 * @example +812 * KJUR.crypto.ECDSA.getName("2b8104000a") → "secp256k1" +813 * KJUR.crypto.ECDSA.getName("NIST P-256") → "secp256r1" +814 * KJUR.crypto.ECDSA.getName("P-521") → undefined // not supported +815 */ +816 KJUR.crypto.ECDSA.getName = function(s) { +817 if (s === "2a8648ce3d030107") return "secp256r1"; // 1.2.840.10045.3.1.7 +818 if (s === "2b8104000a") return "secp256k1"; // 1.3.132.0.10 +819 if (s === "2b81040022") return "secp384r1"; // 1.3.132.0.34 +820 if ("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(s) !== -1) return "secp256r1"; +821 if ("|secp256k1|".indexOf(s) !== -1) return "secp256k1"; +822 if ("|secp384r1|NIST P-384|P-384|".indexOf(s) !== -1) return "secp384r1"; +823 return null; +824 }; +825 +826
    \ No newline at end of file diff --git a/api/symbols/src/keyutil-1.0.js.html b/api/symbols/src/keyutil-1.0.js.html index a6326089..49ec64b0 100644 --- a/api/symbols/src/keyutil-1.0.js.html +++ b/api/symbols/src/keyutil-1.0.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 /*! keyutil-1.0.14.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! keyutil-1.0.15.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * keyutil.js - key utility for PKCS#1/5/8 PEM, RSA/DSA/ECDSA key object
       5  *
    -  6  * Copyright (c) 2013-2016 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license
    @@ -22,7 +22,7 @@
      15  * @fileOverview
      16  * @name keyutil-1.0.js
      17  * @author Kenji Urushima kenji.urushima@gmail.com
    - 18  * @version keyutil 1.0.14 (2016-Oct-08)
    + 18  * @version keyutil 1.1.0 (2017-Jan-14)
      19  * @since jsrsasign 4.1.4
      20  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      21  */
    @@ -285,7 +285,7 @@
     278         version: "1.0.0",
     279 
     280         /**
    -281          * get hexacedimal string of PEM format
    +281          * (DEPRECATED) get hexacedimal string of PEM format
     282          * @name getHexFromPEM
     283          * @memberOf KEYUTIL
     284          * @function
    @@ -293,1814 +293,1752 @@
     286          * @param {String} sHead PEM header string without BEGIN/END
     287          * @return {String} hexadecimal string data of PEM contents
     288          * @since pkcs5pkey 1.0.5
    -289          */
    -290         getHexFromPEM: function(sPEM, sHead) {
    -291             var s = sPEM;
    -292             if (s.indexOf("-----BEGIN ") == -1) {
    -293                 throw "can't find PEM header: " + sHead;
    -294             }
    -295             if (typeof sHead == "string" && sHead != "") {
    -296                 s = s.replace("-----BEGIN " + sHead + "-----", "");
    -297                 s = s.replace("-----END " + sHead + "-----", "");
    -298             } else {
    -299                 s = s.replace(/-----BEGIN [^-]+-----/, '');
    -300                 s = s.replace(/-----END [^-]+-----/, '');
    -301             }
    -302             var sB64 = s.replace(/\s+/g, '');
    -303             var dataHex = b64tohex(sB64);
    -304             return dataHex;
    -305         },
    -306 
    -307         /**
    -308          * decrypt private key by shared key
    -309          * @name getDecryptedKeyHexByKeyIV
    -310          * @memberOf KEYUTIL
    -311          * @function
    -312          * @param {String} encryptedKeyHex hexadecimal string of encrypted private key
    -313          * @param {String} algName name of symmetric key algorithm (ex. 'DES-EBE3-CBC')
    -314          * @param {String} sharedKeyHex hexadecimal string of symmetric key
    -315          * @param {String} ivHex hexadecimal string of initial vector(IV).
    -316          * @return {String} hexadecimal string of decrypted privated key
    -317          */
    -318         getDecryptedKeyHexByKeyIV: function(encryptedKeyHex, algName, sharedKeyHex, ivHex) {
    -319             var f1 = getFuncByName(algName);
    -320             return f1(encryptedKeyHex, sharedKeyHex, ivHex);
    -321         },
    -322 
    -323         /**
    -324          * parse PEM formatted passcode protected PKCS#5 private key
    -325          * @name parsePKCS5PEM
    -326          * @memberOf KEYUTIL
    -327          * @function
    -328          * @param {String} sEncryptedPEM PEM formatted protected passcode protected PKCS#5 private key
    -329          * @return {Hash} hash of key information
    -330          * @description
    -331          * Resulted hash has following attributes.
    -332          * <ul>
    -333          * <li>cipher - symmetric key algorithm name (ex. 'DES-EBE3-CBC', 'AES-256-CBC')</li>
    -334          * <li>ivsalt - IV used for decrypt. Its heading 8 bytes will be used for passcode salt.</li>
    -335          * <li>type - asymmetric key algorithm name of private key described in PEM header.</li>
    -336          * <li>data - base64 encoded encrypted private key.</li>
    -337          * </ul>
    -338          *
    -339          */
    -340         parsePKCS5PEM: function(sPKCS5PEM) {
    -341             return _parsePKCS5PEM(sPKCS5PEM);
    -342         },
    -343 
    -344         /**
    -345          * the same function as OpenSSL EVP_BytsToKey to generate shared key and IV
    -346          * @name getKeyAndUnusedIvByPasscodeAndIvsalt
    -347          * @memberOf KEYUTIL
    -348          * @function
    -349          * @param {String} algName name of symmetric key algorithm (ex. 'DES-EBE3-CBC')
    -350          * @param {String} passcode passcode to decrypt private key (ex. 'password')
    -351          * @param {String} hexadecimal string of IV. heading 8 bytes will be used for passcode salt
    -352          * @return {Hash} hash of key and unused IV (ex. {keyhex:2fe3..., ivhex:3fad..})
    -353          */
    -354         getKeyAndUnusedIvByPasscodeAndIvsalt: function(algName, passcode, ivsaltHex) {
    -355             return _getKeyAndUnusedIvByPasscodeAndIvsalt(algName, passcode, ivsaltHex);
    -356         },
    -357 
    -358         decryptKeyB64: function(privateKeyB64, sharedKeyAlgName, sharedKeyHex, ivsaltHex) {
    -359             return _decryptKeyB64(privateKeyB64, sharedKeyAlgName, sharedKeyHex, ivsaltHex);
    -360         },
    -361 
    -362         /**
    -363          * decrypt PEM formatted protected PKCS#5 private key with passcode
    -364          * @name getDecryptedKeyHex
    -365          * @memberOf KEYUTIL
    -366          * @function
    -367          * @param {String} sEncryptedPEM PEM formatted protected passcode protected PKCS#5 private key
    -368          * @param {String} passcode passcode to decrypt private key (ex. 'password')
    -369          * @return {String} hexadecimal string of decrypted RSA priavte key
    -370          */
    -371         getDecryptedKeyHex: function(sEncryptedPEM, passcode) {
    -372             // 1. parse pem
    -373             var info = _parsePKCS5PEM(sEncryptedPEM);
    -374             var publicKeyAlgName = info.type;
    -375             var sharedKeyAlgName = info.cipher;
    -376             var ivsaltHex = info.ivsalt;
    -377             var privateKeyB64 = info.data;
    -378             //alert("ivsaltHex = " + ivsaltHex);
    -379 
    -380             // 2. generate shared key
    -381             var sharedKeyInfo = _getKeyAndUnusedIvByPasscodeAndIvsalt(sharedKeyAlgName, passcode, ivsaltHex);
    -382             var sharedKeyHex = sharedKeyInfo.keyhex;
    -383             //alert("sharedKeyHex = " + sharedKeyHex);
    -384 
    -385             // 3. decrypt private key
    -386             var decryptedKey = _decryptKeyB64(privateKeyB64, sharedKeyAlgName, sharedKeyHex, ivsaltHex);
    -387             return decryptedKey;
    -388         },
    -389 
    -390         /**
    -391          * (DEPRECATED) read PEM formatted encrypted PKCS#5 private key and returns RSAKey object
    -392          * @name getRSAKeyFromEncryptedPKCS5PEM
    -393          * @memberOf KEYUTIL
    -394          * @function
    -395          * @param {String} sEncryptedP5PEM PEM formatted encrypted PKCS#5 private key
    -396          * @param {String} passcode passcode to decrypt private key
    -397          * @return {RSAKey} loaded RSAKey object of RSA private key
    -398          * @since pkcs5pkey 1.0.2
    -399          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -400          */
    -401         getRSAKeyFromEncryptedPKCS5PEM: function(sEncryptedP5PEM, passcode) {
    -402             var hPKey = this.getDecryptedKeyHex(sEncryptedP5PEM, passcode);
    -403             var rsaKey = new RSAKey();
    -404             rsaKey.readPrivateKeyFromASN1HexString(hPKey);
    -405             return rsaKey;
    -406         },
    -407 
    -408         /*
    -409          * get PEM formatted encrypted PKCS#5 private key from hexadecimal string of plain private key
    -410          * @name getEncryptedPKCS5PEMFromPrvKeyHex
    -411          * @memberOf KEYUTIL
    -412          * @function
    -413          * @param {String} pemHeadAlg algorithm name in the pem header (i.e. RSA,EC or DSA)
    -414          * @param {String} hPrvKey hexadecimal string of plain private key
    -415          * @param {String} passcode pass code to protect private key (ex. password)
    -416          * @param {String} sharedKeyAlgName algorithm name to protect private key (ex. AES-256-CBC)
    -417          * @param {String} ivsaltHex hexadecimal string of IV and salt
    -418          * @return {String} string of PEM formatted encrypted PKCS#5 private key
    -419          * @since pkcs5pkey 1.0.2
    -420          * @description
    -421          * <br/>
    -422          * generate PEM formatted encrypted PKCS#5 private key by hexadecimal string encoded
    -423          * ASN.1 object of plain RSA private key.
    -424          * Following arguments can be omitted.
    -425          * <ul>
    -426          * <li>alg - AES-256-CBC will be used if omitted.</li>
    -427          * <li>ivsaltHex - automatically generate IV and salt which length depends on algorithm</li>
    -428          * </ul>
    -429          * NOTE1: DES-CBC, DES-EDE3-CBC, AES-{128,192.256}-CBC algorithm are supported.
    -430          * @example
    -431          * var pem = 
    -432          *   KEYUTIL.getEncryptedPKCS5PEMFromPrvKeyHex(plainKeyHex, "password");
    -433          * var pem2 = 
    -434          *   KEYUTIL.getEncryptedPKCS5PEMFromPrvKeyHex(plainKeyHex, "password", "AES-128-CBC");
    -435          * var pem3 = 
    -436          *   KEYUTIL.getEncryptedPKCS5PEMFromPrvKeyHex(plainKeyHex, "password", "AES-128-CBC", "1f3d02...");
    -437          */
    -438         getEncryptedPKCS5PEMFromPrvKeyHex: function(pemHeadAlg, hPrvKey, passcode, sharedKeyAlgName, ivsaltHex) {
    -439             var sPEM = "";
    -440 
    -441             // 1. set sharedKeyAlgName if undefined (default AES-256-CBC)
    -442             if (typeof sharedKeyAlgName == "undefined" || sharedKeyAlgName == null) {
    -443                 sharedKeyAlgName = "AES-256-CBC";
    -444             }
    -445             if (typeof ALGLIST[sharedKeyAlgName] == "undefined")
    -446                 throw "KEYUTIL unsupported algorithm: " + sharedKeyAlgName;
    -447 
    -448             // 2. set ivsaltHex if undefined
    -449             if (typeof ivsaltHex == "undefined" || ivsaltHex == null) {
    -450                 var ivlen = ALGLIST[sharedKeyAlgName]['ivlen'];
    -451                 var randIV = _generateIvSaltHex(ivlen);
    -452                 ivsaltHex = randIV.toUpperCase();
    -453             }
    -454 
    -455             // 3. get shared key
    -456             //alert("ivsalthex=" + ivsaltHex);
    -457             var sharedKeyInfo = _getKeyAndUnusedIvByPasscodeAndIvsalt(sharedKeyAlgName, passcode, ivsaltHex);
    -458             var sharedKeyHex = sharedKeyInfo.keyhex;
    -459             // alert("sharedKeyHex = " + sharedKeyHex);
    -460 
    -461             // 3. get encrypted Key in Base64
    -462             var encryptedKeyB64 = _encryptKeyHex(hPrvKey, sharedKeyAlgName, sharedKeyHex, ivsaltHex);
    -463 
    -464             var pemBody = encryptedKeyB64.replace(/(.{64})/g, "$1\r\n");
    -465             var sPEM = "-----BEGIN " + pemHeadAlg + " PRIVATE KEY-----\r\n";
    -466             sPEM += "Proc-Type: 4,ENCRYPTED\r\n";
    -467             sPEM += "DEK-Info: " + sharedKeyAlgName + "," + ivsaltHex + "\r\n";
    -468             sPEM += "\r\n";
    -469             sPEM += pemBody;
    -470             sPEM += "\r\n-----END " + pemHeadAlg + " PRIVATE KEY-----\r\n";
    -471 
    -472             return sPEM;
    -473         },
    -474 
    -475         /**
    -476          * (DEPRECATED) get PEM formatted encrypted PKCS#5 private key from RSAKey object of private key
    -477          * @name getEncryptedPKCS5PEMFromRSAKey
    -478          * @memberOf KEYUTIL
    -479          * @function
    -480          * @param {RSAKey} pKey RSAKey object of private key
    -481          * @param {String} passcode pass code to protect private key (ex. password)
    -482          * @param {String} alg algorithm name to protect private key (default AES-256-CBC)
    -483          * @param {String} ivsaltHex hexadecimal string of IV and salt (default generated random IV)
    -484          * @return {String} string of PEM formatted encrypted PKCS#5 private key
    -485          * @since pkcs5pkey 1.0.2
    -486          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getPEM#}.
    -487          * @description
    -488          * <br/>
    -489          * generate PEM formatted encrypted PKCS#5 private key by
    -490          * {@link RSAKey} object of RSA private key and passcode.
    -491          * Following argument can be omitted.
    -492          * <ul>
    -493          * <li>alg - AES-256-CBC will be used if omitted.</li>
    -494          * <li>ivsaltHex - automatically generate IV and salt which length depends on algorithm</li>
    -495          * </ul>
    -496          * @example
    -497          * var pkey = new RSAKey();
    -498          * pkey.generate(1024, '10001'); // generate 1024bit RSA private key with public exponent 'x010001'
    -499          * var pem = KEYUTIL.getEncryptedPKCS5PEMFromRSAKey(pkey, "password");
    -500          */
    -501         getEncryptedPKCS5PEMFromRSAKey: function(pKey, passcode, alg, ivsaltHex) {
    -502             var version = new KJUR.asn1.DERInteger({'int': 0});
    -503             var n = new KJUR.asn1.DERInteger({'bigint': pKey.n});
    -504             var e = new KJUR.asn1.DERInteger({'int': pKey.e});
    -505             var d = new KJUR.asn1.DERInteger({'bigint': pKey.d});
    -506             var p = new KJUR.asn1.DERInteger({'bigint': pKey.p});
    -507             var q = new KJUR.asn1.DERInteger({'bigint': pKey.q});
    -508             var dmp1 = new KJUR.asn1.DERInteger({'bigint': pKey.dmp1});
    -509             var dmq1 = new KJUR.asn1.DERInteger({'bigint': pKey.dmq1});
    -510             var coeff = new KJUR.asn1.DERInteger({'bigint': pKey.coeff});
    -511             var seq = new KJUR.asn1.DERSequence({'array': [version, n, e, d, p, q, dmp1, dmq1, coeff]});
    -512             var hex = seq.getEncodedHex();
    -513             return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA", hex, passcode, alg, ivsaltHex);
    -514         },
    -515 
    -516         /**
    -517          * generate RSAKey and PEM formatted encrypted PKCS#5 private key
    -518          * @name newEncryptedPKCS5PEM
    -519          * @memberOf KEYUTIL
    -520          * @function
    -521          * @param {String} passcode pass code to protect private key (ex. password)
    -522          * @param {Integer} keyLen key bit length of RSA key to be generated. (default 1024)
    -523          * @param {String} hPublicExponent hexadecimal string of public exponent (default 10001)
    -524          * @param {String} alg shared key algorithm to encrypt private key (default AES-258-CBC)
    -525          * @return {String} string of PEM formatted encrypted PKCS#5 private key
    -526          * @since pkcs5pkey 1.0.2
    -527          * @example
    -528          * var pem1 = KEYUTIL.newEncryptedPKCS5PEM("password");           // RSA1024bit/10001/AES-256-CBC
    -529          * var pem2 = KEYUTIL.newEncryptedPKCS5PEM("password", 512);      // RSA 512bit/10001/AES-256-CBC
    -530          * var pem3 = KEYUTIL.newEncryptedPKCS5PEM("password", 512, '3'); // RSA 512bit/    3/AES-256-CBC
    -531          */
    -532         newEncryptedPKCS5PEM: function(passcode, keyLen, hPublicExponent, alg) {
    -533             if (typeof keyLen == "undefined" || keyLen == null) {
    -534                 keyLen = 1024;
    -535             }
    -536             if (typeof hPublicExponent == "undefined" || hPublicExponent == null) {
    -537                 hPublicExponent = '10001';
    -538             }
    -539             var pKey = new RSAKey();
    -540             pKey.generate(keyLen, hPublicExponent);
    -541             var pem = null;
    -542             if (typeof alg == "undefined" || alg == null) {
    -543                 pem = this.getEncryptedPKCS5PEMFromRSAKey(pKey, passcode);
    -544             } else {
    -545                 pem = this.getEncryptedPKCS5PEMFromRSAKey(pKey, passcode, alg);
    -546             }
    -547             return pem;
    -548         },
    -549 
    -550         // === PKCS8 ===============================================================
    -551 
    -552         /**
    -553          * (DEPRECATED) read PEM formatted unencrypted PKCS#8 private key and returns RSAKey object
    -554          * @name getRSAKeyFromPlainPKCS8PEM
    -555          * @memberOf KEYUTIL
    -556          * @function
    -557          * @param {String} pkcs8PEM PEM formatted unencrypted PKCS#8 private key
    -558          * @return {RSAKey} loaded RSAKey object of RSA private key
    -559          * @since pkcs5pkey 1.0.1
    -560          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -561          */
    -562         getRSAKeyFromPlainPKCS8PEM: function(pkcs8PEM) {
    -563             if (pkcs8PEM.match(/ENCRYPTED/))
    -564                 throw "pem shall be not ENCRYPTED";
    -565             var prvKeyHex = this.getHexFromPEM(pkcs8PEM, "PRIVATE KEY");
    -566             var rsaKey = this.getRSAKeyFromPlainPKCS8Hex(prvKeyHex);
    -567             return rsaKey;
    -568         },
    -569 
    -570         /**
    -571          * (DEPRECATED) provide hexadecimal string of unencrypted PKCS#8 private key and returns RSAKey object
    -572          * @name getRSAKeyFromPlainPKCS8Hex
    -573          * @memberOf KEYUTIL
    -574          * @function
    -575          * @param {String} prvKeyHex hexadecimal string of unencrypted PKCS#8 private key
    -576          * @return {RSAKey} loaded RSAKey object of RSA private key
    -577          * @since pkcs5pkey 1.0.3
    -578          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -579          */
    -580         getRSAKeyFromPlainPKCS8Hex: function(prvKeyHex) {
    -581             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(prvKeyHex, 0);
    -582             if (a1.length != 3)
    -583                 throw "outer DERSequence shall have 3 elements: " + a1.length;
    -584             var algIdTLV =ASN1HEX.getHexOfTLV_AtObj(prvKeyHex, a1[1]);
    -585             if (algIdTLV != "300d06092a864886f70d0101010500") // AlgId rsaEncryption
    -586                 throw "PKCS8 AlgorithmIdentifier is not rsaEnc: " + algIdTLV;
    -587             var algIdTLV = ASN1HEX.getHexOfTLV_AtObj(prvKeyHex, a1[1]);
    -588             var octetStr = ASN1HEX.getHexOfTLV_AtObj(prvKeyHex, a1[2]);
    -589             var p5KeyHex = ASN1HEX.getHexOfV_AtObj(octetStr, 0);
    -590             //alert(p5KeyHex);
    -591             var rsaKey = new RSAKey();
    -592             rsaKey.readPrivateKeyFromASN1HexString(p5KeyHex);
    -593             return rsaKey;
    -594         },
    -595 
    -596         /**
    -597          * generate PBKDF2 key hexstring with specified passcode and information
    -598          * @name parseHexOfEncryptedPKCS8
    -599          * @memberOf KEYUTIL
    -600          * @function
    -601          * @param {String} passcode passcode to decrypto private key
    -602          * @return {Array} info associative array of PKCS#8 parameters
    -603          * @since pkcs5pkey 1.0.3
    -604          * @description
    -605          * The associative array which is returned by this method has following properties:
    -606          * <ul>
    -607          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
    -608          * <li>info.pkbdf2Iter - iteration count</li>
    -609          * <li>info.ciphertext - hexadecimal string of encrypted private key</li>
    -610          * <li>info.encryptionSchemeAlg - encryption algorithm name (currently TripleDES only)</li>
    -611          * <li>info.encryptionSchemeIV - initial vector for encryption algorithm</li>
    -612          * </ul>
    -613          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    -614          * <ul>
    -615          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    -616          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    -617          * </ul>
    -618          * @example
    -619          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    -620          * // key with PBKDF2 with TripleDES
    -621          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    -622          */
    -623         parseHexOfEncryptedPKCS8: function(sHEX) {
    -624             var info = {};
    -625             
    -626             var a0 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, 0);
    -627             if (a0.length != 2)
    -628                 throw "malformed format: SEQUENCE(0).items != 2: " + a0.length;
    -629 
    -630             // 1. ciphertext
    -631             info.ciphertext = ASN1HEX.getHexOfV_AtObj(sHEX, a0[1]);
    +289 	 * @deprecated from keyutil 1.1.0 jsrsasign 7.0.1. please move to {@link ASN1HEX.pemToHex}
    +290          */
    +291         getHexFromPEM: function(sPEM, sHead) {
    +292 	    return ASN1HEX.pemToHex(sPEM, sHead);
    +293         },
    +294 
    +295         /**
    +296          * decrypt private key by shared key
    +297          * @name getDecryptedKeyHexByKeyIV
    +298          * @memberOf KEYUTIL
    +299          * @function
    +300          * @param {String} encryptedKeyHex hexadecimal string of encrypted private key
    +301          * @param {String} algName name of symmetric key algorithm (ex. 'DES-EBE3-CBC')
    +302          * @param {String} sharedKeyHex hexadecimal string of symmetric key
    +303          * @param {String} ivHex hexadecimal string of initial vector(IV).
    +304          * @return {String} hexadecimal string of decrypted privated key
    +305          */
    +306         getDecryptedKeyHexByKeyIV: function(encryptedKeyHex, algName, sharedKeyHex, ivHex) {
    +307             var f1 = getFuncByName(algName);
    +308             return f1(encryptedKeyHex, sharedKeyHex, ivHex);
    +309         },
    +310 
    +311         /**
    +312          * parse PEM formatted passcode protected PKCS#5 private key
    +313          * @name parsePKCS5PEM
    +314          * @memberOf KEYUTIL
    +315          * @function
    +316          * @param {String} sEncryptedPEM PEM formatted protected passcode protected PKCS#5 private key
    +317          * @return {Hash} hash of key information
    +318          * @description
    +319          * Resulted hash has following attributes.
    +320          * <ul>
    +321          * <li>cipher - symmetric key algorithm name (ex. 'DES-EBE3-CBC', 'AES-256-CBC')</li>
    +322          * <li>ivsalt - IV used for decrypt. Its heading 8 bytes will be used for passcode salt.</li>
    +323          * <li>type - asymmetric key algorithm name of private key described in PEM header.</li>
    +324          * <li>data - base64 encoded encrypted private key.</li>
    +325          * </ul>
    +326          *
    +327          */
    +328         parsePKCS5PEM: function(sPKCS5PEM) {
    +329             return _parsePKCS5PEM(sPKCS5PEM);
    +330         },
    +331 
    +332         /**
    +333          * the same function as OpenSSL EVP_BytsToKey to generate shared key and IV
    +334          * @name getKeyAndUnusedIvByPasscodeAndIvsalt
    +335          * @memberOf KEYUTIL
    +336          * @function
    +337          * @param {String} algName name of symmetric key algorithm (ex. 'DES-EBE3-CBC')
    +338          * @param {String} passcode passcode to decrypt private key (ex. 'password')
    +339          * @param {String} hexadecimal string of IV. heading 8 bytes will be used for passcode salt
    +340          * @return {Hash} hash of key and unused IV (ex. {keyhex:2fe3..., ivhex:3fad..})
    +341          */
    +342         getKeyAndUnusedIvByPasscodeAndIvsalt: function(algName, passcode, ivsaltHex) {
    +343             return _getKeyAndUnusedIvByPasscodeAndIvsalt(algName, passcode, ivsaltHex);
    +344         },
    +345 
    +346         decryptKeyB64: function(privateKeyB64, sharedKeyAlgName, sharedKeyHex, ivsaltHex) {
    +347             return _decryptKeyB64(privateKeyB64, sharedKeyAlgName, sharedKeyHex, ivsaltHex);
    +348         },
    +349 
    +350         /**
    +351          * decrypt PEM formatted protected PKCS#5 private key with passcode
    +352          * @name getDecryptedKeyHex
    +353          * @memberOf KEYUTIL
    +354          * @function
    +355          * @param {String} sEncryptedPEM PEM formatted protected passcode protected PKCS#5 private key
    +356          * @param {String} passcode passcode to decrypt private key (ex. 'password')
    +357          * @return {String} hexadecimal string of decrypted RSA priavte key
    +358          */
    +359         getDecryptedKeyHex: function(sEncryptedPEM, passcode) {
    +360             // 1. parse pem
    +361             var info = _parsePKCS5PEM(sEncryptedPEM);
    +362             var publicKeyAlgName = info.type;
    +363             var sharedKeyAlgName = info.cipher;
    +364             var ivsaltHex = info.ivsalt;
    +365             var privateKeyB64 = info.data;
    +366             //alert("ivsaltHex = " + ivsaltHex);
    +367 
    +368             // 2. generate shared key
    +369             var sharedKeyInfo = _getKeyAndUnusedIvByPasscodeAndIvsalt(sharedKeyAlgName, passcode, ivsaltHex);
    +370             var sharedKeyHex = sharedKeyInfo.keyhex;
    +371             //alert("sharedKeyHex = " + sharedKeyHex);
    +372 
    +373             // 3. decrypt private key
    +374             var decryptedKey = _decryptKeyB64(privateKeyB64, sharedKeyAlgName, sharedKeyHex, ivsaltHex);
    +375             return decryptedKey;
    +376         },
    +377 
    +378         /**
    +379          * (DEPRECATED) read PEM formatted encrypted PKCS#5 private key and returns RSAKey object
    +380          * @name getRSAKeyFromEncryptedPKCS5PEM
    +381          * @memberOf KEYUTIL
    +382          * @function
    +383          * @param {String} sEncryptedP5PEM PEM formatted encrypted PKCS#5 private key
    +384          * @param {String} passcode passcode to decrypt private key
    +385          * @return {RSAKey} loaded RSAKey object of RSA private key
    +386          * @since pkcs5pkey 1.0.2
    +387          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +388          */
    +389         getRSAKeyFromEncryptedPKCS5PEM: function(sEncryptedP5PEM, passcode) {
    +390             var hPKey = this.getDecryptedKeyHex(sEncryptedP5PEM, passcode);
    +391             var rsaKey = new RSAKey();
    +392             rsaKey.readPrivateKeyFromASN1HexString(hPKey);
    +393             return rsaKey;
    +394         },
    +395 
    +396         /*
    +397          * get PEM formatted encrypted PKCS#5 private key from hexadecimal string of plain private key
    +398          * @name getEncryptedPKCS5PEMFromPrvKeyHex
    +399          * @memberOf KEYUTIL
    +400          * @function
    +401          * @param {String} pemHeadAlg algorithm name in the pem header (i.e. RSA,EC or DSA)
    +402          * @param {String} hPrvKey hexadecimal string of plain private key
    +403          * @param {String} passcode pass code to protect private key (ex. password)
    +404          * @param {String} sharedKeyAlgName algorithm name to protect private key (ex. AES-256-CBC)
    +405          * @param {String} ivsaltHex hexadecimal string of IV and salt
    +406          * @return {String} string of PEM formatted encrypted PKCS#5 private key
    +407          * @since pkcs5pkey 1.0.2
    +408          * @description
    +409          * <br/>
    +410          * generate PEM formatted encrypted PKCS#5 private key by hexadecimal string encoded
    +411          * ASN.1 object of plain RSA private key.
    +412          * Following arguments can be omitted.
    +413          * <ul>
    +414          * <li>alg - AES-256-CBC will be used if omitted.</li>
    +415          * <li>ivsaltHex - automatically generate IV and salt which length depends on algorithm</li>
    +416          * </ul>
    +417          * NOTE1: DES-CBC, DES-EDE3-CBC, AES-{128,192.256}-CBC algorithm are supported.
    +418          * @example
    +419          * var pem = 
    +420          *   KEYUTIL.getEncryptedPKCS5PEMFromPrvKeyHex(plainKeyHex, "password");
    +421          * var pem2 = 
    +422          *   KEYUTIL.getEncryptedPKCS5PEMFromPrvKeyHex(plainKeyHex, "password", "AES-128-CBC");
    +423          * var pem3 = 
    +424          *   KEYUTIL.getEncryptedPKCS5PEMFromPrvKeyHex(plainKeyHex, "password", "AES-128-CBC", "1f3d02...");
    +425          */
    +426         getEncryptedPKCS5PEMFromPrvKeyHex: function(pemHeadAlg, hPrvKey, passcode, sharedKeyAlgName, ivsaltHex) {
    +427             var sPEM = "";
    +428 
    +429             // 1. set sharedKeyAlgName if undefined (default AES-256-CBC)
    +430             if (typeof sharedKeyAlgName == "undefined" || sharedKeyAlgName == null) {
    +431                 sharedKeyAlgName = "AES-256-CBC";
    +432             }
    +433             if (typeof ALGLIST[sharedKeyAlgName] == "undefined")
    +434                 throw "KEYUTIL unsupported algorithm: " + sharedKeyAlgName;
    +435 
    +436             // 2. set ivsaltHex if undefined
    +437             if (typeof ivsaltHex == "undefined" || ivsaltHex == null) {
    +438                 var ivlen = ALGLIST[sharedKeyAlgName]['ivlen'];
    +439                 var randIV = _generateIvSaltHex(ivlen);
    +440                 ivsaltHex = randIV.toUpperCase();
    +441             }
    +442 
    +443             // 3. get shared key
    +444             //alert("ivsalthex=" + ivsaltHex);
    +445             var sharedKeyInfo = _getKeyAndUnusedIvByPasscodeAndIvsalt(sharedKeyAlgName, passcode, ivsaltHex);
    +446             var sharedKeyHex = sharedKeyInfo.keyhex;
    +447             // alert("sharedKeyHex = " + sharedKeyHex);
    +448 
    +449             // 3. get encrypted Key in Base64
    +450             var encryptedKeyB64 = _encryptKeyHex(hPrvKey, sharedKeyAlgName, sharedKeyHex, ivsaltHex);
    +451 
    +452             var pemBody = encryptedKeyB64.replace(/(.{64})/g, "$1\r\n");
    +453             var sPEM = "-----BEGIN " + pemHeadAlg + " PRIVATE KEY-----\r\n";
    +454             sPEM += "Proc-Type: 4,ENCRYPTED\r\n";
    +455             sPEM += "DEK-Info: " + sharedKeyAlgName + "," + ivsaltHex + "\r\n";
    +456             sPEM += "\r\n";
    +457             sPEM += pemBody;
    +458             sPEM += "\r\n-----END " + pemHeadAlg + " PRIVATE KEY-----\r\n";
    +459 
    +460             return sPEM;
    +461         },
    +462 
    +463         /**
    +464          * (DEPRECATED) get PEM formatted encrypted PKCS#5 private key from RSAKey object of private key
    +465          * @name getEncryptedPKCS5PEMFromRSAKey
    +466          * @memberOf KEYUTIL
    +467          * @function
    +468          * @param {RSAKey} pKey RSAKey object of private key
    +469          * @param {String} passcode pass code to protect private key (ex. password)
    +470          * @param {String} alg algorithm name to protect private key (default AES-256-CBC)
    +471          * @param {String} ivsaltHex hexadecimal string of IV and salt (default generated random IV)
    +472          * @return {String} string of PEM formatted encrypted PKCS#5 private key
    +473          * @since pkcs5pkey 1.0.2
    +474          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getPEM#}.
    +475          * @description
    +476          * <br/>
    +477          * generate PEM formatted encrypted PKCS#5 private key by
    +478          * {@link RSAKey} object of RSA private key and passcode.
    +479          * Following argument can be omitted.
    +480          * <ul>
    +481          * <li>alg - AES-256-CBC will be used if omitted.</li>
    +482          * <li>ivsaltHex - automatically generate IV and salt which length depends on algorithm</li>
    +483          * </ul>
    +484          * @example
    +485          * var pkey = new RSAKey();
    +486          * pkey.generate(1024, '10001'); // generate 1024bit RSA private key with public exponent 'x010001'
    +487          * var pem = KEYUTIL.getEncryptedPKCS5PEMFromRSAKey(pkey, "password");
    +488          */
    +489         getEncryptedPKCS5PEMFromRSAKey: function(pKey, passcode, alg, ivsaltHex) {
    +490             var version = new KJUR.asn1.DERInteger({'int': 0});
    +491             var n = new KJUR.asn1.DERInteger({'bigint': pKey.n});
    +492             var e = new KJUR.asn1.DERInteger({'int': pKey.e});
    +493             var d = new KJUR.asn1.DERInteger({'bigint': pKey.d});
    +494             var p = new KJUR.asn1.DERInteger({'bigint': pKey.p});
    +495             var q = new KJUR.asn1.DERInteger({'bigint': pKey.q});
    +496             var dmp1 = new KJUR.asn1.DERInteger({'bigint': pKey.dmp1});
    +497             var dmq1 = new KJUR.asn1.DERInteger({'bigint': pKey.dmq1});
    +498             var coeff = new KJUR.asn1.DERInteger({'bigint': pKey.coeff});
    +499             var seq = new KJUR.asn1.DERSequence({'array': [version, n, e, d, p, q, dmp1, dmq1, coeff]});
    +500             var hex = seq.getEncodedHex();
    +501             return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA", hex, passcode, alg, ivsaltHex);
    +502         },
    +503 
    +504         /**
    +505          * generate RSAKey and PEM formatted encrypted PKCS#5 private key
    +506          * @name newEncryptedPKCS5PEM
    +507          * @memberOf KEYUTIL
    +508          * @function
    +509          * @param {String} passcode pass code to protect private key (ex. password)
    +510          * @param {Integer} keyLen key bit length of RSA key to be generated. (default 1024)
    +511          * @param {String} hPublicExponent hexadecimal string of public exponent (default 10001)
    +512          * @param {String} alg shared key algorithm to encrypt private key (default AES-258-CBC)
    +513          * @return {String} string of PEM formatted encrypted PKCS#5 private key
    +514          * @since pkcs5pkey 1.0.2
    +515          * @example
    +516          * var pem1 = KEYUTIL.newEncryptedPKCS5PEM("password");           // RSA1024bit/10001/AES-256-CBC
    +517          * var pem2 = KEYUTIL.newEncryptedPKCS5PEM("password", 512);      // RSA 512bit/10001/AES-256-CBC
    +518          * var pem3 = KEYUTIL.newEncryptedPKCS5PEM("password", 512, '3'); // RSA 512bit/    3/AES-256-CBC
    +519          */
    +520         newEncryptedPKCS5PEM: function(passcode, keyLen, hPublicExponent, alg) {
    +521             if (typeof keyLen == "undefined" || keyLen == null) {
    +522                 keyLen = 1024;
    +523             }
    +524             if (typeof hPublicExponent == "undefined" || hPublicExponent == null) {
    +525                 hPublicExponent = '10001';
    +526             }
    +527             var pKey = new RSAKey();
    +528             pKey.generate(keyLen, hPublicExponent);
    +529             var pem = null;
    +530             if (typeof alg == "undefined" || alg == null) {
    +531                 pem = this.getEncryptedPKCS5PEMFromRSAKey(pKey, passcode);
    +532             } else {
    +533                 pem = this.getEncryptedPKCS5PEMFromRSAKey(pKey, passcode, alg);
    +534             }
    +535             return pem;
    +536         },
    +537 
    +538         // === PKCS8 ===============================================================
    +539 
    +540         /**
    +541          * (DEPRECATED) read PEM formatted unencrypted PKCS#8 private key and returns RSAKey object
    +542          * @name getRSAKeyFromPlainPKCS8PEM
    +543          * @memberOf KEYUTIL
    +544          * @function
    +545          * @param {String} pkcs8PEM PEM formatted unencrypted PKCS#8 private key
    +546          * @return {RSAKey} loaded RSAKey object of RSA private key
    +547          * @since pkcs5pkey 1.0.1
    +548          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +549          */
    +550         getRSAKeyFromPlainPKCS8PEM: function(pkcs8PEM) {
    +551             if (pkcs8PEM.match(/ENCRYPTED/))
    +552                 throw "pem shall be not ENCRYPTED";
    +553             var prvKeyHex = ASN1HEX.pemToHex(pkcs8PEM, "PRIVATE KEY");
    +554             var rsaKey = this.getRSAKeyFromPlainPKCS8Hex(prvKeyHex);
    +555             return rsaKey;
    +556         },
    +557 
    +558         /**
    +559          * (DEPRECATED) provide hexadecimal string of unencrypted PKCS#8 private key and returns RSAKey object
    +560          * @name getRSAKeyFromPlainPKCS8Hex
    +561          * @memberOf KEYUTIL
    +562          * @function
    +563          * @param {String} prvKeyHex hexadecimal string of unencrypted PKCS#8 private key
    +564          * @return {RSAKey} loaded RSAKey object of RSA private key
    +565          * @since pkcs5pkey 1.0.3
    +566          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +567          */
    +568         getRSAKeyFromPlainPKCS8Hex: function(prvKeyHex) {
    +569             var rsaKey = new RSAKey();
    +570             rsaKey.readPKCS8PrvKeyHex(prvKeyHex);
    +571             return rsaKey;
    +572 	},
    +573 
    +574         /**
    +575          * generate PBKDF2 key hexstring with specified passcode and information
    +576          * @name parseHexOfEncryptedPKCS8
    +577          * @memberOf KEYUTIL
    +578          * @function
    +579          * @param {String} passcode passcode to decrypto private key
    +580          * @return {Array} info associative array of PKCS#8 parameters
    +581          * @since pkcs5pkey 1.0.3
    +582          * @description
    +583          * The associative array which is returned by this method has following properties:
    +584          * <ul>
    +585          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
    +586          * <li>info.pkbdf2Iter - iteration count</li>
    +587          * <li>info.ciphertext - hexadecimal string of encrypted private key</li>
    +588          * <li>info.encryptionSchemeAlg - encryption algorithm name (currently TripleDES only)</li>
    +589          * <li>info.encryptionSchemeIV - initial vector for encryption algorithm</li>
    +590          * </ul>
    +591          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    +592          * <ul>
    +593          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    +594          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    +595          * </ul>
    +596          * @example
    +597          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    +598          * // key with PBKDF2 with TripleDES
    +599          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    +600          */
    +601         parseHexOfEncryptedPKCS8: function(sHEX) {
    +602             var info = {};
    +603             
    +604             var a0 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, 0);
    +605             if (a0.length != 2)
    +606                 throw "malformed format: SEQUENCE(0).items != 2: " + a0.length;
    +607 
    +608             // 1. ciphertext
    +609             info.ciphertext = ASN1HEX.getHexOfV_AtObj(sHEX, a0[1]);
    +610 
    +611             // 2. pkcs5PBES2
    +612             var a0_0 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0[0]); 
    +613             if (a0_0.length != 2)
    +614                 throw "malformed format: SEQUENCE(0.0).items != 2: " + a0_0.length;
    +615 
    +616             // 2.1 check if pkcs5PBES2(1 2 840 113549 1 5 13)
    +617             if (ASN1HEX.getHexOfV_AtObj(sHEX, a0_0[0]) != "2a864886f70d01050d")
    +618                 throw "this only supports pkcs5PBES2";
    +619 
    +620             // 2.2 pkcs5PBES2 param
    +621             var a0_0_1 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0[1]); 
    +622             if (a0_0.length != 2)
    +623                 throw "malformed format: SEQUENCE(0.0.1).items != 2: " + a0_0_1.length;
    +624 
    +625             // 2.2.1 encryptionScheme
    +626             var a0_0_1_1 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0_1[1]); 
    +627             if (a0_0_1_1.length != 2)
    +628                 throw "malformed format: SEQUENCE(0.0.1.1).items != 2: " + a0_0_1_1.length;
    +629             if (ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_1[0]) != "2a864886f70d0307")
    +630                 throw "this only supports TripleDES";
    +631             info.encryptionSchemeAlg = "TripleDES";
     632 
    -633             // 2. pkcs5PBES2
    -634             var a0_0 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0[0]); 
    -635             if (a0_0.length != 2)
    -636                 throw "malformed format: SEQUENCE(0.0).items != 2: " + a0_0.length;
    -637 
    -638             // 2.1 check if pkcs5PBES2(1 2 840 113549 1 5 13)
    -639             if (ASN1HEX.getHexOfV_AtObj(sHEX, a0_0[0]) != "2a864886f70d01050d")
    -640                 throw "this only supports pkcs5PBES2";
    -641 
    -642             // 2.2 pkcs5PBES2 param
    -643             var a0_0_1 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0[1]); 
    -644             if (a0_0.length != 2)
    -645                 throw "malformed format: SEQUENCE(0.0.1).items != 2: " + a0_0_1.length;
    -646 
    -647             // 2.2.1 encryptionScheme
    -648             var a0_0_1_1 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0_1[1]); 
    -649             if (a0_0_1_1.length != 2)
    -650                 throw "malformed format: SEQUENCE(0.0.1.1).items != 2: " + a0_0_1_1.length;
    -651             if (ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_1[0]) != "2a864886f70d0307")
    -652                 throw "this only supports TripleDES";
    -653             info.encryptionSchemeAlg = "TripleDES";
    -654 
    -655             // 2.2.1.1 IV of encryptionScheme
    -656             info.encryptionSchemeIV = ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_1[1]);
    -657 
    -658             // 2.2.2 keyDerivationFunc
    -659             var a0_0_1_0 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0_1[0]); 
    -660             if (a0_0_1_0.length != 2)
    -661                 throw "malformed format: SEQUENCE(0.0.1.0).items != 2: " + a0_0_1_0.length;
    -662             if (ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_0[0]) != "2a864886f70d01050c")
    -663                 throw "this only supports pkcs5PBKDF2";
    -664 
    -665             // 2.2.2.1 pkcs5PBKDF2 param
    -666             var a0_0_1_0_1 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0_1_0[1]); 
    -667             if (a0_0_1_0_1.length < 2)
    -668                 throw "malformed format: SEQUENCE(0.0.1.0.1).items < 2: " + a0_0_1_0_1.length;
    -669 
    -670             // 2.2.2.1.1 PBKDF2 salt
    -671             info.pbkdf2Salt = ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_0_1[0]);
    -672 
    -673             // 2.2.2.1.2 PBKDF2 iter
    -674             var iterNumHex = ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_0_1[1]);
    -675             try {
    -676                 info.pbkdf2Iter = parseInt(iterNumHex, 16);
    -677             } catch(ex) {
    -678                 throw "malformed format pbkdf2Iter: " + iterNumHex;
    -679             }
    -680 
    -681             return info;
    -682         },
    -683 
    -684         /**
    -685          * generate PBKDF2 key hexstring with specified passcode and information
    -686          * @name getPBKDF2KeyHexFromParam
    -687          * @memberOf KEYUTIL
    -688          * @function
    -689          * @param {Array} info result of {@link parseHexOfEncryptedPKCS8} which has preference of PKCS#8 file
    -690          * @param {String} passcode passcode to decrypto private key
    -691          * @return {String} hexadecimal string of PBKDF2 key
    -692          * @since pkcs5pkey 1.0.3
    -693          * @description
    -694          * As for info, this uses following properties:
    -695          * <ul>
    -696          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
    -697          * <li>info.pkbdf2Iter - iteration count</li>
    -698          * </ul>
    -699          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    -700          * <ul>
    -701          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    -702          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    -703          * </ul>
    -704          * @example
    -705          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    -706          * // key with PBKDF2 with TripleDES
    -707          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    -708          */
    -709         getPBKDF2KeyHexFromParam: function(info, passcode) {
    -710             var pbkdf2SaltWS = CryptoJS.enc.Hex.parse(info.pbkdf2Salt);
    -711             var pbkdf2Iter = info.pbkdf2Iter;
    -712             var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
    -713                                               pbkdf2SaltWS, 
    -714                                               { keySize: 192/32, iterations: pbkdf2Iter });
    -715             var pbkdf2KeyHex = CryptoJS.enc.Hex.stringify(pbkdf2KeyWS);
    -716             return pbkdf2KeyHex;
    -717         },
    -718 
    -719         /**
    -720          * read PEM formatted encrypted PKCS#8 private key and returns hexadecimal string of plain PKCS#8 private key
    -721          * @name getPlainPKCS8HexFromEncryptedPKCS8PEM
    -722          * @memberOf KEYUTIL
    -723          * @function
    -724          * @param {String} pkcs8PEM PEM formatted encrypted PKCS#8 private key
    -725          * @param {String} passcode passcode to decrypto private key
    -726          * @return {String} hexadecimal string of plain PKCS#8 private key
    -727          * @since pkcs5pkey 1.0.3
    -728          * @description
    -729          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    -730          * <ul>
    -731          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    -732          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    -733          * </ul>
    -734          * @example
    -735          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    -736          * // key with PBKDF2 with TripleDES
    -737          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    -738          */
    -739         getPlainPKCS8HexFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
    -740             // 1. derHex - PKCS#8 private key encrypted by PBKDF2
    -741             var derHex = this.getHexFromPEM(pkcs8PEM, "ENCRYPTED PRIVATE KEY");
    -742             // 2. info - PKCS#5 PBES info
    -743             var info = this.parseHexOfEncryptedPKCS8(derHex);
    -744             // 3. hKey - PBKDF2 key
    -745             var pbkdf2KeyHex = KEYUTIL.getPBKDF2KeyHexFromParam(info, passcode);
    -746             // 4. decrypt ciphertext by PBKDF2 key
    -747             var encrypted = {};
    -748             encrypted.ciphertext = CryptoJS.enc.Hex.parse(info.ciphertext);
    -749             var pbkdf2KeyWS = CryptoJS.enc.Hex.parse(pbkdf2KeyHex);
    -750             var des3IVWS = CryptoJS.enc.Hex.parse(info.encryptionSchemeIV);
    -751             var decWS = CryptoJS.TripleDES.decrypt(encrypted, pbkdf2KeyWS, { iv: des3IVWS });
    -752             var decHex = CryptoJS.enc.Hex.stringify(decWS);
    -753             return decHex;
    -754         },
    -755 
    -756         /**
    -757          * (DEPRECATED) read PEM formatted encrypted PKCS#8 private key and returns RSAKey object
    -758          * @name getRSAKeyFromEncryptedPKCS8PEM
    -759          * @memberOf KEYUTIL
    -760          * @function
    -761          * @param {String} pkcs8PEM PEM formatted encrypted PKCS#8 private key
    -762          * @param {String} passcode passcode to decrypto private key
    -763          * @return {RSAKey} loaded RSAKey object of RSA private key
    -764          * @since pkcs5pkey 1.0.3
    -765          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -766          * @description
    -767          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    -768          * <ul>
    -769          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    -770          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    -771          * </ul>
    -772          * @example
    -773          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    -774          * // key with PBKDF2 with TripleDES
    -775          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    -776          */
    -777         getRSAKeyFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
    -778             var prvKeyHex = this.getPlainPKCS8HexFromEncryptedPKCS8PEM(pkcs8PEM, passcode);
    -779             var rsaKey = this.getRSAKeyFromPlainPKCS8Hex(prvKeyHex);
    -780             return rsaKey;
    -781         },
    -782 
    -783         /**
    -784          * get RSAKey/ECDSA private key object from encrypted PEM PKCS#8 private key
    -785          * @name getKeyFromEncryptedPKCS8PEM
    -786          * @memberOf KEYUTIL
    -787          * @function
    -788          * @param {String} pkcs8PEM string of PEM formatted PKCS#8 private key
    -789          * @param {String} passcode passcode string to decrypt key
    -790          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    -791          * @since pkcs5pkey 1.0.5
    +633             // 2.2.1.1 IV of encryptionScheme
    +634             info.encryptionSchemeIV = ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_1[1]);
    +635 
    +636             // 2.2.2 keyDerivationFunc
    +637             var a0_0_1_0 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0_1[0]); 
    +638             if (a0_0_1_0.length != 2)
    +639                 throw "malformed format: SEQUENCE(0.0.1.0).items != 2: " + a0_0_1_0.length;
    +640             if (ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_0[0]) != "2a864886f70d01050c")
    +641                 throw "this only supports pkcs5PBKDF2";
    +642 
    +643             // 2.2.2.1 pkcs5PBKDF2 param
    +644             var a0_0_1_0_1 = ASN1HEX.getPosArrayOfChildren_AtObj(sHEX, a0_0_1_0[1]); 
    +645             if (a0_0_1_0_1.length < 2)
    +646                 throw "malformed format: SEQUENCE(0.0.1.0.1).items < 2: " + a0_0_1_0_1.length;
    +647 
    +648             // 2.2.2.1.1 PBKDF2 salt
    +649             info.pbkdf2Salt = ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_0_1[0]);
    +650 
    +651             // 2.2.2.1.2 PBKDF2 iter
    +652             var iterNumHex = ASN1HEX.getHexOfV_AtObj(sHEX, a0_0_1_0_1[1]);
    +653             try {
    +654                 info.pbkdf2Iter = parseInt(iterNumHex, 16);
    +655             } catch(ex) {
    +656                 throw "malformed format pbkdf2Iter: " + iterNumHex;
    +657             }
    +658 
    +659             return info;
    +660         },
    +661 
    +662         /**
    +663          * generate PBKDF2 key hexstring with specified passcode and information
    +664          * @name getPBKDF2KeyHexFromParam
    +665          * @memberOf KEYUTIL
    +666          * @function
    +667          * @param {Array} info result of {@link parseHexOfEncryptedPKCS8} which has preference of PKCS#8 file
    +668          * @param {String} passcode passcode to decrypto private key
    +669          * @return {String} hexadecimal string of PBKDF2 key
    +670          * @since pkcs5pkey 1.0.3
    +671          * @description
    +672          * As for info, this uses following properties:
    +673          * <ul>
    +674          * <li>info.pbkdf2Salt - hexadecimal string of PBKDF2 salt</li>
    +675          * <li>info.pkbdf2Iter - iteration count</li>
    +676          * </ul>
    +677          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    +678          * <ul>
    +679          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    +680          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    +681          * </ul>
    +682          * @example
    +683          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    +684          * // key with PBKDF2 with TripleDES
    +685          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    +686          */
    +687         getPBKDF2KeyHexFromParam: function(info, passcode) {
    +688             var pbkdf2SaltWS = CryptoJS.enc.Hex.parse(info.pbkdf2Salt);
    +689             var pbkdf2Iter = info.pbkdf2Iter;
    +690             var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
    +691                                               pbkdf2SaltWS, 
    +692                                               { keySize: 192/32, iterations: pbkdf2Iter });
    +693             var pbkdf2KeyHex = CryptoJS.enc.Hex.stringify(pbkdf2KeyWS);
    +694             return pbkdf2KeyHex;
    +695         },
    +696 
    +697         /**
    +698          * read PEM formatted encrypted PKCS#8 private key and returns hexadecimal string of plain PKCS#8 private key
    +699          * @name getPlainPKCS8HexFromEncryptedPKCS8PEM
    +700          * @memberOf KEYUTIL
    +701          * @function
    +702          * @param {String} pkcs8PEM PEM formatted encrypted PKCS#8 private key
    +703          * @param {String} passcode passcode to decrypto private key
    +704          * @return {String} hexadecimal string of plain PKCS#8 private key
    +705          * @since pkcs5pkey 1.0.3
    +706          * @description
    +707          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    +708          * <ul>
    +709          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    +710          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    +711          * </ul>
    +712          * @example
    +713          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    +714          * // key with PBKDF2 with TripleDES
    +715          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    +716          */
    +717         getPlainPKCS8HexFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
    +718             // 1. derHex - PKCS#8 private key encrypted by PBKDF2
    +719             var derHex = ASN1HEX.pemToHex(pkcs8PEM, "ENCRYPTED PRIVATE KEY");
    +720             // 2. info - PKCS#5 PBES info
    +721             var info = this.parseHexOfEncryptedPKCS8(derHex);
    +722             // 3. hKey - PBKDF2 key
    +723             var pbkdf2KeyHex = KEYUTIL.getPBKDF2KeyHexFromParam(info, passcode);
    +724             // 4. decrypt ciphertext by PBKDF2 key
    +725             var encrypted = {};
    +726             encrypted.ciphertext = CryptoJS.enc.Hex.parse(info.ciphertext);
    +727             var pbkdf2KeyWS = CryptoJS.enc.Hex.parse(pbkdf2KeyHex);
    +728             var des3IVWS = CryptoJS.enc.Hex.parse(info.encryptionSchemeIV);
    +729             var decWS = CryptoJS.TripleDES.decrypt(encrypted, pbkdf2KeyWS, { iv: des3IVWS });
    +730             var decHex = CryptoJS.enc.Hex.stringify(decWS);
    +731             return decHex;
    +732         },
    +733 
    +734         /**
    +735          * (DEPRECATED) read PEM formatted encrypted PKCS#8 private key and returns RSAKey object
    +736          * @name getRSAKeyFromEncryptedPKCS8PEM
    +737          * @memberOf KEYUTIL
    +738          * @function
    +739          * @param {String} pkcs8PEM PEM formatted encrypted PKCS#8 private key
    +740          * @param {String} passcode passcode to decrypto private key
    +741          * @return {RSAKey} loaded RSAKey object of RSA private key
    +742          * @since pkcs5pkey 1.0.3
    +743          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +744          * @description
    +745          * Currently, this method only supports PKCS#5v2.0 with PBES2/PBDKF2 of HmacSHA1 and TripleDES.
    +746          * <ul>
    +747          * <li>keyDerivationFunc = pkcs5PBKDF2 with HmacSHA1</li>
    +748          * <li>encryptionScheme = des-EDE3-CBC(i.e. TripleDES</li>
    +749          * </ul>
    +750          * @example
    +751          * // to convert plain PKCS#5 private key to encrypted PKCS#8 private
    +752          * // key with PBKDF2 with TripleDES
    +753          * % openssl pkcs8 -in plain_p5.pem -topk8 -v2 -des3 -out encrypted_p8.pem
    +754          */
    +755         getRSAKeyFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
    +756             var prvKeyHex = this.getPlainPKCS8HexFromEncryptedPKCS8PEM(pkcs8PEM, passcode);
    +757             var rsaKey = this.getRSAKeyFromPlainPKCS8Hex(prvKeyHex);
    +758             return rsaKey;
    +759         },
    +760 
    +761         /**
    +762          * get RSAKey/ECDSA private key object from encrypted PEM PKCS#8 private key
    +763          * @name getKeyFromEncryptedPKCS8PEM
    +764          * @memberOf KEYUTIL
    +765          * @function
    +766          * @param {String} pkcs8PEM string of PEM formatted PKCS#8 private key
    +767          * @param {String} passcode passcode string to decrypt key
    +768          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    +769          * @since pkcs5pkey 1.0.5
    +770          */
    +771         getKeyFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
    +772             var prvKeyHex = this.getPlainPKCS8HexFromEncryptedPKCS8PEM(pkcs8PEM, passcode);
    +773             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
    +774             return key;
    +775         },
    +776 
    +777         /**
    +778          * parse hexadecimal string of plain PKCS#8 private key
    +779          * @name parsePlainPrivatePKCS8Hex
    +780          * @memberOf KEYUTIL
    +781          * @function
    +782          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 plain private key
    +783          * @return {Array} associative array of parsed key
    +784          * @since pkcs5pkey 1.0.5
    +785          * @description
    +786          * Resulted associative array has following properties:
    +787          * <ul>
    +788          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
    +789          * <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
    +790          * <li>keyidx - string starting index of key in pkcs8PrvHex</li>
    +791          * </ul>
     792          */
    -793         getKeyFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) {
    -794             var prvKeyHex = this.getPlainPKCS8HexFromEncryptedPKCS8PEM(pkcs8PEM, passcode);
    -795             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
    -796             return key;
    -797         },
    -798 
    -799         /**
    -800          * parse hexadecimal string of plain PKCS#8 private key
    -801          * @name parsePlainPrivatePKCS8Hex
    -802          * @memberOf KEYUTIL
    -803          * @function
    -804          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 plain private key
    -805          * @return {Array} associative array of parsed key
    -806          * @since pkcs5pkey 1.0.5
    -807          * @description
    -808          * Resulted associative array has following properties:
    -809          * <ul>
    -810          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
    -811          * <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
    -812          * <li>keyidx - string starting index of key in pkcs8PrvHex</li>
    -813          * </ul>
    -814          */
    -815         parsePlainPrivatePKCS8Hex: function(pkcs8PrvHex) {
    -816             var result = {};
    -817             result.algparam = null;
    +793         parsePlainPrivatePKCS8Hex: function(pkcs8PrvHex) {
    +794             var result = {};
    +795             result.algparam = null;
    +796 
    +797             // 1. sequence
    +798             if (pkcs8PrvHex.substr(0, 2) != "30")
    +799                 throw "malformed plain PKCS8 private key(code:001)"; // not sequence
    +800 
    +801             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, 0);
    +802             if (a1.length != 3)
    +803                 throw "malformed plain PKCS8 private key(code:002)";
    +804 
    +805             // 2. AlgID
    +806             if (pkcs8PrvHex.substr(a1[1], 2) != "30")
    +807                 throw "malformed PKCS8 private key(code:003)"; // AlgId not sequence
    +808 
    +809             var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, a1[1]);
    +810             if (a2.length != 2)
    +811                 throw "malformed PKCS8 private key(code:004)"; // AlgId not have two elements
    +812 
    +813             // 2.1. AlgID OID
    +814             if (pkcs8PrvHex.substr(a2[0], 2) != "06")
    +815                 throw "malformed PKCS8 private key(code:005)"; // AlgId.oid is not OID
    +816 
    +817             result.algoid = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a2[0]);
     818 
    -819             // 1. sequence
    -820             if (pkcs8PrvHex.substr(0, 2) != "30")
    -821                 throw "malformed plain PKCS8 private key(code:001)"; // not sequence
    -822 
    -823             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, 0);
    -824             if (a1.length != 3)
    -825                 throw "malformed plain PKCS8 private key(code:002)";
    -826 
    -827             // 2. AlgID
    -828             if (pkcs8PrvHex.substr(a1[1], 2) != "30")
    -829                 throw "malformed PKCS8 private key(code:003)"; // AlgId not sequence
    -830 
    -831             var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, a1[1]);
    -832             if (a2.length != 2)
    -833                 throw "malformed PKCS8 private key(code:004)"; // AlgId not have two elements
    -834 
    -835             // 2.1. AlgID OID
    -836             if (pkcs8PrvHex.substr(a2[0], 2) != "06")
    -837                 throw "malformed PKCS8 private key(code:005)"; // AlgId.oid is not OID
    -838 
    -839             result.algoid = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a2[0]);
    -840 
    -841             // 2.2. AlgID param
    -842             if (pkcs8PrvHex.substr(a2[1], 2) == "06") {
    -843                 result.algparam = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a2[1]);
    -844             }
    -845 
    -846             // 3. Key index
    -847             if (pkcs8PrvHex.substr(a1[2], 2) != "04")
    -848                 throw "malformed PKCS8 private key(code:006)"; // not octet string
    -849 
    -850             result.keyidx = ASN1HEX.getStartPosOfV_AtObj(pkcs8PrvHex, a1[2]);
    -851 
    -852             return result;
    -853         },
    -854 
    -855         /**
    -856          * get RSAKey/ECDSA private key object from PEM plain PEM PKCS#8 private key
    -857          * @name getKeyFromPlainPrivatePKCS8PEM
    -858          * @memberOf KEYUTIL
    -859          * @function
    -860          * @param {String} pkcs8PEM string of plain PEM formatted PKCS#8 private key
    -861          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    -862          * @since pkcs5pkey 1.0.5
    -863          */
    -864         getKeyFromPlainPrivatePKCS8PEM: function(prvKeyPEM) {
    -865             var prvKeyHex = this.getHexFromPEM(prvKeyPEM, "PRIVATE KEY");
    -866             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
    -867             return key;
    -868         },
    -869 
    -870         /**
    -871          * get RSAKey/ECDSA private key object from HEX plain PEM PKCS#8 private key
    -872          * @name getKeyFromPlainPrivatePKCS8Hex
    -873          * @memberOf KEYUTIL
    -874          * @function
    -875          * @param {String} prvKeyHex hexadecimal string of plain PKCS#8 private key
    -876          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    -877          * @since pkcs5pkey 1.0.5
    -878          */
    -879         getKeyFromPlainPrivatePKCS8Hex: function(prvKeyHex) {
    -880             var p8 = this.parsePlainPrivatePKCS8Hex(prvKeyHex);
    -881             
    -882             if (p8.algoid == "2a864886f70d010101") { // RSA
    -883                 this.parsePrivateRawRSAKeyHexAtObj(prvKeyHex, p8);
    -884                 var k = p8.key;
    -885                 var key = new RSAKey();
    -886                 key.setPrivateEx(k.n, k.e, k.d, k.p, k.q, k.dp, k.dq, k.co);
    -887                 return key;
    -888             } else if (p8.algoid == "2a8648ce3d0201") { // ECC
    -889                 this.parsePrivateRawECKeyHexAtObj(prvKeyHex, p8);
    -890                 if (KJUR.crypto.OID.oidhex2name[p8.algparam] === undefined)
    -891                     throw "KJUR.crypto.OID.oidhex2name undefined: " + p8.algparam;
    -892                 var curveName = KJUR.crypto.OID.oidhex2name[p8.algparam];
    -893                 var key = new KJUR.crypto.ECDSA({'curve': curveName});
    -894                 key.setPublicKeyHex(p8.pubkey);
    -895                 key.setPrivateKeyHex(p8.key);
    -896                 key.isPublic = false;
    -897                 return key;
    -898             } else if (p8.algoid == "2a8648ce380401") { // DSA
    -899                 var hP = ASN1HEX.getVbyList(prvKeyHex, 0, [1,1,0], "02");
    -900                 var hQ = ASN1HEX.getVbyList(prvKeyHex, 0, [1,1,1], "02");
    -901                 var hG = ASN1HEX.getVbyList(prvKeyHex, 0, [1,1,2], "02");
    -902                 var hX = ASN1HEX.getVbyList(prvKeyHex, 0, [2,0], "02");
    -903                 var biP = new BigInteger(hP, 16);
    -904                 var biQ = new BigInteger(hQ, 16);
    -905                 var biG = new BigInteger(hG, 16);
    -906                 var biX = new BigInteger(hX, 16);
    -907                 var key = new KJUR.crypto.DSA();
    -908                 key.setPrivate(biP, biQ, biG, null, biX);
    -909                 return key;
    -910             } else {
    -911                 throw "unsupported private key algorithm";
    -912             }
    -913         },
    -914 
    -915         // === PKCS8 RSA Public Key ================================================
    -916         /**
    -917          * (DEPRECATED) read PEM formatted PKCS#8 public key and returns RSAKey object
    -918          * @name getRSAKeyFromPublicPKCS8PEM
    -919          * @memberOf KEYUTIL
    -920          * @function
    -921          * @param {String} pkcs8PubPEM PEM formatted PKCS#8 public key
    -922          * @return {RSAKey} loaded RSAKey object of RSA public key
    -923          * @since pkcs5pkey 1.0.4
    -924          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -925          */
    -926         getRSAKeyFromPublicPKCS8PEM: function(pkcs8PubPEM) {
    -927             var pubKeyHex = this.getHexFromPEM(pkcs8PubPEM, "PUBLIC KEY");
    -928             var rsaKey = this.getRSAKeyFromPublicPKCS8Hex(pubKeyHex);
    -929             return rsaKey;
    -930         },
    -931 
    -932         /**
    -933          * (DEPRECATED) get RSAKey/ECDSA public key object from PEM PKCS#8 public key
    -934          * @name getKeyFromPublicPKCS8PEM
    -935          * @memberOf KEYUTIL
    -936          * @function
    -937          * @param {String} pkcsPub8PEM string of PEM formatted PKCS#8 public key
    -938          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    -939          * @since pkcs5pkey 1.0.5
    -940          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -941          */
    -942         getKeyFromPublicPKCS8PEM: function(pkcs8PubPEM) {
    -943             var pubKeyHex = this.getHexFromPEM(pkcs8PubPEM, "PUBLIC KEY");
    -944             var key = this.getKeyFromPublicPKCS8Hex(pubKeyHex);
    -945             return key;
    -946         },
    -947 
    -948         /**
    -949          * (DEPRECATED) get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#8 public key
    -950          * @name getKeyFromPublicPKCS8Hex
    -951          * @memberOf KEYUTIL
    -952          * @function
    -953          * @param {String} pkcsPub8Hex hexadecimal string of PKCS#8 public key
    -954          * @return {Object} RSAKey or KJUR.crypto.{ECDSA,DSA} private key object
    -955          * @since pkcs5pkey 1.0.5
    -956          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -957          */
    -958         getKeyFromPublicPKCS8Hex: function(pkcs8PubHex) {
    -959             var p8 = this.parsePublicPKCS8Hex(pkcs8PubHex);
    -960             
    -961             if (p8.algoid == "2a864886f70d010101") { // RSA
    -962                 var aRSA = this.parsePublicRawRSAKeyHex(p8.key);
    -963                 var key = new RSAKey();
    -964                 key.setPublic(aRSA.n, aRSA.e);
    -965                 return key;
    -966             } else if (p8.algoid == "2a8648ce3d0201") { // ECC
    -967                 if (KJUR.crypto.OID.oidhex2name[p8.algparam] === undefined)
    -968                     throw "KJUR.crypto.OID.oidhex2name undefined: " + p8.algparam;
    -969                 var curveName = KJUR.crypto.OID.oidhex2name[p8.algparam];
    -970                 var key = new KJUR.crypto.ECDSA({'curve': curveName, 'pub': p8.key});
    -971                 return key;
    -972             } else if (p8.algoid == "2a8648ce380401") { // DSA 1.2.840.10040.4.1
    -973                 var param = p8.algparam;
    -974                 var y = ASN1HEX.getHexOfV_AtObj(p8.key, 0);
    -975                 var key = new KJUR.crypto.DSA();
    -976                 key.setPublic(new BigInteger(param.p, 16),
    -977                               new BigInteger(param.q, 16),
    -978                               new BigInteger(param.g, 16),
    -979                               new BigInteger(y, 16));
    -980                 return key;
    -981             } else {
    -982                 throw "unsupported public key algorithm";
    -983             }
    -984         },
    -985 
    -986         /**
    -987          * parse hexadecimal string of plain PKCS#8 private key
    -988          * @name parsePublicRawRSAKeyHex
    -989          * @memberOf KEYUTIL
    -990          * @function
    -991          * @param {String} pubRawRSAHex hexadecimal string of ASN.1 encoded PKCS#8 public key
    -992          * @return {Array} associative array of parsed key
    -993          * @since pkcs5pkey 1.0.5
    -994          * @description
    -995          * Resulted associative array has following properties:
    -996          * <ul>
    -997          * <li>n - hexadecimal string of public key
    -998          * <li>e - hexadecimal string of public exponent
    -999          * </ul>
    -1000          */
    -1001         parsePublicRawRSAKeyHex: function(pubRawRSAHex) {
    -1002             var result = {};
    -1003             
    -1004             // 1. Sequence
    -1005             if (pubRawRSAHex.substr(0, 2) != "30")
    -1006                 throw "malformed RSA key(code:001)"; // not sequence
    -1007             
    -1008             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pubRawRSAHex, 0);
    -1009             if (a1.length != 2)
    -1010                 throw "malformed RSA key(code:002)"; // not 2 items in seq
    -1011 
    -1012             // 2. public key "N"
    -1013             if (pubRawRSAHex.substr(a1[0], 2) != "02")
    -1014                 throw "malformed RSA key(code:003)"; // 1st item is not integer
    -1015 
    -1016             result.n = ASN1HEX.getHexOfV_AtObj(pubRawRSAHex, a1[0]);
    -1017 
    -1018             // 3. public key "E"
    -1019             if (pubRawRSAHex.substr(a1[1], 2) != "02")
    -1020                 throw "malformed RSA key(code:004)"; // 2nd item is not integer
    -1021 
    -1022             result.e = ASN1HEX.getHexOfV_AtObj(pubRawRSAHex, a1[1]);
    -1023 
    -1024             return result;
    -1025         },
    -1026 
    -1027         /**
    -1028          * parse hexadecimal string of RSA private key
    -1029          * @name parsePrivateRawRSAKeyHexAtObj
    -1030          * @memberOf KEYUTIL
    -1031          * @function
    -1032          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 private key concluding RSA private key
    -1033          * @return {Array} info associative array to add parsed RSA private key information
    -1034          * @since pkcs5pkey 1.0.5
    -1035          * @description
    -1036          * Following properties are added to associative array 'info'
    -1037          * <ul>
    -1038          * <li>n - hexadecimal string of public key
    -1039          * <li>e - hexadecimal string of public exponent
    -1040          * <li>d - hexadecimal string of private key
    -1041          * <li>p - hexadecimal string
    -1042          * <li>q - hexadecimal string
    -1043          * <li>dp - hexadecimal string
    -1044          * <li>dq - hexadecimal string
    -1045          * <li>co - hexadecimal string
    -1046          * </ul>
    -1047          */
    -1048         parsePrivateRawRSAKeyHexAtObj: function(pkcs8PrvHex, info) {
    -1049             var keyIdx = info.keyidx;
    -1050             
    -1051             // 1. sequence
    -1052             if (pkcs8PrvHex.substr(keyIdx, 2) != "30")
    -1053                 throw "malformed RSA private key(code:001)"; // not sequence
    -1054 
    -1055             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, keyIdx);
    -1056             if (a1.length != 9)
    -1057                 throw "malformed RSA private key(code:002)"; // not sequence
    -1058 
    -1059             // 2. RSA key
    -1060             info.key = {};
    -1061             info.key.n = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[1]);
    -1062             info.key.e = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[2]);
    -1063             info.key.d = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[3]);
    -1064             info.key.p = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[4]);
    -1065             info.key.q = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[5]);
    -1066             info.key.dp = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[6]);
    -1067             info.key.dq = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[7]);
    -1068             info.key.co = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[8]);
    -1069         },
    -1070 
    -1071         /**
    -1072          * parse hexadecimal string of ECC private key
    -1073          * @name parsePrivateRawECKeyHexAtObj
    -1074          * @memberOf KEYUTIL
    -1075          * @function
    -1076          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 private key concluding EC private key
    -1077          * @return {Array} info associative array to add parsed ECC private key information
    -1078          * @since pkcs5pkey 1.0.5
    -1079          * @description
    -1080          * Following properties are added to associative array 'info'
    -1081          * <ul>
    -1082          * <li>key - hexadecimal string of ECC private key
    -1083          * </ul>
    -1084          */
    -1085         parsePrivateRawECKeyHexAtObj: function(pkcs8PrvHex, info) {
    -1086             var keyIdx = info.keyidx;
    -1087             
    -1088             var key = ASN1HEX.getVbyList(pkcs8PrvHex, keyIdx, [1], "04");
    -1089             var pubkey = ASN1HEX.getVbyList(pkcs8PrvHex, keyIdx, [2,0], "03").substr(2);
    -1090 
    -1091             info.key = key;
    -1092             info.pubkey = pubkey;
    -1093         },
    +819             // 2.2. AlgID param
    +820             if (pkcs8PrvHex.substr(a2[1], 2) == "06") {
    +821                 result.algparam = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a2[1]);
    +822             }
    +823 
    +824             // 3. Key index
    +825             if (pkcs8PrvHex.substr(a1[2], 2) != "04")
    +826                 throw "malformed PKCS8 private key(code:006)"; // not octet string
    +827 
    +828             result.keyidx = ASN1HEX.getStartPosOfV_AtObj(pkcs8PrvHex, a1[2]);
    +829 
    +830             return result;
    +831         },
    +832 
    +833         /**
    +834          * get RSAKey/ECDSA private key object from PEM plain PEM PKCS#8 private key
    +835          * @name getKeyFromPlainPrivatePKCS8PEM
    +836          * @memberOf KEYUTIL
    +837          * @function
    +838          * @param {String} pkcs8PEM string of plain PEM formatted PKCS#8 private key
    +839          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    +840          * @since pkcs5pkey 1.0.5
    +841          */
    +842         getKeyFromPlainPrivatePKCS8PEM: function(prvKeyPEM) {
    +843             var prvKeyHex = ASN1HEX.pemToHex(prvKeyPEM, "PRIVATE KEY");
    +844             var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex);
    +845             return key;
    +846         },
    +847 
    +848         /**
    +849          * get RSAKey/DSA/ECDSA private key object from HEX plain PEM PKCS#8 private key
    +850          * @name getKeyFromPlainPrivatePKCS8Hex
    +851          * @memberOf KEYUTIL
    +852          * @function
    +853          * @param {String} prvKeyHex hexadecimal string of plain PKCS#8 private key
    +854          * @return {Object} RSAKey or KJUR.crypto.{DSA,ECDSA} private key object
    +855          * @since pkcs5pkey 1.0.5
    +856          */
    +857         getKeyFromPlainPrivatePKCS8Hex: function(prvKeyHex) {
    +858             var p8 = this.parsePlainPrivatePKCS8Hex(prvKeyHex);
    +859 	    var key;
    +860             
    +861             if (p8.algoid == "2a864886f70d010101") { // RSA
    +862 		key = new RSAKey();
    +863 	    } else if (p8.algoid == "2a8648ce380401") { // DSA
    +864 		key = new KJUR.crypto.DSA();
    +865             } else if (p8.algoid == "2a8648ce3d0201") { // ECC
    +866                 key = new KJUR.crypto.ECDSA();
    +867             } else {
    +868                 throw "unsupported private key algorithm";
    +869             }
    +870 
    +871 	    key.readPKCS8PrvKeyHex(prvKeyHex);
    +872 	    return key;
    +873         },
    +874 
    +875         // === PKCS8 RSA Public Key ================================================
    +876         /**
    +877          * (DEPRECATED) read PEM formatted PKCS#8 public key and returns RSAKey object
    +878          * @name getRSAKeyFromPublicPKCS8PEM
    +879          * @memberOf KEYUTIL
    +880          * @function
    +881          * @param {String} pkcs8PubPEM PEM formatted PKCS#8 public key
    +882          * @return {RSAKey} loaded RSAKey object of RSA public key
    +883          * @since pkcs5pkey 1.0.4
    +884          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +885          */
    +886         getRSAKeyFromPublicPKCS8PEM: function(pkcs8PubPEM) {
    +887             var pubKeyHex = ASN1HEX.pemToHex(pkcs8PubPEM, "PUBLIC KEY");
    +888             var rsaKey = this.getRSAKeyFromPublicPKCS8Hex(pubKeyHex);
    +889             return rsaKey;
    +890         },
    +891 
    +892         /**
    +893          * (DEPRECATED) get RSAKey/ECDSA public key object from PEM PKCS#8 public key
    +894          * @name getKeyFromPublicPKCS8PEM
    +895          * @memberOf KEYUTIL
    +896          * @function
    +897          * @param {String} pkcsPub8PEM string of PEM formatted PKCS#8 public key
    +898          * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object
    +899          * @since pkcs5pkey 1.0.5
    +900          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +901          */
    +902         getKeyFromPublicPKCS8PEM: function(pkcs8PubPEM) {
    +903             var pubKeyHex = ASN1HEX.pemToHex(pkcs8PubPEM, "PUBLIC KEY");
    +904             var key = this.getKeyFromPublicPKCS8Hex(pubKeyHex);
    +905             return key;
    +906         },
    +907 
    +908         /**
    +909          * (DEPRECATED) get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#8 public key
    +910          * @name getKeyFromPublicPKCS8Hex
    +911          * @memberOf KEYUTIL
    +912          * @function
    +913          * @param {String} pkcsPub8Hex hexadecimal string of PKCS#8 public key
    +914          * @return {Object} RSAKey or KJUR.crypto.{ECDSA,DSA} private key object
    +915          * @since pkcs5pkey 1.0.5
    +916          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +917          */
    +918         getKeyFromPublicPKCS8Hex: function(h) {
    +919 	    var key;
    +920 	    var hOID = ASN1HEX.getVbyList(h, 0, [0, 0], "06");
    +921 
    +922 	    if (hOID === "2a864886f70d010101") {    // oid=RSA
    +923 		key = new RSAKey();
    +924 	    } else if (hOID === "2a8648ce380401") { // oid=DSA
    +925 		key = new KJUR.crypto.DSA();
    +926 	    } else if (hOID === "2a8648ce3d0201") { // oid=ECPUB
    +927 		key = new KJUR.crypto.ECDSA();
    +928 	    } else {
    +929 		throw "unsupported PKCS#8 public key hex";
    +930 	    }
    +931 	    key.readPKCS8PubKeyHex(h);
    +932 	    return key;
    +933 	},
    +934 
    +935         /**
    +936          * parse hexadecimal string of plain PKCS#8 private key
    +937          * @name parsePublicRawRSAKeyHex
    +938          * @memberOf KEYUTIL
    +939          * @function
    +940          * @param {String} pubRawRSAHex hexadecimal string of ASN.1 encoded PKCS#8 public key
    +941          * @return {Array} associative array of parsed key
    +942          * @since pkcs5pkey 1.0.5
    +943          * @description
    +944          * Resulted associative array has following properties:
    +945          * <ul>
    +946          * <li>n - hexadecimal string of public key
    +947          * <li>e - hexadecimal string of public exponent
    +948          * </ul>
    +949          */
    +950         parsePublicRawRSAKeyHex: function(pubRawRSAHex) {
    +951             var result = {};
    +952             
    +953             // 1. Sequence
    +954             if (pubRawRSAHex.substr(0, 2) != "30")
    +955                 throw "malformed RSA key(code:001)"; // not sequence
    +956             
    +957             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pubRawRSAHex, 0);
    +958             if (a1.length != 2)
    +959                 throw "malformed RSA key(code:002)"; // not 2 items in seq
    +960 
    +961             // 2. public key "N"
    +962             if (pubRawRSAHex.substr(a1[0], 2) != "02")
    +963                 throw "malformed RSA key(code:003)"; // 1st item is not integer
    +964 
    +965             result.n = ASN1HEX.getHexOfV_AtObj(pubRawRSAHex, a1[0]);
    +966 
    +967             // 3. public key "E"
    +968             if (pubRawRSAHex.substr(a1[1], 2) != "02")
    +969                 throw "malformed RSA key(code:004)"; // 2nd item is not integer
    +970 
    +971             result.e = ASN1HEX.getHexOfV_AtObj(pubRawRSAHex, a1[1]);
    +972 
    +973             return result;
    +974         },
    +975 
    +976         /**
    +977          * parse hexadecimal string of RSA private key
    +978          * @name parsePrivateRawRSAKeyHexAtObj
    +979          * @memberOf KEYUTIL
    +980          * @function
    +981          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 private key concluding RSA private key
    +982          * @return {Array} info associative array to add parsed RSA private key information
    +983          * @since pkcs5pkey 1.0.5
    +984 	 * @deprecated since jsrsasign 7.1.0 keyutil 1.1.0
    +985          * @description
    +986          * Following properties are added to associative array 'info'
    +987          * <ul>
    +988          * <li>n - hexadecimal string of public key
    +989          * <li>e - hexadecimal string of public exponent
    +990          * <li>d - hexadecimal string of private key
    +991          * <li>p - hexadecimal string
    +992          * <li>q - hexadecimal string
    +993          * <li>dp - hexadecimal string
    +994          * <li>dq - hexadecimal string
    +995          * <li>co - hexadecimal string
    +996          * </ul>
    +997          */
    +998         parsePrivateRawRSAKeyHexAtObj: function(pkcs8PrvHex, info) {
    +999 	    var _ASN1HEX = ASN1HEX;
    +1000 	    var _getV = _ASN1HEX.getHexOfV_AtObj;
    +1001 
    +1002 	    var idxSeq = _ASN1HEX.getDecendantIndexByNthList(pkcs8PrvHex, 0, [2, 0]);
    +1003 	    var a = _ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, idxSeq);
    +1004 	    
    +1005 	    if (a.length !== 9) throw "malformed PKCS#8 plain RSA private key";
    +1006 
    +1007             // 2. RSA key
    +1008             info.key = {};
    +1009             info.key.n  = _getV(pkcs8PrvHex, a[1]);
    +1010             info.key.e  = _getV(pkcs8PrvHex, a[2]);
    +1011             info.key.d  = _getV(pkcs8PrvHex, a[3]);
    +1012             info.key.p  = _getV(pkcs8PrvHex, a[4]);
    +1013             info.key.q  = _getV(pkcs8PrvHex, a[5]);
    +1014             info.key.dp = _getV(pkcs8PrvHex, a[6]);
    +1015             info.key.dq = _getV(pkcs8PrvHex, a[7]);
    +1016             info.key.co = _getV(pkcs8PrvHex, a[8]);
    +1017         },
    +1018 
    +1019         /**
    +1020          * parse hexadecimal string of ECC private key
    +1021          * @name parsePrivateRawECKeyHexAtObj
    +1022          * @memberOf KEYUTIL
    +1023          * @function
    +1024          * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 private key concluding EC private key
    +1025          * @return {Array} info associative array to add parsed ECC private key information
    +1026          * @since pkcs5pkey 1.0.5
    +1027 	 * @deprecated since jsrsasign 7.1.0 keyutil 1.1.0
    +1028          * @description
    +1029          * Following properties are added to associative array 'info'
    +1030          * <ul>
    +1031          * <li>key - hexadecimal string of ECC private key
    +1032          * </ul>
    +1033          */
    +1034         parsePrivateRawECKeyHexAtObj: function(pkcs8PrvHex, info) {
    +1035 	    var _ASN1HEX = ASN1HEX;
    +1036 
    +1037             var keyIdx = info.keyidx;
    +1038 
    +1039 	    var ec = new KJUR.crypto.ECDSA();
    +1040 	    ec.readPKCS8PrvKeyHex(pkcs8PrvHex);
    +1041 	    
    +1042             info.key = ec.prvKeyHex;
    +1043 	    info.pubkey = ec.pubKeyHex;
    +1044         },
    +1045 
    +1046         /**
    +1047          * parse hexadecimal string of PKCS#8 RSA/EC/DSA public key
    +1048          * @name parsePublicPKCS8Hex
    +1049          * @memberOf KEYUTIL
    +1050          * @function
    +1051          * @param {String} pkcs8PubHex hexadecimal string of PKCS#8 public key
    +1052          * @return {Hash} hash of key information
    +1053          * @description
    +1054          * Resulted hash has following attributes.
    +1055          * <ul>
    +1056          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
    +1057          * <li>algparam - hexadecimal string of OID of ECC curve name, parameter SEQUENCE of DSA or null</li>
    +1058          * <li>key - hexadecimal string of public key</li>
    +1059          * </ul>
    +1060          */
    +1061         parsePublicPKCS8Hex: function(pkcs8PubHex) {
    +1062             var result = {};
    +1063             result.algparam = null;
    +1064 
    +1065             // 1. AlgID and Key bit string
    +1066             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, 0);
    +1067             if (a1.length != 2)
    +1068                 throw "outer DERSequence shall have 2 elements: " + a1.length;
    +1069 
    +1070             // 2. AlgID
    +1071             var idxAlgIdTLV = a1[0];
    +1072             if (pkcs8PubHex.substr(idxAlgIdTLV, 2) != "30")
    +1073                 throw "malformed PKCS8 public key(code:001)"; // AlgId not sequence
    +1074 
    +1075             var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, idxAlgIdTLV);
    +1076             if (a2.length != 2)
    +1077                 throw "malformed PKCS8 public key(code:002)"; // AlgId not have two elements
    +1078 
    +1079             // 2.1. AlgID OID
    +1080             if (pkcs8PubHex.substr(a2[0], 2) != "06")
    +1081                 throw "malformed PKCS8 public key(code:003)"; // AlgId.oid is not OID
    +1082 
    +1083             result.algoid = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[0]);
    +1084 
    +1085             // 2.2. AlgID param
    +1086             if (pkcs8PubHex.substr(a2[1], 2) == "06") { // OID for EC
    +1087                 result.algparam = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[1]);
    +1088             } else if (pkcs8PubHex.substr(a2[1], 2) == "30") { // SEQ for DSA
    +1089                 result.algparam = {};
    +1090                 result.algparam.p = ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [0], "02");
    +1091                 result.algparam.q = ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [1], "02");
    +1092                 result.algparam.g = ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [2], "02");
    +1093             }
     1094 
    -1095         /**
    -1096          * parse hexadecimal string of PKCS#8 RSA/EC/DSA public key
    -1097          * @name parsePublicPKCS8Hex
    -1098          * @memberOf KEYUTIL
    -1099          * @function
    -1100          * @param {String} pkcs8PubHex hexadecimal string of PKCS#8 public key
    -1101          * @return {Hash} hash of key information
    -1102          * @description
    -1103          * Resulted hash has following attributes.
    -1104          * <ul>
    -1105          * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
    -1106          * <li>algparam - hexadecimal string of OID of ECC curve name, parameter SEQUENCE of DSA or null</li>
    -1107          * <li>key - hexadecimal string of public key</li>
    -1108          * </ul>
    -1109          */
    -1110         parsePublicPKCS8Hex: function(pkcs8PubHex) {
    -1111             var result = {};
    -1112             result.algparam = null;
    -1113 
    -1114             // 1. AlgID and Key bit string
    -1115             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, 0);
    -1116             if (a1.length != 2)
    -1117                 throw "outer DERSequence shall have 2 elements: " + a1.length;
    -1118 
    -1119             // 2. AlgID
    -1120             var idxAlgIdTLV = a1[0];
    -1121             if (pkcs8PubHex.substr(idxAlgIdTLV, 2) != "30")
    -1122                 throw "malformed PKCS8 public key(code:001)"; // AlgId not sequence
    -1123 
    -1124             var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, idxAlgIdTLV);
    -1125             if (a2.length != 2)
    -1126                 throw "malformed PKCS8 public key(code:002)"; // AlgId not have two elements
    -1127 
    -1128             // 2.1. AlgID OID
    -1129             if (pkcs8PubHex.substr(a2[0], 2) != "06")
    -1130                 throw "malformed PKCS8 public key(code:003)"; // AlgId.oid is not OID
    -1131 
    -1132             result.algoid = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[0]);
    -1133 
    -1134             // 2.2. AlgID param
    -1135             if (pkcs8PubHex.substr(a2[1], 2) == "06") { // OID for EC
    -1136                 result.algparam = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[1]);
    -1137             } else if (pkcs8PubHex.substr(a2[1], 2) == "30") { // SEQ for DSA
    -1138                 result.algparam = {};
    -1139                 result.algparam.p = ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [0], "02");
    -1140                 result.algparam.q = ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [1], "02");
    -1141                 result.algparam.g = ASN1HEX.getVbyList(pkcs8PubHex, a2[1], [2], "02");
    -1142             }
    -1143 
    -1144             // 3. Key
    -1145             if (pkcs8PubHex.substr(a1[1], 2) != "03")
    -1146                 throw "malformed PKCS8 public key(code:004)"; // Key is not bit string
    -1147 
    -1148             result.key = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a1[1]).substr(2);
    -1149             
    -1150             // 4. return result assoc array
    -1151             return result;
    -1152         },
    -1153 
    -1154         /**
    -1155          * (DEPRECATED) provide hexadecimal string of unencrypted PKCS#8 private key and returns RSAKey object
    -1156          * @name getRSAKeyFromPublicPKCS8Hex
    -1157          * @memberOf KEYUTIL
    -1158          * @function
    -1159          * @param {String} pkcs8PubHex hexadecimal string of unencrypted PKCS#8 public key
    -1160          * @return {RSAKey} loaded RSAKey object of RSA public key
    -1161          * @since pkcs5pkey 1.0.4
    -1162          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    -1163          */
    -1164         getRSAKeyFromPublicPKCS8Hex: function(pkcs8PubHex) {
    -1165             var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, 0);
    -1166             if (a1.length != 2)
    -1167                 throw "outer DERSequence shall have 2 elements: " + a1.length;
    -1168 
    -1169             var algIdTLV =ASN1HEX.getHexOfTLV_AtObj(pkcs8PubHex, a1[0]);
    -1170             if (algIdTLV != "300d06092a864886f70d0101010500") // AlgId rsaEncryption
    -1171                 throw "PKCS8 AlgorithmId is not rsaEncryption";
    -1172             
    -1173             if (pkcs8PubHex.substr(a1[1], 2) != "03")
    -1174                 throw "PKCS8 Public Key is not BITSTRING encapslated.";
    -1175 
    -1176             var idxPub = ASN1HEX.getStartPosOfV_AtObj(pkcs8PubHex, a1[1]) + 2; // 2 for unused bit
    -1177             
    -1178             if (pkcs8PubHex.substr(idxPub, 2) != "30")
    -1179                 throw "PKCS8 Public Key is not SEQUENCE.";
    -1180 
    -1181             var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, idxPub);
    -1182             if (a2.length != 2)
    -1183                 throw "inner DERSequence shall have 2 elements: " + a2.length;
    -1184 
    -1185             if (pkcs8PubHex.substr(a2[0], 2) != "02") 
    -1186                 throw "N is not ASN.1 INTEGER";
    -1187             if (pkcs8PubHex.substr(a2[1], 2) != "02") 
    -1188                 throw "E is not ASN.1 INTEGER";
    -1189             
    -1190             var hN = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[0]);
    -1191             var hE = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[1]);
    -1192 
    -1193             var pubKey = new RSAKey();
    -1194             pubKey.setPublic(hN, hE);
    -1195             
    -1196             return pubKey;
    -1197         },
    -1198 
    -1199         //addAlgorithm: function(functionObject, algName, keyLen, ivLen) {
    -1200         //}
    -1201     };
    -1202 }();
    +1095             // 3. Key
    +1096             if (pkcs8PubHex.substr(a1[1], 2) != "03")
    +1097                 throw "malformed PKCS8 public key(code:004)"; // Key is not bit string
    +1098 
    +1099             result.key = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a1[1]).substr(2);
    +1100             
    +1101             // 4. return result assoc array
    +1102             return result;
    +1103         },
    +1104 
    +1105         /**
    +1106          * (DEPRECATED) provide hexadecimal string of unencrypted PKCS#8 private key and returns RSAKey object
    +1107          * @name getRSAKeyFromPublicPKCS8Hex
    +1108          * @memberOf KEYUTIL
    +1109          * @function
    +1110          * @param {String} pkcs8PubHex hexadecimal string of unencrypted PKCS#8 public key
    +1111          * @return {RSAKey} loaded RSAKey object of RSA public key
    +1112          * @since pkcs5pkey 1.0.4
    +1113          * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}.
    +1114          */
    +1115         getRSAKeyFromPublicPKCS8Hex: function(pkcs8PubHex) {
    +1116 	    var key = new RSAKey();
    +1117 	    key.readPKCS8PubKeyHex(pkcs8PubHex);
    +1118 	    return key;
    +1119 	},
    +1120     };
    +1121 }();
    +1122 
    +1123 // -- MAJOR PUBLIC METHODS -------------------------------------------------------
    +1124 /**
    +1125  * get private or public key object from any arguments
    +1126  * @name getKey
    +1127  * @memberOf KEYUTIL
    +1128  * @function
    +1129  * @static
    +1130  * @param {Object} param parameter to get key object. see description in detail.
    +1131  * @param {String} passcode (OPTION) parameter to get key object. see description in detail.
    +1132  * @param {String} hextype (OPTOIN) parameter to get key object. see description in detail.
    +1133  * @return {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.ECDSA} object
    +1134  * @since keyutil 1.0.0
    +1135  * @description
    +1136  * This method gets private or public key object({@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA})
    +1137  * for RSA, DSA and ECC.
    +1138  * Arguments for this methods depends on a key format you specify.
    +1139  * Following key representations are supported.
    +1140  * <ul>
    +1141  * <li>ECC private/public key object(as is): param=KJUR.crypto.ECDSA</li>
    +1142  * <li>DSA private/public key object(as is): param=KJUR.crypto.DSA</li>
    +1143  * <li>RSA private/public key object(as is): param=RSAKey </li>
    +1144  * <li>ECC private key parameters: param={d: d, curve: curveName}</li>
    +1145  * <li>RSA private key parameters: param={n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq, co: co}<br/>
    +1146  * NOTE: Each value shall be hexadecimal string of key spec.</li>
    +1147  * <li>DSA private key parameters: param={p: p, q: q, g: g, y: y, x: x}<br/>
    +1148  * NOTE: Each value shall be hexadecimal string of key spec.</li>
    +1149  * <li>ECC public key parameters: param={xy: xy, curve: curveName}<br/>
    +1150  * NOTE: ECC public key 'xy' shall be concatination of "04", x-bytes-hex and y-bytes-hex.</li>
    +1151  * <li>DSA public key parameters: param={p: p, q: q, g: g, y: y}<br/>
    +1152  * NOTE: Each value shall be hexadecimal string of key spec.</li>
    +1153  * <li>RSA public key parameters: param={n: n, e: e} </li>
    +1154  * <li>X.509v1/v3 PEM certificate (RSA/DSA/ECC): param=pemString</li>
    +1155  * <li>PKCS#8 hexadecimal RSA/ECC public key: param=pemString, null, "pkcs8pub"</li>
    +1156  * <li>PKCS#8 PEM RSA/DSA/ECC public key: param=pemString</li>
    +1157  * <li>PKCS#5 plain hexadecimal RSA private key: param=hexString, null, "pkcs5prv"</li>
    +1158  * <li>PKCS#5 plain PEM DSA/RSA private key: param=pemString</li>
    +1159  * <li>PKCS#8 plain PEM RSA/ECDSA private key: param=pemString</li>
    +1160  * <li>PKCS#5 encrypted PEM RSA/DSA private key: param=pemString, passcode</li>
    +1161  * <li>PKCS#8 encrypted PEM RSA/ECDSA private key: param=pemString, passcode</li>
    +1162  * </ul>
    +1163  * Please note following limitation on encrypted keys:
    +1164  * <ul>
    +1165  * <li>Encrypted PKCS#8 only supports PBKDF2/HmacSHA1/3DES</li>
    +1166  * <li>Encrypted PKCS#5 supports DES-CBC, DES-EDE3-CBC, AES-{128,192.256}-CBC</li>
    +1167  * <li>JWT plain ECC private/public key</li>
    +1168  * <li>JWT plain RSA public key</li>
    +1169  * <li>JWT plain RSA private key with P/Q/DP/DQ/COEFF</li>
    +1170  * <li>JWT plain RSA private key without P/Q/DP/DQ/COEFF (since jsrsasign 5.0.0)</li>
    +1171  * </ul>
    +1172  * NOTE1: <a href="https://tools.ietf.org/html/rfc7517">RFC 7517 JSON Web Key(JWK)</a> support for RSA/ECC private/public key from jsrsasign 4.8.1.<br/>
    +1173  * NOTE2: X509v1 support is added since jsrsasign 5.0.11.
    +1174  * 
    +1175  * <h5>EXAMPLE</h5>
    +1176  * @example
    +1177  * // 1. loading private key from PEM string
    +1178  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY...");
    +1179  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY..., "passcode");
    +1180  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
    +1181  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...", "passcode");
    +1182  * // 2. loading public key from PEM string
    +1183  * keyObj = KEYUTIL.getKey("-----BEGIN PUBLIC KEY...");
    +1184  * keyObj = KEYUTIL.getKey("-----BEGIN X509 CERTIFICATE...");
    +1185  * // 3. loading hexadecimal PKCS#5/PKCS#8 key
    +1186  * keyObj = KEYUTIL.getKey("308205c1...", null, "pkcs8pub");
    +1187  * keyObj = KEYUTIL.getKey("3082048b...", null, "pkcs5prv");
    +1188  * // 4. loading JSON Web Key(JWK)
    +1189  * keyObj = KEYUTIL.getKey({kty: "RSA", n: "0vx7...", e: "AQAB"});
    +1190  * keyObj = KEYUTIL.getKey({kty: "EC", crv: "P-256", 
    +1191  *                          x: "MKBC...", y: "4Etl6...", d: "870Mb..."});
    +1192  * // 5. bare hexadecimal key
    +1193  * keyObj = KEYUTIL.getKey({n: "75ab..", e: "010001"});
    +1194  */
    +1195 KEYUTIL.getKey = function(param, passcode, hextype) {
    +1196     // 1. by key RSAKey/KJUR.crypto.ECDSA/KJUR.crypto.DSA object
    +1197     if (typeof RSAKey != 'undefined' && param instanceof RSAKey)
    +1198         return param;
    +1199     if (typeof KJUR.crypto.ECDSA != 'undefined' && param instanceof KJUR.crypto.ECDSA)
    +1200         return param;
    +1201     if (typeof KJUR.crypto.DSA != 'undefined' && param instanceof KJUR.crypto.DSA)
    +1202         return param;
     1203 
    -1204 // -- MAJOR PUBLIC METHODS -------------------------------------------------------
    -1205 /**
    -1206  * get private or public key object from any arguments
    -1207  * @name getKey
    -1208  * @memberOf KEYUTIL
    -1209  * @function
    -1210  * @static
    -1211  * @param {Object} param parameter to get key object. see description in detail.
    -1212  * @param {String} passcode (OPTION) parameter to get key object. see description in detail.
    -1213  * @param {String} hextype (OPTOIN) parameter to get key object. see description in detail.
    -1214  * @return {Object} {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.ECDSA} object
    -1215  * @since keyutil 1.0.0
    -1216  * @description
    -1217  * This method gets private or public key object({@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA})
    -1218  * for RSA, DSA and ECC.
    -1219  * Arguments for this methods depends on a key format you specify.
    -1220  * Following key representations are supported.
    -1221  * <ul>
    -1222  * <li>ECC private/public key object(as is): param=KJUR.crypto.ECDSA</li>
    -1223  * <li>DSA private/public key object(as is): param=KJUR.crypto.DSA</li>
    -1224  * <li>RSA private/public key object(as is): param=RSAKey </li>
    -1225  * <li>ECC private key parameters: param={d: d, curve: curveName}</li>
    -1226  * <li>RSA private key parameters: param={n: n, e: e, d: d, p: p, q: q, dp: dp, dq: dq, co: co}<br/>
    -1227  * NOTE: Each value shall be hexadecimal string of key spec.</li>
    -1228  * <li>DSA private key parameters: param={p: p, q: q, g: g, y: y, x: x}<br/>
    -1229  * NOTE: Each value shall be hexadecimal string of key spec.</li>
    -1230  * <li>ECC public key parameters: param={xy: xy, curve: curveName}<br/>
    -1231  * NOTE: ECC public key 'xy' shall be concatination of "04", x-bytes-hex and y-bytes-hex.</li>
    -1232  * <li>DSA public key parameters: param={p: p, q: q, g: g, y: y}<br/>
    -1233  * NOTE: Each value shall be hexadecimal string of key spec.</li>
    -1234  * <li>RSA public key parameters: param={n: n, e: e} </li>
    -1235  * <li>X.509v1/v3 PEM certificate (RSA/DSA/ECC): param=pemString</li>
    -1236  * <li>PKCS#8 hexadecimal RSA/ECC public key: param=pemString, null, "pkcs8pub"</li>
    -1237  * <li>PKCS#8 PEM RSA/DSA/ECC public key: param=pemString</li>
    -1238  * <li>PKCS#5 plain hexadecimal RSA private key: param=hexString, null, "pkcs5prv"</li>
    -1239  * <li>PKCS#5 plain PEM DSA/RSA private key: param=pemString</li>
    -1240  * <li>PKCS#8 plain PEM RSA/ECDSA private key: param=pemString</li>
    -1241  * <li>PKCS#5 encrypted PEM RSA/DSA private key: param=pemString, passcode</li>
    -1242  * <li>PKCS#8 encrypted PEM RSA/ECDSA private key: param=pemString, passcode</li>
    -1243  * </ul>
    -1244  * Please note following limitation on encrypted keys:
    -1245  * <ul>
    -1246  * <li>Encrypted PKCS#8 only supports PBKDF2/HmacSHA1/3DES</li>
    -1247  * <li>Encrypted PKCS#5 supports DES-CBC, DES-EDE3-CBC, AES-{128,192.256}-CBC</li>
    -1248  * <li>JWT plain ECC private/public key</li>
    -1249  * <li>JWT plain RSA public key</li>
    -1250  * <li>JWT plain RSA private key with P/Q/DP/DQ/COEFF</li>
    -1251  * <li>JWT plain RSA private key without P/Q/DP/DQ/COEFF (since jsrsasign 5.0.0)</li>
    -1252  * </ul>
    -1253  * NOTE1: <a href="https://tools.ietf.org/html/rfc7517">RFC 7517 JSON Web Key(JWK)</a> support for RSA/ECC private/public key from jsrsasign 4.8.1.<br/>
    -1254  * NOTE2: X509v1 support is added since jsrsasign 5.0.11.
    -1255  * 
    -1256  * <h5>EXAMPLE</h5>
    -1257  * @example
    -1258  * // 1. loading private key from PEM string
    -1259  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY...");
    -1260  * keyObj = KEYUTIL.getKey("-----BEGIN RSA PRIVATE KEY..., "passcode");
    -1261  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...");
    -1262  * keyObj = KEYUTIL.getKey("-----BEGIN PRIVATE KEY...", "passcode");
    -1263  * // 2. loading public key from PEM string
    -1264  * keyObj = KEYUTIL.getKey("-----BEGIN PUBLIC KEY...");
    -1265  * keyObj = KEYUTIL.getKey("-----BEGIN X509 CERTIFICATE...");
    -1266  * // 3. loading hexadecimal PKCS#5/PKCS#8 key
    -1267  * keyObj = KEYUTIL.getKey("308205c1...", null, "pkcs8pub");
    -1268  * keyObj = KEYUTIL.getKey("3082048b...", null, "pkcs5prv");
    -1269  * // 4. loading JSON Web Key(JWK)
    -1270  * keyObj = KEYUTIL.getKey({kty: "RSA", n: "0vx7...", e: "AQAB"});
    -1271  * keyObj = KEYUTIL.getKey({kty: "EC", crv: "P-256", 
    -1272  *                          x: "MKBC...", y: "4Etl6...", d: "870Mb..."});
    -1273  * // 5. bare hexadecimal key
    -1274  * keyObj = KEYUTIL.getKey({n: "75ab..", e: "010001"});
    -1275  */
    -1276 KEYUTIL.getKey = function(param, passcode, hextype) {
    -1277     // 1. by key RSAKey/KJUR.crypto.ECDSA/KJUR.crypto.DSA object
    -1278     if (typeof RSAKey != 'undefined' && param instanceof RSAKey)
    -1279         return param;
    -1280     if (typeof KJUR.crypto.ECDSA != 'undefined' && param instanceof KJUR.crypto.ECDSA)
    -1281         return param;
    -1282     if (typeof KJUR.crypto.DSA != 'undefined' && param instanceof KJUR.crypto.DSA)
    -1283         return param;
    -1284 
    -1285     // 2. by parameters of key
    +1204     // 2. by parameters of key
    +1205 
    +1206     // 2.1. bare ECC
    +1207     // 2.1.1. bare ECC public key by hex values
    +1208     if (param.curve !== undefined &&
    +1209 	param.xy !== undefined && param.d === undefined) {
    +1210         return new KJUR.crypto.ECDSA({pub: param.xy, curve: param.curve});
    +1211     }
    +1212 
    +1213     // 2.1.2. bare ECC private key by hex values
    +1214     if (param.curve !== undefined && param.d !== undefined) {
    +1215         return new KJUR.crypto.ECDSA({prv: param.d, curve: param.curve});
    +1216     }
    +1217 
    +1218     // 2.2. bare RSA
    +1219     // 2.2.1. bare RSA public key by hex values
    +1220     if (param.kty === undefined &&
    +1221 	param.n !== undefined && param.e !== undefined &&
    +1222         param.d === undefined) {
    +1223         var key = new RSAKey();
    +1224         key.setPublic(param.n, param.e);
    +1225         return key;
    +1226     }
    +1227 
    +1228     // 2.2.2. bare RSA private key with P/Q/DP/DQ/COEFF by hex values
    +1229     if (param.kty === undefined &&
    +1230 	param.n !== undefined &&
    +1231 	param.e !== undefined &&
    +1232 	param.d !== undefined &&
    +1233         param.p !== undefined &&
    +1234 	param.q !== undefined &&
    +1235         param.dp !== undefined &&
    +1236 	param.dq !== undefined &&
    +1237 	param.co !== undefined &&
    +1238         param.qi === undefined) {
    +1239         var key = new RSAKey();
    +1240         key.setPrivateEx(param.n, param.e, param.d, param.p, param.q,
    +1241                          param.dp, param.dq, param.co);
    +1242         return key;
    +1243     }
    +1244 
    +1245     // 2.2.3. bare RSA public key without P/Q/DP/DQ/COEFF by hex values
    +1246     if (param.kty === undefined &&
    +1247 	param.n !== undefined &&
    +1248 	param.e !== undefined &&
    +1249 	param.d !== undefined &&
    +1250         param.p === undefined) {
    +1251         var key = new RSAKey();
    +1252         key.setPrivate(param.n, param.e, param.d);
    +1253         return key;
    +1254     }
    +1255 
    +1256     // 2.3. bare DSA
    +1257     // 2.3.1. bare DSA public key by hex values
    +1258     if (param.p !== undefined && param.q !== undefined &&
    +1259 	param.g !== undefined &&
    +1260         param.y !== undefined && param.x === undefined) {
    +1261         var key = new KJUR.crypto.DSA();
    +1262         key.setPublic(param.p, param.q, param.g, param.y);
    +1263         return key;
    +1264     }
    +1265 
    +1266     // 2.3.2. bare DSA private key by hex values
    +1267     if (param.p !== undefined && param.q !== undefined &&
    +1268 	param.g !== undefined &&
    +1269         param.y !== undefined && param.x !== undefined) {
    +1270         var key = new KJUR.crypto.DSA();
    +1271         key.setPrivate(param.p, param.q, param.g, param.y, param.x);
    +1272         return key;
    +1273     }
    +1274 
    +1275     // 3. JWK
    +1276     // 3.1. JWK RSA
    +1277     // 3.1.1. JWK RSA public key by b64u values
    +1278     if (param.kty === "RSA" &&
    +1279 	param.n !== undefined &&
    +1280 	param.e !== undefined &&
    +1281 	param.d === undefined) {
    +1282 	var key = new RSAKey();
    +1283 	key.setPublic(b64utohex(param.n), b64utohex(param.e));
    +1284 	return key;
    +1285     }
     1286 
    -1287     // 2.1. bare ECC
    -1288     // 2.1.1. bare ECC public key by hex values
    -1289     if (param.curve !== undefined &&
    -1290 	param.xy !== undefined && param.d === undefined) {
    -1291         return new KJUR.crypto.ECDSA({pub: param.xy, curve: param.curve});
    -1292     }
    -1293 
    -1294     // 2.1.2. bare ECC private key by hex values
    -1295     if (param.curve !== undefined && param.d !== undefined) {
    -1296         return new KJUR.crypto.ECDSA({prv: param.d, curve: param.curve});
    -1297     }
    -1298 
    -1299     // 2.2. bare RSA
    -1300     // 2.2.1. bare RSA public key by hex values
    -1301     if (param.kty === undefined &&
    -1302 	param.n !== undefined && param.e !== undefined &&
    -1303         param.d === undefined) {
    -1304         var key = new RSAKey();
    -1305         key.setPublic(param.n, param.e);
    -1306         return key;
    +1287     // 3.1.2. JWK RSA private key with p/q/dp/dq/coeff by b64u values
    +1288     if (param.kty === "RSA" &&
    +1289 	param.n !== undefined &&
    +1290 	param.e !== undefined &&
    +1291 	param.d !== undefined &&
    +1292 	param.p !== undefined &&
    +1293 	param.q !== undefined &&
    +1294 	param.dp !== undefined &&
    +1295 	param.dq !== undefined &&
    +1296 	param.qi !== undefined) {
    +1297 	var key = new RSAKey();
    +1298         key.setPrivateEx(b64utohex(param.n),
    +1299 			 b64utohex(param.e),
    +1300 			 b64utohex(param.d),
    +1301 			 b64utohex(param.p),
    +1302 			 b64utohex(param.q),
    +1303                          b64utohex(param.dp),
    +1304 			 b64utohex(param.dq),
    +1305 			 b64utohex(param.qi));
    +1306 	return key;
     1307     }
     1308 
    -1309     // 2.2.2. bare RSA private key with P/Q/DP/DQ/COEFF by hex values
    -1310     if (param.kty === undefined &&
    -1311 	param.n !== undefined &&
    -1312 	param.e !== undefined &&
    -1313 	param.d !== undefined &&
    -1314         param.p !== undefined &&
    -1315 	param.q !== undefined &&
    -1316         param.dp !== undefined &&
    -1317 	param.dq !== undefined &&
    -1318 	param.co !== undefined &&
    -1319         param.qi === undefined) {
    -1320         var key = new RSAKey();
    -1321         key.setPrivateEx(param.n, param.e, param.d, param.p, param.q,
    -1322                          param.dp, param.dq, param.co);
    -1323         return key;
    -1324     }
    -1325 
    -1326     // 2.2.3. bare RSA public key without P/Q/DP/DQ/COEFF by hex values
    -1327     if (param.kty === undefined &&
    -1328 	param.n !== undefined &&
    -1329 	param.e !== undefined &&
    -1330 	param.d !== undefined &&
    -1331         param.p === undefined) {
    -1332         var key = new RSAKey();
    -1333         key.setPrivate(param.n, param.e, param.d);
    -1334         return key;
    -1335     }
    -1336 
    -1337     // 2.3. bare DSA
    -1338     // 2.3.1. bare DSA public key by hex values
    -1339     if (param.p !== undefined && param.q !== undefined &&
    -1340 	param.g !== undefined &&
    -1341         param.y !== undefined && param.x === undefined) {
    -1342         var key = new KJUR.crypto.DSA();
    -1343         key.setPublic(param.p, param.q, param.g, param.y);
    -1344         return key;
    -1345     }
    -1346 
    -1347     // 2.3.2. bare DSA private key by hex values
    -1348     if (param.p !== undefined && param.q !== undefined &&
    -1349 	param.g !== undefined &&
    -1350         param.y !== undefined && param.x !== undefined) {
    -1351         var key = new KJUR.crypto.DSA();
    -1352         key.setPrivate(param.p, param.q, param.g, param.y, param.x);
    -1353         return key;
    -1354     }
    -1355 
    -1356     // 3. JWK
    -1357     // 3.1. JWK RSA
    -1358     // 3.1.1. JWK RSA public key by b64u values
    -1359     if (param.kty === "RSA" &&
    -1360 	param.n !== undefined &&
    -1361 	param.e !== undefined &&
    -1362 	param.d === undefined) {
    -1363 	var key = new RSAKey();
    -1364 	key.setPublic(b64utohex(param.n), b64utohex(param.e));
    -1365 	return key;
    -1366     }
    -1367 
    -1368     // 3.1.2. JWK RSA private key with p/q/dp/dq/coeff by b64u values
    -1369     if (param.kty === "RSA" &&
    -1370 	param.n !== undefined &&
    -1371 	param.e !== undefined &&
    -1372 	param.d !== undefined &&
    -1373 	param.p !== undefined &&
    -1374 	param.q !== undefined &&
    -1375 	param.dp !== undefined &&
    -1376 	param.dq !== undefined &&
    -1377 	param.qi !== undefined) {
    -1378 	var key = new RSAKey();
    -1379         key.setPrivateEx(b64utohex(param.n),
    -1380 			 b64utohex(param.e),
    -1381 			 b64utohex(param.d),
    -1382 			 b64utohex(param.p),
    -1383 			 b64utohex(param.q),
    -1384                          b64utohex(param.dp),
    -1385 			 b64utohex(param.dq),
    -1386 			 b64utohex(param.qi));
    -1387 	return key;
    -1388     }
    -1389 
    -1390     // 3.1.3. JWK RSA private key without p/q/dp/dq/coeff by b64u
    -1391     //        since jsrsasign 5.0.0 keyutil 1.0.11
    -1392     if (param.kty === "RSA" &&
    -1393 	param.n !== undefined &&
    -1394 	param.e !== undefined &&
    -1395 	param.d !== undefined) {
    -1396 	var key = new RSAKey();
    -1397         key.setPrivate(b64utohex(param.n),
    -1398 		       b64utohex(param.e),
    -1399 		       b64utohex(param.d));
    -1400 	return key;
    -1401     }
    -1402 
    -1403     // 3.2. JWK ECC
    -1404     // 3.2.1. JWK ECC public key by b64u values
    -1405     if (param.kty === "EC" &&
    -1406 	param.crv !== undefined &&
    -1407 	param.x !== undefined &&
    -1408 	param.y !== undefined &&
    -1409         param.d === undefined) {
    -1410 	var ec = new KJUR.crypto.ECDSA({"curve": param.crv});
    -1411 	var charlen = ec.ecparams.keylen / 4;
    -1412         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
    -1413         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
    -1414         var hPub = "04" + hX + hY;
    -1415 	ec.setPublicKeyHex(hPub);
    -1416 	return ec;
    -1417     }
    -1418 
    -1419     // 3.2.2. JWK ECC private key by b64u values
    -1420     if (param.kty === "EC" &&
    -1421 	param.crv !== undefined &&
    -1422 	param.x !== undefined &&
    -1423 	param.y !== undefined &&
    -1424         param.d !== undefined) {
    -1425 	var ec = new KJUR.crypto.ECDSA({"curve": param.crv});
    -1426 	var charlen = ec.ecparams.keylen / 4;
    -1427         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
    -1428         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
    -1429         var hPub = "04" + hX + hY;
    -1430         var hPrv = ("0000000000" + b64utohex(param.d)).slice(- charlen);
    -1431 	ec.setPublicKeyHex(hPub);
    -1432 	ec.setPrivateKeyHex(hPrv);
    -1433 	return ec;
    -1434     }
    -1435     
    -1436     // 4. by PEM certificate (-----BEGIN ... CERTIFITE----)
    -1437     if (param.indexOf("-END CERTIFICATE-", 0) != -1 ||
    -1438         param.indexOf("-END X509 CERTIFICATE-", 0) != -1 ||
    -1439         param.indexOf("-END TRUSTED CERTIFICATE-", 0) != -1) {
    -1440         return X509.getPublicKeyFromCertPEM(param);
    +1309     // 3.1.3. JWK RSA private key without p/q/dp/dq/coeff by b64u
    +1310     //        since jsrsasign 5.0.0 keyutil 1.0.11
    +1311     if (param.kty === "RSA" &&
    +1312 	param.n !== undefined &&
    +1313 	param.e !== undefined &&
    +1314 	param.d !== undefined) {
    +1315 	var key = new RSAKey();
    +1316         key.setPrivate(b64utohex(param.n),
    +1317 		       b64utohex(param.e),
    +1318 		       b64utohex(param.d));
    +1319 	return key;
    +1320     }
    +1321 
    +1322     // 3.2. JWK ECC
    +1323     // 3.2.1. JWK ECC public key by b64u values
    +1324     if (param.kty === "EC" &&
    +1325 	param.crv !== undefined &&
    +1326 	param.x !== undefined &&
    +1327 	param.y !== undefined &&
    +1328         param.d === undefined) {
    +1329 	var ec = new KJUR.crypto.ECDSA({"curve": param.crv});
    +1330 	var charlen = ec.ecparams.keylen / 4;
    +1331         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
    +1332         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
    +1333         var hPub = "04" + hX + hY;
    +1334 	ec.setPublicKeyHex(hPub);
    +1335 	return ec;
    +1336     }
    +1337 
    +1338     // 3.2.2. JWK ECC private key by b64u values
    +1339     if (param.kty === "EC" &&
    +1340 	param.crv !== undefined &&
    +1341 	param.x !== undefined &&
    +1342 	param.y !== undefined &&
    +1343         param.d !== undefined) {
    +1344 	var ec = new KJUR.crypto.ECDSA({"curve": param.crv});
    +1345 	var charlen = ec.ecparams.keylen / 4;
    +1346         var hX   = ("0000000000" + b64utohex(param.x)).slice(- charlen);
    +1347         var hY   = ("0000000000" + b64utohex(param.y)).slice(- charlen);
    +1348         var hPub = "04" + hX + hY;
    +1349         var hPrv = ("0000000000" + b64utohex(param.d)).slice(- charlen);
    +1350 	ec.setPublicKeyHex(hPub);
    +1351 	ec.setPrivateKeyHex(hPrv);
    +1352 	return ec;
    +1353     }
    +1354     
    +1355     // 4. (plain) hexadecimal data
    +1356     // 4.1. get private key by PKCS#5 plain RSA/DSA/ECDSA hexadecimal string
    +1357     if (hextype === "pkcs5prv") {
    +1358 	var h = param, _ASN1HEX = ASN1HEX, a, key;
    +1359 	a = _ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    +1360 	if (a.length === 9) {        // RSA (INT x 9)
    +1361 	    key = new RSAKey();
    +1362             key.readPrivateKeyFromASN1HexString(param);
    +1363 	} else if (a.length === 6) { // DSA (INT x 6)
    +1364 	    key = new KJUR.crypto.DSA();
    +1365 	    key.readPKCS5PrvKeyHex(h);
    +1366 	} else if (a.length > 2 &&   // ECDSA (INT, OCT prv, [0] curve, [1] pub)
    +1367 		   h.substr(a[1], 2) === "04") {
    +1368 	    key = new KJUR.crypto.ECDSA();
    +1369 	    key.readPKCS5PrvKeyHex(h);
    +1370 	} else {
    +1371 	    throw "unsupported PKCS#1/5 hexadecimal key";
    +1372 	}
    +1373 
    +1374         return key;
    +1375     }
    +1376 
    +1377     // 4.2. get private key by PKCS#8 plain RSA/DSA/ECDSA hexadecimal string
    +1378     if (hextype === "pkcs8prv") {
    +1379 	var key = KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(param);
    +1380         return key;
    +1381     }
    +1382 
    +1383     // 4.3. get public key by PKCS#8 RSA/DSA/ECDSA hexadecimal string
    +1384     if (hextype === "pkcs8pub") {
    +1385         return KEYUTIL.getKeyFromPublicPKCS8Hex(param);
    +1386     }
    +1387 
    +1388     // 4.4. get public key by X.509 hexadecimal string for RSA/DSA/ECDSA
    +1389     if (hextype === "x509pub") {
    +1390         return X509.getPublicKeyFromCertHex(param);
    +1391     }
    +1392 
    +1393     // 5. by PEM certificate (-----BEGIN ... CERTIFICATE----)
    +1394     if (param.indexOf("-END CERTIFICATE-", 0) != -1 ||
    +1395         param.indexOf("-END X509 CERTIFICATE-", 0) != -1 ||
    +1396         param.indexOf("-END TRUSTED CERTIFICATE-", 0) != -1) {
    +1397         return X509.getPublicKeyFromCertPEM(param);
    +1398     }
    +1399 
    +1400     // 6. public key by PKCS#8 PEM string
    +1401     if (param.indexOf("-END PUBLIC KEY-") != -1) {
    +1402         return KEYUTIL.getKeyFromPublicPKCS8PEM(param);
    +1403     }
    +1404     
    +1405     // 8.1 private key by plain PKCS#5 PEM RSA string 
    +1406     //    getKey("-----BEGIN RSA PRIVATE KEY-...")
    +1407     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
    +1408         param.indexOf("4,ENCRYPTED") == -1) {
    +1409         var hex = ASN1HEX.pemToHex(param, "RSA PRIVATE KEY");
    +1410         return KEYUTIL.getKey(hex, null, "pkcs5prv");
    +1411     }
    +1412 
    +1413     // 8.2. private key by plain PKCS#5 PEM DSA string
    +1414     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
    +1415         param.indexOf("4,ENCRYPTED") == -1) {
    +1416 
    +1417         var hKey = ASN1HEX.pemToHex(param, "DSA PRIVATE KEY");
    +1418         var p = ASN1HEX.getVbyList(hKey, 0, [1], "02");
    +1419         var q = ASN1HEX.getVbyList(hKey, 0, [2], "02");
    +1420         var g = ASN1HEX.getVbyList(hKey, 0, [3], "02");
    +1421         var y = ASN1HEX.getVbyList(hKey, 0, [4], "02");
    +1422         var x = ASN1HEX.getVbyList(hKey, 0, [5], "02");
    +1423         var key = new KJUR.crypto.DSA();
    +1424         key.setPrivate(new BigInteger(p, 16),
    +1425                        new BigInteger(q, 16),
    +1426                        new BigInteger(g, 16),
    +1427                        new BigInteger(y, 16),
    +1428                        new BigInteger(x, 16));
    +1429         return key;
    +1430     }
    +1431 
    +1432     // 10. private key by plain PKCS#8 PEM ECC/RSA string
    +1433     if (param.indexOf("-END PRIVATE KEY-") != -1) {
    +1434         return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(param);
    +1435     }
    +1436 
    +1437     // 11.1 private key by encrypted PKCS#5 PEM RSA string
    +1438     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
    +1439         param.indexOf("4,ENCRYPTED") != -1) {
    +1440         return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(param, passcode);
     1441     }
     1442 
    -1443     // 4. public key by PKCS#8 hexadecimal string
    -1444     if (hextype === "pkcs8pub") {
    -1445         return KEYUTIL.getKeyFromPublicPKCS8Hex(param);
    -1446     }
    +1443     // 11.2. private key by encrypted PKCS#5 PEM ECDSA string
    +1444     if (param.indexOf("-END EC PRIVATE KEY-") != -1 &&
    +1445         param.indexOf("4,ENCRYPTED") != -1) {
    +1446         var hKey = KEYUTIL.getDecryptedKeyHex(param, passcode);
     1447 
    -1448     // 5. public key by PKCS#8 PEM string
    -1449     if (param.indexOf("-END PUBLIC KEY-") != -1) {
    -1450         return KEYUTIL.getKeyFromPublicPKCS8PEM(param);
    -1451     }
    -1452     
    -1453     // 6. private key by PKCS#5 plain hexadecimal RSA string
    -1454     if (hextype === "pkcs5prv") {
    -1455         var key = new RSAKey();
    -1456         key.readPrivateKeyFromASN1HexString(param);
    -1457         return key;
    -1458     }
    -1459 
    -1460     // 7. private key by plain PKCS#5 hexadecimal RSA string
    -1461     if (hextype === "pkcs5prv") {
    -1462         var key = new RSAKey();
    -1463         key.readPrivateKeyFromASN1HexString(param);
    -1464         return key;
    -1465     }
    -1466 
    -1467     // 8. private key by plain PKCS#5 PEM RSA string 
    -1468     //    getKey("-----BEGIN RSA PRIVATE KEY-...")
    -1469     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
    -1470         param.indexOf("4,ENCRYPTED") == -1) {
    -1471         var hex = KEYUTIL.getHexFromPEM(param, "RSA PRIVATE KEY");
    -1472         return KEYUTIL.getKey(hex, null, "pkcs5prv");
    -1473     }
    -1474 
    -1475     // 8.2. private key by plain PKCS#5 PEM DSA string
    -1476     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
    -1477         param.indexOf("4,ENCRYPTED") == -1) {
    -1478 
    -1479         var hKey = this.getHexFromPEM(param, "DSA PRIVATE KEY");
    -1480         var p = ASN1HEX.getVbyList(hKey, 0, [1], "02");
    -1481         var q = ASN1HEX.getVbyList(hKey, 0, [2], "02");
    -1482         var g = ASN1HEX.getVbyList(hKey, 0, [3], "02");
    -1483         var y = ASN1HEX.getVbyList(hKey, 0, [4], "02");
    -1484         var x = ASN1HEX.getVbyList(hKey, 0, [5], "02");
    -1485         var key = new KJUR.crypto.DSA();
    -1486         key.setPrivate(new BigInteger(p, 16),
    -1487                        new BigInteger(q, 16),
    -1488                        new BigInteger(g, 16),
    -1489                        new BigInteger(y, 16),
    -1490                        new BigInteger(x, 16));
    -1491         return key;
    -1492     }
    -1493 
    -1494     // 9. private key by plain PKCS#8 PEM ECC/RSA string
    -1495     if (param.indexOf("-END PRIVATE KEY-") != -1) {
    -1496         return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(param);
    -1497     }
    -1498 
    -1499     // 10. private key by encrypted PKCS#5 PEM RSA string
    -1500     if (param.indexOf("-END RSA PRIVATE KEY-") != -1 &&
    -1501         param.indexOf("4,ENCRYPTED") != -1) {
    -1502         return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(param, passcode);
    -1503     }
    -1504 
    -1505     // 10.2. private key by encrypted PKCS#5 PEM ECDSA string
    -1506     if (param.indexOf("-END EC PRIVATE KEY-") != -1 &&
    -1507         param.indexOf("4,ENCRYPTED") != -1) {
    -1508         var hKey = KEYUTIL.getDecryptedKeyHex(param, passcode);
    -1509 
    -1510         var key = ASN1HEX.getVbyList(hKey, 0, [1], "04");
    -1511         var curveNameOidHex = ASN1HEX.getVbyList(hKey, 0, [2,0], "06");
    -1512         var pubkey = ASN1HEX.getVbyList(hKey, 0, [3,0], "03").substr(2);
    -1513         var curveName = "";
    -1514 
    -1515         if (KJUR.crypto.OID.oidhex2name[curveNameOidHex] !== undefined) {
    -1516             curveName = KJUR.crypto.OID.oidhex2name[curveNameOidHex];
    -1517         } else {
    -1518             throw "undefined OID(hex) in KJUR.crypto.OID: " + curveNameOidHex;
    -1519         }
    -1520 
    -1521         var ec = new KJUR.crypto.ECDSA({'name': curveName});
    -1522         ec.setPublicKeyHex(pubkey);
    -1523         ec.setPrivateKeyHex(key);
    -1524         ec.isPublic = false;
    -1525         return ec;
    -1526     }
    -1527 
    -1528     // 10.3. private key by encrypted PKCS#5 PEM DSA string
    -1529     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
    -1530         param.indexOf("4,ENCRYPTED") != -1) {
    -1531         var hKey = KEYUTIL.getDecryptedKeyHex(param, passcode);
    -1532         var p = ASN1HEX.getVbyList(hKey, 0, [1], "02");
    -1533         var q = ASN1HEX.getVbyList(hKey, 0, [2], "02");
    -1534         var g = ASN1HEX.getVbyList(hKey, 0, [3], "02");
    -1535         var y = ASN1HEX.getVbyList(hKey, 0, [4], "02");
    -1536         var x = ASN1HEX.getVbyList(hKey, 0, [5], "02");
    -1537         var key = new KJUR.crypto.DSA();
    -1538         key.setPrivate(new BigInteger(p, 16),
    -1539                        new BigInteger(q, 16),
    -1540                        new BigInteger(g, 16),
    -1541                        new BigInteger(y, 16),
    -1542                        new BigInteger(x, 16));
    -1543         return key;
    -1544     }
    -1545 
    -1546     // 11. private key by encrypted PKCS#8 hexadecimal RSA/ECDSA string
    -1547     if (param.indexOf("-END ENCRYPTED PRIVATE KEY-") != -1) {
    -1548         return KEYUTIL.getKeyFromEncryptedPKCS8PEM(param, passcode);
    -1549     }
    -1550 
    -1551     throw "not supported argument";
    -1552 };
    +1448         var key = ASN1HEX.getVbyList(hKey, 0, [1], "04");
    +1449         var curveNameOidHex = ASN1HEX.getVbyList(hKey, 0, [2,0], "06");
    +1450         var pubkey = ASN1HEX.getVbyList(hKey, 0, [3,0], "03").substr(2);
    +1451         var curveName = "";
    +1452 
    +1453         if (KJUR.crypto.OID.oidhex2name[curveNameOidHex] !== undefined) {
    +1454             curveName = KJUR.crypto.OID.oidhex2name[curveNameOidHex];
    +1455         } else {
    +1456             throw "undefined OID(hex) in KJUR.crypto.OID: " + curveNameOidHex;
    +1457         }
    +1458 
    +1459         var ec = new KJUR.crypto.ECDSA({'curve': curveName});
    +1460         ec.setPublicKeyHex(pubkey);
    +1461         ec.setPrivateKeyHex(key);
    +1462         ec.isPublic = false;
    +1463         return ec;
    +1464     }
    +1465 
    +1466     // 11.3. private key by encrypted PKCS#5 PEM DSA string
    +1467     if (param.indexOf("-END DSA PRIVATE KEY-") != -1 &&
    +1468         param.indexOf("4,ENCRYPTED") != -1) {
    +1469         var hKey = KEYUTIL.getDecryptedKeyHex(param, passcode);
    +1470         var p = ASN1HEX.getVbyList(hKey, 0, [1], "02");
    +1471         var q = ASN1HEX.getVbyList(hKey, 0, [2], "02");
    +1472         var g = ASN1HEX.getVbyList(hKey, 0, [3], "02");
    +1473         var y = ASN1HEX.getVbyList(hKey, 0, [4], "02");
    +1474         var x = ASN1HEX.getVbyList(hKey, 0, [5], "02");
    +1475         var key = new KJUR.crypto.DSA();
    +1476         key.setPrivate(new BigInteger(p, 16),
    +1477                        new BigInteger(q, 16),
    +1478                        new BigInteger(g, 16),
    +1479                        new BigInteger(y, 16),
    +1480                        new BigInteger(x, 16));
    +1481         return key;
    +1482     }
    +1483 
    +1484     // 11. private key by encrypted PKCS#8 hexadecimal RSA/ECDSA string
    +1485     if (param.indexOf("-END ENCRYPTED PRIVATE KEY-") != -1) {
    +1486         return KEYUTIL.getKeyFromEncryptedPKCS8PEM(param, passcode);
    +1487     }
    +1488 
    +1489     throw "not supported argument";
    +1490 };
    +1491 
    +1492 /**
    +1493  * @name generateKeypair
    +1494  * @memberOf KEYUTIL
    +1495  * @function
    +1496  * @static
    +1497  * @param {String} alg 'RSA' or 'EC'
    +1498  * @param {Object} keylenOrCurve key length for RSA or curve name for EC
    +1499  * @return {Array} associative array of keypair which has prvKeyObj and pubKeyObj parameters
    +1500  * @since keyutil 1.0.1
    +1501  * @description
    +1502  * This method generates a key pair of public key algorithm.
    +1503  * The result will be an associative array which has following
    +1504  * parameters:
    +1505  * <ul>
    +1506  * <li>prvKeyObj - RSAKey or ECDSA object of private key</li>
    +1507  * <li>pubKeyObj - RSAKey or ECDSA object of public key</li>
    +1508  * </ul>
    +1509  * NOTE1: As for RSA algoirthm, public exponent has fixed
    +1510  * value '0x10001'.
    +1511  * NOTE2: As for EC algorithm, supported names of curve are
    +1512  * secp256r1, secp256k1 and secp384r1.
    +1513  * NOTE3: DSA is not supported yet.
    +1514  * @example
    +1515  * var rsaKeypair = KEYUTIL.generateKeypair("RSA", 1024);
    +1516  * var ecKeypair = KEYUTIL.generateKeypair("EC", "secp256r1");
    +1517  *
    +1518  */
    +1519 KEYUTIL.generateKeypair = function(alg, keylenOrCurve) {
    +1520     if (alg == "RSA") {
    +1521         var keylen = keylenOrCurve;
    +1522         var prvKey = new RSAKey();
    +1523         prvKey.generate(keylen, '10001');
    +1524         prvKey.isPrivate = true;
    +1525         prvKey.isPublic = true;
    +1526         
    +1527         var pubKey = new RSAKey();
    +1528         var hN = prvKey.n.toString(16);
    +1529         var hE = prvKey.e.toString(16);
    +1530         pubKey.setPublic(hN, hE);
    +1531         pubKey.isPrivate = false;
    +1532         pubKey.isPublic = true;
    +1533         
    +1534         var result = {};
    +1535         result.prvKeyObj = prvKey;
    +1536         result.pubKeyObj = pubKey;
    +1537         return result;
    +1538     } else if (alg == "EC") {
    +1539         var curve = keylenOrCurve;
    +1540         var ec = new KJUR.crypto.ECDSA({curve: curve});
    +1541         var keypairHex = ec.generateKeyPairHex();
    +1542 
    +1543         var prvKey = new KJUR.crypto.ECDSA({curve: curve});
    +1544         prvKey.setPublicKeyHex(keypairHex.ecpubhex);
    +1545         prvKey.setPrivateKeyHex(keypairHex.ecprvhex);
    +1546         prvKey.isPrivate = true;
    +1547         prvKey.isPublic = false;
    +1548 
    +1549         var pubKey = new KJUR.crypto.ECDSA({curve: curve});
    +1550         pubKey.setPublicKeyHex(keypairHex.ecpubhex);
    +1551         pubKey.isPrivate = false;
    +1552         pubKey.isPublic = true;
     1553 
    -1554 /**
    -1555  * @name generateKeypair
    -1556  * @memberOf KEYUTIL
    -1557  * @function
    -1558  * @static
    -1559  * @param {String} alg 'RSA' or 'EC'
    -1560  * @param {Object} keylenOrCurve key length for RSA or curve name for EC
    -1561  * @return {Array} associative array of keypair which has prvKeyObj and pubKeyObj parameters
    -1562  * @since keyutil 1.0.1
    -1563  * @description
    -1564  * This method generates a key pair of public key algorithm.
    -1565  * The result will be an associative array which has following
    -1566  * parameters:
    -1567  * <ul>
    -1568  * <li>prvKeyObj - RSAKey or ECDSA object of private key</li>
    -1569  * <li>pubKeyObj - RSAKey or ECDSA object of public key</li>
    -1570  * </ul>
    -1571  * NOTE1: As for RSA algoirthm, public exponent has fixed
    -1572  * value '0x10001'.
    -1573  * NOTE2: As for EC algorithm, supported names of curve are
    -1574  * secp256r1, secp256k1 and secp384r1.
    -1575  * NOTE3: DSA is not supported yet.
    -1576  * @example
    -1577  * var rsaKeypair = KEYUTIL.generateKeypair("RSA", 1024);
    -1578  * var ecKeypair = KEYUTIL.generateKeypair("EC", "secp256r1");
    -1579  *
    -1580  */
    -1581 KEYUTIL.generateKeypair = function(alg, keylenOrCurve) {
    -1582     if (alg == "RSA") {
    -1583         var keylen = keylenOrCurve;
    -1584         var prvKey = new RSAKey();
    -1585         prvKey.generate(keylen, '10001');
    -1586         prvKey.isPrivate = true;
    -1587         prvKey.isPublic = true;
    -1588         
    -1589         var pubKey = new RSAKey();
    -1590         var hN = prvKey.n.toString(16);
    -1591         var hE = prvKey.e.toString(16);
    -1592         pubKey.setPublic(hN, hE);
    -1593         pubKey.isPrivate = false;
    -1594         pubKey.isPublic = true;
    -1595         
    -1596         var result = {};
    -1597         result.prvKeyObj = prvKey;
    -1598         result.pubKeyObj = pubKey;
    -1599         return result;
    -1600     } else if (alg == "EC") {
    -1601         var curve = keylenOrCurve;
    -1602         var ec = new KJUR.crypto.ECDSA({curve: curve});
    -1603         var keypairHex = ec.generateKeyPairHex();
    -1604 
    -1605         var prvKey = new KJUR.crypto.ECDSA({curve: curve});
    -1606         prvKey.setPublicKeyHex(keypairHex.ecpubhex);
    -1607         prvKey.setPrivateKeyHex(keypairHex.ecprvhex);
    -1608         prvKey.isPrivate = true;
    -1609         prvKey.isPublic = false;
    -1610 
    -1611         var pubKey = new KJUR.crypto.ECDSA({curve: curve});
    -1612         pubKey.setPublicKeyHex(keypairHex.ecpubhex);
    -1613         pubKey.isPrivate = false;
    -1614         pubKey.isPublic = true;
    +1554         var result = {};
    +1555         result.prvKeyObj = prvKey;
    +1556         result.pubKeyObj = pubKey;
    +1557         return result;
    +1558     } else {
    +1559         throw "unknown algorithm: " + alg;
    +1560     }
    +1561 };
    +1562 
    +1563 /**
    +1564  * get PEM formatted private or public key file from a RSA/ECDSA/DSA key object
    +1565  * @name getPEM
    +1566  * @memberOf KEYUTIL
    +1567  * @function
    +1568  * @static
    +1569  * @param {Object} keyObjOrHex key object {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} to encode to
    +1570  * @param {String} formatType (OPTION) output format type of "PKCS1PRV", "PKCS5PRV" or "PKCS8PRV" for private key
    +1571  * @param {String} passwd (OPTION) password to protect private key
    +1572  * @param {String} encAlg (OPTION) encryption algorithm for PKCS#5. currently supports DES-CBC, DES-EDE3-CBC and AES-{128,192,256}-CBC
    +1573  * @since keyutil 1.0.4
    +1574  * @description
    +1575  * <dl>
    +1576  * <dt><b>NOTE1:</b>
    +1577  * <dd>
    +1578  * PKCS#5 encrypted private key protection algorithm supports DES-CBC, 
    +1579  * DES-EDE3-CBC and AES-{128,192,256}-CBC
    +1580  * <dt><b>NOTE2:</b>
    +1581  * <dd>
    +1582  * OpenSSL supports
    +1583  * </dl>
    +1584  * @example
    +1585  * KEUUTIL.getPEM(publicKey) => generates PEM PKCS#8 public key 
    +1586  * KEUUTIL.getPEM(privateKey, "PKCS1PRV") => generates PEM PKCS#1 plain private key
    +1587  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass") => generates PEM PKCS#5 encrypted private key 
    +1588  *                                                          with DES-EDE3-CBC (DEFAULT)
    +1589  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass", "DES-CBC") => generates PEM PKCS#5 encrypted 
    +1590  *                                                                 private key with DES-CBC
    +1591  * KEUUTIL.getPEM(privateKey, "PKCS8PRV") => generates PEM PKCS#8 plain private key
    +1592  * KEUUTIL.getPEM(privateKey, "PKCS8PRV", "pass") => generates PEM PKCS#8 encrypted private key
    +1593  *                                                      with PBKDF2_HmacSHA1_3DES
    +1594  */
    +1595 KEYUTIL.getPEM = function(keyObjOrHex, formatType, passwd, encAlg, hexType) {
    +1596     var ns1 = KJUR.asn1;
    +1597     var ns2 = KJUR.crypto;
    +1598 
    +1599     function _rsaprv2asn1obj(keyObjOrHex) {
    +1600         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    +1601             "seq": [
    +1602                 {"int": 0 },
    +1603                 {"int": {"bigint": keyObjOrHex.n}},
    +1604                 {"int": keyObjOrHex.e},
    +1605                 {"int": {"bigint": keyObjOrHex.d}},
    +1606                 {"int": {"bigint": keyObjOrHex.p}},
    +1607                 {"int": {"bigint": keyObjOrHex.q}},
    +1608                 {"int": {"bigint": keyObjOrHex.dmp1}},
    +1609                 {"int": {"bigint": keyObjOrHex.dmq1}},
    +1610                 {"int": {"bigint": keyObjOrHex.coeff}}
    +1611             ]
    +1612         });
    +1613         return asn1Obj;
    +1614     };
     1615 
    -1616         var result = {};
    -1617         result.prvKeyObj = prvKey;
    -1618         result.pubKeyObj = pubKey;
    -1619         return result;
    -1620     } else {
    -1621         throw "unknown algorithm: " + alg;
    -1622     }
    -1623 };
    -1624 
    -1625 /**
    -1626  * get PEM formatted private or public key file from a RSA/ECDSA/DSA key object
    -1627  * @name getPEM
    -1628  * @memberOf KEYUTIL
    -1629  * @function
    -1630  * @static
    -1631  * @param {Object} keyObjOrHex key object {@link RSAKey}, {@link KJUR.crypto.ECDSA} or {@link KJUR.crypto.DSA} to encode to
    -1632  * @param {String} formatType (OPTION) output format type of "PKCS1PRV", "PKCS5PRV" or "PKCS8PRV" for private key
    -1633  * @param {String} passwd (OPTION) password to protect private key
    -1634  * @param {String} encAlg (OPTION) encryption algorithm for PKCS#5. currently supports DES-CBC, DES-EDE3-CBC and AES-{128,192,256}-CBC
    -1635  * @since keyutil 1.0.4
    -1636  * @description
    -1637  * <dl>
    -1638  * <dt><b>NOTE1:</b>
    -1639  * <dd>
    -1640  * PKCS#5 encrypted private key protection algorithm supports DES-CBC, 
    -1641  * DES-EDE3-CBC and AES-{128,192,256}-CBC
    -1642  * <dt><b>NOTE2:</b>
    -1643  * <dd>
    -1644  * OpenSSL supports
    -1645  * </dl>
    -1646  * @example
    -1647  * KEUUTIL.getPEM(publicKey) => generates PEM PKCS#8 public key 
    -1648  * KEUUTIL.getPEM(privateKey, "PKCS1PRV") => generates PEM PKCS#1 plain private key
    -1649  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass") => generates PEM PKCS#5 encrypted private key 
    -1650  *                                                          with DES-EDE3-CBC (DEFAULT)
    -1651  * KEUUTIL.getPEM(privateKey, "PKCS5PRV", "pass", "DES-CBC") => generates PEM PKCS#5 encrypted 
    -1652  *                                                                 private key with DES-CBC
    -1653  * KEUUTIL.getPEM(privateKey, "PKCS8PRV") => generates PEM PKCS#8 plain private key
    -1654  * KEUUTIL.getPEM(privateKey, "PKCS8PRV", "pass") => generates PEM PKCS#8 encrypted private key
    -1655  *                                                      with PBKDF2_HmacSHA1_3DES
    -1656  */
    -1657 KEYUTIL.getPEM = function(keyObjOrHex, formatType, passwd, encAlg, hexType) {
    -1658     var ns1 = KJUR.asn1;
    -1659     var ns2 = KJUR.crypto;
    -1660 
    -1661     function _rsaprv2asn1obj(keyObjOrHex) {
    -1662         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    -1663             "seq": [
    -1664                 {"int": 0 },
    -1665                 {"int": {"bigint": keyObjOrHex.n}},
    -1666                 {"int": keyObjOrHex.e},
    -1667                 {"int": {"bigint": keyObjOrHex.d}},
    -1668                 {"int": {"bigint": keyObjOrHex.p}},
    -1669                 {"int": {"bigint": keyObjOrHex.q}},
    -1670                 {"int": {"bigint": keyObjOrHex.dmp1}},
    -1671                 {"int": {"bigint": keyObjOrHex.dmq1}},
    -1672                 {"int": {"bigint": keyObjOrHex.coeff}}
    -1673             ]
    -1674         });
    -1675         return asn1Obj;
    -1676     };
    -1677 
    -1678     function _ecdsaprv2asn1obj(keyObjOrHex) {
    -1679         var asn1Obj2 = KJUR.asn1.ASN1Util.newObject({
    -1680             "seq": [
    -1681                 {"int": 1 },
    -1682                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}},
    -1683                 {"tag": ['a0', true, {'oid': {'name': keyObjOrHex.curveName}}]},
    -1684                 {"tag": ['a1', true, {'bitstr': {'hex': '00' + keyObjOrHex.pubKeyHex}}]}
    -1685             ]
    -1686         });
    -1687         return asn1Obj2;
    -1688     };
    -1689 
    -1690     function _dsaprv2asn1obj(keyObjOrHex) {
    -1691         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    -1692             "seq": [
    -1693                 {"int": 0 },
    -1694                 {"int": {"bigint": keyObjOrHex.p}},
    -1695                 {"int": {"bigint": keyObjOrHex.q}},
    -1696                 {"int": {"bigint": keyObjOrHex.g}},
    -1697                 {"int": {"bigint": keyObjOrHex.y}},
    -1698                 {"int": {"bigint": keyObjOrHex.x}}
    -1699             ]
    -1700         });
    -1701         return asn1Obj;
    -1702     };
    -1703 
    -1704     // 1. public key
    -1705 
    -1706     // x. PEM PKCS#8 public key of RSA/ECDSA/DSA public key object
    -1707     if (((typeof RSAKey != "undefined" && keyObjOrHex instanceof RSAKey) ||
    -1708          (typeof ns2.DSA != "undefined" && keyObjOrHex instanceof ns2.DSA) ||
    -1709          (typeof ns2.ECDSA != "undefined" && keyObjOrHex instanceof ns2.ECDSA)) &&
    -1710         keyObjOrHex.isPublic == true &&
    -1711         (formatType === undefined || formatType == "PKCS8PUB")) {
    -1712         var asn1Obj = new KJUR.asn1.x509.SubjectPublicKeyInfo(keyObjOrHex);
    -1713         var asn1Hex = asn1Obj.getEncodedHex();
    -1714         return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PUBLIC KEY");
    -1715     }
    -1716     
    -1717     // 2. private
    -1718 
    -1719     // x. PEM PKCS#1 plain private key of RSA private key object
    -1720     if (formatType == "PKCS1PRV" &&
    -1721         typeof RSAKey != "undefined" &&
    -1722         keyObjOrHex instanceof RSAKey &&
    -1723         (passwd === undefined || passwd == null) &&
    -1724         keyObjOrHex.isPrivate  == true) {
    -1725 
    -1726         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
    -1727         var asn1Hex = asn1Obj.getEncodedHex();
    -1728         return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "RSA PRIVATE KEY");
    -1729     }
    -1730 
    -1731     // x. PEM PKCS#1 plain private key of ECDSA private key object
    -1732     if (formatType == "PKCS1PRV" &&
    -1733         typeof RSAKey != "undefined" &&
    -1734         keyObjOrHex instanceof KJUR.crypto.ECDSA &&
    -1735         (passwd === undefined || passwd == null) &&
    -1736         keyObjOrHex.isPrivate  == true) {
    -1737 
    -1738         var asn1Obj1 = new KJUR.asn1.DERObjectIdentifier({'name': keyObjOrHex.curveName});
    -1739         var asn1Hex1 = asn1Obj1.getEncodedHex();
    -1740         var asn1Obj2 = _ecdsaprv2asn1obj(keyObjOrHex);
    -1741         var asn1Hex2 = asn1Obj2.getEncodedHex();
    +1616     function _ecdsaprv2asn1obj(keyObjOrHex) {
    +1617         var asn1Obj2 = KJUR.asn1.ASN1Util.newObject({
    +1618             "seq": [
    +1619                 {"int": 1 },
    +1620                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}},
    +1621                 {"tag": ['a0', true, {'oid': {'name': keyObjOrHex.curveName}}]},
    +1622                 {"tag": ['a1', true, {'bitstr': {'hex': '00' + keyObjOrHex.pubKeyHex}}]}
    +1623             ]
    +1624         });
    +1625         return asn1Obj2;
    +1626     };
    +1627 
    +1628     function _dsaprv2asn1obj(keyObjOrHex) {
    +1629         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    +1630             "seq": [
    +1631                 {"int": 0 },
    +1632                 {"int": {"bigint": keyObjOrHex.p}},
    +1633                 {"int": {"bigint": keyObjOrHex.q}},
    +1634                 {"int": {"bigint": keyObjOrHex.g}},
    +1635                 {"int": {"bigint": keyObjOrHex.y}},
    +1636                 {"int": {"bigint": keyObjOrHex.x}}
    +1637             ]
    +1638         });
    +1639         return asn1Obj;
    +1640     };
    +1641 
    +1642     // 1. public key
    +1643 
    +1644     // x. PEM PKCS#8 public key of RSA/ECDSA/DSA public key object
    +1645     if (((typeof RSAKey != "undefined" && keyObjOrHex instanceof RSAKey) ||
    +1646          (typeof ns2.DSA != "undefined" && keyObjOrHex instanceof ns2.DSA) ||
    +1647          (typeof ns2.ECDSA != "undefined" && keyObjOrHex instanceof ns2.ECDSA)) &&
    +1648         keyObjOrHex.isPublic == true &&
    +1649         (formatType === undefined || formatType == "PKCS8PUB")) {
    +1650         var asn1Obj = new KJUR.asn1.x509.SubjectPublicKeyInfo(keyObjOrHex);
    +1651         var asn1Hex = asn1Obj.getEncodedHex();
    +1652         return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PUBLIC KEY");
    +1653     }
    +1654     
    +1655     // 2. private
    +1656 
    +1657     // x. PEM PKCS#1 plain private key of RSA private key object
    +1658     if (formatType == "PKCS1PRV" &&
    +1659         typeof RSAKey != "undefined" &&
    +1660         keyObjOrHex instanceof RSAKey &&
    +1661         (passwd === undefined || passwd == null) &&
    +1662         keyObjOrHex.isPrivate  == true) {
    +1663 
    +1664         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
    +1665         var asn1Hex = asn1Obj.getEncodedHex();
    +1666         return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "RSA PRIVATE KEY");
    +1667     }
    +1668 
    +1669     // x. PEM PKCS#1 plain private key of ECDSA private key object
    +1670     if (formatType == "PKCS1PRV" &&
    +1671         typeof RSAKey != "undefined" &&
    +1672         keyObjOrHex instanceof KJUR.crypto.ECDSA &&
    +1673         (passwd === undefined || passwd == null) &&
    +1674         keyObjOrHex.isPrivate  == true) {
    +1675 
    +1676         var asn1Obj1 = new KJUR.asn1.DERObjectIdentifier({'name': keyObjOrHex.curveName});
    +1677         var asn1Hex1 = asn1Obj1.getEncodedHex();
    +1678         var asn1Obj2 = _ecdsaprv2asn1obj(keyObjOrHex);
    +1679         var asn1Hex2 = asn1Obj2.getEncodedHex();
    +1680 
    +1681         var s = "";
    +1682         s += ns1.ASN1Util.getPEMStringFromHex(asn1Hex1, "EC PARAMETERS");
    +1683         s += ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "EC PRIVATE KEY");
    +1684         return s;
    +1685     }
    +1686 
    +1687     // x. PEM PKCS#1 plain private key of DSA private key object
    +1688     if (formatType == "PKCS1PRV" &&
    +1689         typeof KJUR.crypto.DSA != "undefined" &&
    +1690         keyObjOrHex instanceof KJUR.crypto.DSA &&
    +1691         (passwd === undefined || passwd == null) &&
    +1692         keyObjOrHex.isPrivate  == true) {
    +1693 
    +1694         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
    +1695         var asn1Hex = asn1Obj.getEncodedHex();
    +1696         return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "DSA PRIVATE KEY");
    +1697     }
    +1698 
    +1699     // 3. private
    +1700 
    +1701     // x. PEM PKCS#5 encrypted private key of RSA private key object
    +1702     if (formatType == "PKCS5PRV" &&
    +1703         typeof RSAKey != "undefined" &&
    +1704         keyObjOrHex instanceof RSAKey &&
    +1705         (passwd !== undefined && passwd != null) &&
    +1706         keyObjOrHex.isPrivate  == true) {
    +1707 
    +1708         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
    +1709         var asn1Hex = asn1Obj.getEncodedHex();
    +1710 
    +1711         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
    +1712         return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA", asn1Hex, passwd, encAlg);
    +1713     }
    +1714 
    +1715     // x. PEM PKCS#5 encrypted private key of ECDSA private key object
    +1716     if (formatType == "PKCS5PRV" &&
    +1717         typeof KJUR.crypto.ECDSA != "undefined" &&
    +1718         keyObjOrHex instanceof KJUR.crypto.ECDSA &&
    +1719         (passwd !== undefined && passwd != null) &&
    +1720         keyObjOrHex.isPrivate  == true) {
    +1721 
    +1722         var asn1Obj = _ecdsaprv2asn1obj(keyObjOrHex);
    +1723         var asn1Hex = asn1Obj.getEncodedHex();
    +1724 
    +1725         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
    +1726         return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC", asn1Hex, passwd, encAlg);
    +1727     }
    +1728 
    +1729     // x. PEM PKCS#5 encrypted private key of DSA private key object
    +1730     if (formatType == "PKCS5PRV" &&
    +1731         typeof KJUR.crypto.DSA != "undefined" &&
    +1732         keyObjOrHex instanceof KJUR.crypto.DSA &&
    +1733         (passwd !== undefined && passwd != null) &&
    +1734         keyObjOrHex.isPrivate  == true) {
    +1735 
    +1736         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
    +1737         var asn1Hex = asn1Obj.getEncodedHex();
    +1738 
    +1739         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
    +1740         return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA", asn1Hex, passwd, encAlg);
    +1741     }
     1742 
    -1743         var s = "";
    -1744         s += ns1.ASN1Util.getPEMStringFromHex(asn1Hex1, "EC PARAMETERS");
    -1745         s += ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "EC PRIVATE KEY");
    -1746         return s;
    -1747     }
    -1748 
    -1749     // x. PEM PKCS#1 plain private key of DSA private key object
    -1750     if (formatType == "PKCS1PRV" &&
    -1751         typeof KJUR.crypto.DSA != "undefined" &&
    -1752         keyObjOrHex instanceof KJUR.crypto.DSA &&
    -1753         (passwd === undefined || passwd == null) &&
    -1754         keyObjOrHex.isPrivate  == true) {
    -1755 
    -1756         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
    -1757         var asn1Hex = asn1Obj.getEncodedHex();
    -1758         return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "DSA PRIVATE KEY");
    -1759     }
    -1760 
    -1761     // 3. private
    -1762 
    -1763     // x. PEM PKCS#5 encrypted private key of RSA private key object
    -1764     if (formatType == "PKCS5PRV" &&
    -1765         typeof RSAKey != "undefined" &&
    -1766         keyObjOrHex instanceof RSAKey &&
    -1767         (passwd !== undefined && passwd != null) &&
    -1768         keyObjOrHex.isPrivate  == true) {
    -1769 
    -1770         var asn1Obj = _rsaprv2asn1obj(keyObjOrHex);
    -1771         var asn1Hex = asn1Obj.getEncodedHex();
    +1743     // x. ======================================================================
    +1744 
    +1745     var _getEncryptedPKCS8 = function(plainKeyHex, passcode) {
    +1746         var info = _getEencryptedPKCS8Info(plainKeyHex, passcode);
    +1747         //alert("iv=" + info.encryptionSchemeIV);
    +1748         //alert("info.ciphertext2[" + info.ciphertext.length + "=" + info.ciphertext);
    +1749         var asn1Obj = new KJUR.asn1.ASN1Util.newObject({
    +1750             "seq": [
    +1751                 {"seq": [
    +1752                     {"oid": {"name": "pkcs5PBES2"}},
    +1753                     {"seq": [
    +1754                         {"seq": [
    +1755                             {"oid": {"name": "pkcs5PBKDF2"}},
    +1756                             {"seq": [
    +1757                                 {"octstr": {"hex": info.pbkdf2Salt}},
    +1758                                 {"int": info.pbkdf2Iter}
    +1759                             ]}
    +1760                         ]},
    +1761                         {"seq": [
    +1762                             {"oid": {"name": "des-EDE3-CBC"}},
    +1763                             {"octstr": {"hex": info.encryptionSchemeIV}}
    +1764                         ]}
    +1765                     ]}
    +1766                 ]},
    +1767                 {"octstr": {"hex": info.ciphertext}}
    +1768             ]
    +1769         });
    +1770         return asn1Obj.getEncodedHex();
    +1771     };
     1772 
    -1773         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
    -1774         return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA", asn1Hex, passwd, encAlg);
    -1775     }
    -1776 
    -1777     // x. PEM PKCS#5 encrypted private key of ECDSA private key object
    -1778     if (formatType == "PKCS5PRV" &&
    -1779         typeof KJUR.crypto.ECDSA != "undefined" &&
    -1780         keyObjOrHex instanceof KJUR.crypto.ECDSA &&
    -1781         (passwd !== undefined && passwd != null) &&
    -1782         keyObjOrHex.isPrivate  == true) {
    -1783 
    -1784         var asn1Obj = _ecdsaprv2asn1obj(keyObjOrHex);
    -1785         var asn1Hex = asn1Obj.getEncodedHex();
    +1773     var _getEencryptedPKCS8Info = function(plainKeyHex, passcode) {
    +1774         var pbkdf2Iter = 100;
    +1775         var pbkdf2SaltWS = CryptoJS.lib.WordArray.random(8);
    +1776         var encryptionSchemeAlg = "DES-EDE3-CBC";
    +1777         var encryptionSchemeIVWS = CryptoJS.lib.WordArray.random(8);
    +1778         // PBKDF2 key
    +1779         var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
    +1780                                           pbkdf2SaltWS, { "keySize": 192/32,
    +1781                                                           "iterations": pbkdf2Iter });
    +1782         // ENCRYPT
    +1783         var plainKeyWS = CryptoJS.enc.Hex.parse(plainKeyHex);
    +1784         var encryptedKeyHex = 
    +1785             CryptoJS.TripleDES.encrypt(plainKeyWS, pbkdf2KeyWS, { "iv": encryptionSchemeIVWS }) + "";
     1786 
    -1787         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
    -1788         return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC", asn1Hex, passwd, encAlg);
    -1789     }
    -1790 
    -1791     // x. PEM PKCS#5 encrypted private key of DSA private key object
    -1792     if (formatType == "PKCS5PRV" &&
    -1793         typeof KJUR.crypto.DSA != "undefined" &&
    -1794         keyObjOrHex instanceof KJUR.crypto.DSA &&
    -1795         (passwd !== undefined && passwd != null) &&
    -1796         keyObjOrHex.isPrivate  == true) {
    -1797 
    -1798         var asn1Obj = _dsaprv2asn1obj(keyObjOrHex);
    -1799         var asn1Hex = asn1Obj.getEncodedHex();
    -1800 
    -1801         if (encAlg === undefined) encAlg = "DES-EDE3-CBC";
    -1802         return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA", asn1Hex, passwd, encAlg);
    -1803     }
    +1787         //alert("encryptedKeyHex=" + encryptedKeyHex);
    +1788 
    +1789         var info = {};
    +1790         info.ciphertext = encryptedKeyHex;
    +1791         //alert("info.ciphertext=" + info.ciphertext);
    +1792         info.pbkdf2Salt = CryptoJS.enc.Hex.stringify(pbkdf2SaltWS);
    +1793         info.pbkdf2Iter = pbkdf2Iter;
    +1794         info.encryptionSchemeAlg = encryptionSchemeAlg;
    +1795         info.encryptionSchemeIV = CryptoJS.enc.Hex.stringify(encryptionSchemeIVWS);
    +1796         return info;
    +1797     };
    +1798 
    +1799     // x. PEM PKCS#8 plain private key of RSA private key object
    +1800     if (formatType == "PKCS8PRV" &&
    +1801         typeof RSAKey != "undefined" &&
    +1802         keyObjOrHex instanceof RSAKey &&
    +1803         keyObjOrHex.isPrivate  == true) {
     1804 
    -1805     // x. ======================================================================
    -1806 
    -1807     var _getEncryptedPKCS8 = function(plainKeyHex, passcode) {
    -1808         var info = _getEencryptedPKCS8Info(plainKeyHex, passcode);
    -1809         //alert("iv=" + info.encryptionSchemeIV);
    -1810         //alert("info.ciphertext2[" + info.ciphertext.length + "=" + info.ciphertext);
    -1811         var asn1Obj = new KJUR.asn1.ASN1Util.newObject({
    -1812             "seq": [
    -1813                 {"seq": [
    -1814                     {"oid": {"name": "pkcs5PBES2"}},
    -1815                     {"seq": [
    -1816                         {"seq": [
    -1817                             {"oid": {"name": "pkcs5PBKDF2"}},
    -1818                             {"seq": [
    -1819                                 {"octstr": {"hex": info.pbkdf2Salt}},
    -1820                                 {"int": info.pbkdf2Iter}
    -1821                             ]}
    -1822                         ]},
    -1823                         {"seq": [
    -1824                             {"oid": {"name": "des-EDE3-CBC"}},
    -1825                             {"octstr": {"hex": info.encryptionSchemeIV}}
    -1826                         ]}
    -1827                     ]}
    -1828                 ]},
    -1829                 {"octstr": {"hex": info.ciphertext}}
    -1830             ]
    -1831         });
    -1832         return asn1Obj.getEncodedHex();
    -1833     };
    -1834 
    -1835     var _getEencryptedPKCS8Info = function(plainKeyHex, passcode) {
    -1836         var pbkdf2Iter = 100;
    -1837         var pbkdf2SaltWS = CryptoJS.lib.WordArray.random(8);
    -1838         var encryptionSchemeAlg = "DES-EDE3-CBC";
    -1839         var encryptionSchemeIVWS = CryptoJS.lib.WordArray.random(8);
    -1840         // PBKDF2 key
    -1841         var pbkdf2KeyWS = CryptoJS.PBKDF2(passcode, 
    -1842                                           pbkdf2SaltWS, { "keySize": 192/32,
    -1843                                                           "iterations": pbkdf2Iter });
    -1844         // ENCRYPT
    -1845         var plainKeyWS = CryptoJS.enc.Hex.parse(plainKeyHex);
    -1846         var encryptedKeyHex = 
    -1847             CryptoJS.TripleDES.encrypt(plainKeyWS, pbkdf2KeyWS, { "iv": encryptionSchemeIVWS }) + "";
    -1848 
    -1849         //alert("encryptedKeyHex=" + encryptedKeyHex);
    +1805         var keyObj = _rsaprv2asn1obj(keyObjOrHex);
    +1806         var keyHex = keyObj.getEncodedHex();
    +1807 
    +1808         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    +1809             "seq": [
    +1810                 {"int": 0},
    +1811                 {"seq": [{"oid": {"name": "rsaEncryption"}},{"null": true}]},
    +1812                 {"octstr": {"hex": keyHex}}
    +1813             ]
    +1814         });
    +1815         var asn1Hex = asn1Obj.getEncodedHex();
    +1816 
    +1817         if (passwd === undefined || passwd == null) {
    +1818             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PRIVATE KEY");
    +1819         } else {
    +1820             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
    +1821             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "ENCRYPTED PRIVATE KEY");
    +1822         }
    +1823     }
    +1824 
    +1825     // x. PEM PKCS#8 plain private key of ECDSA private key object
    +1826     if (formatType == "PKCS8PRV" &&
    +1827         typeof KJUR.crypto.ECDSA != "undefined" &&
    +1828         keyObjOrHex instanceof KJUR.crypto.ECDSA &&
    +1829         keyObjOrHex.isPrivate  == true) {
    +1830 
    +1831         var keyObj = new KJUR.asn1.ASN1Util.newObject({
    +1832             "seq": [
    +1833                 {"int": 1},
    +1834                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}},
    +1835                 {"tag": ['a1', true, {"bitstr": {"hex": "00" + keyObjOrHex.pubKeyHex}}]}
    +1836             ]
    +1837         });
    +1838         var keyHex = keyObj.getEncodedHex();
    +1839 
    +1840         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    +1841             "seq": [
    +1842                 {"int": 0},
    +1843                 {"seq": [
    +1844                     {"oid": {"name": "ecPublicKey"}},
    +1845                     {"oid": {"name": keyObjOrHex.curveName}}
    +1846                 ]},
    +1847                 {"octstr": {"hex": keyHex}}
    +1848             ]
    +1849         });
     1850 
    -1851         var info = {};
    -1852         info.ciphertext = encryptedKeyHex;
    -1853         //alert("info.ciphertext=" + info.ciphertext);
    -1854         info.pbkdf2Salt = CryptoJS.enc.Hex.stringify(pbkdf2SaltWS);
    -1855         info.pbkdf2Iter = pbkdf2Iter;
    -1856         info.encryptionSchemeAlg = encryptionSchemeAlg;
    -1857         info.encryptionSchemeIV = CryptoJS.enc.Hex.stringify(encryptionSchemeIVWS);
    -1858         return info;
    -1859     };
    -1860 
    -1861     // x. PEM PKCS#8 plain private key of RSA private key object
    -1862     if (formatType == "PKCS8PRV" &&
    -1863         typeof RSAKey != "undefined" &&
    -1864         keyObjOrHex instanceof RSAKey &&
    -1865         keyObjOrHex.isPrivate  == true) {
    -1866 
    -1867         var keyObj = _rsaprv2asn1obj(keyObjOrHex);
    -1868         var keyHex = keyObj.getEncodedHex();
    -1869 
    -1870         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    -1871             "seq": [
    -1872                 {"int": 0},
    -1873                 {"seq": [{"oid": {"name": "rsaEncryption"}},{"null": true}]},
    -1874                 {"octstr": {"hex": keyHex}}
    -1875             ]
    -1876         });
    -1877         var asn1Hex = asn1Obj.getEncodedHex();
    -1878 
    -1879         if (passwd === undefined || passwd == null) {
    -1880             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PRIVATE KEY");
    -1881         } else {
    -1882             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
    -1883             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "ENCRYPTED PRIVATE KEY");
    -1884         }
    -1885     }
    -1886 
    -1887     // x. PEM PKCS#8 plain private key of ECDSA private key object
    -1888     if (formatType == "PKCS8PRV" &&
    -1889         typeof KJUR.crypto.ECDSA != "undefined" &&
    -1890         keyObjOrHex instanceof KJUR.crypto.ECDSA &&
    -1891         keyObjOrHex.isPrivate  == true) {
    +1851         var asn1Hex = asn1Obj.getEncodedHex();
    +1852         if (passwd === undefined || passwd == null) {
    +1853             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PRIVATE KEY");
    +1854         } else {
    +1855             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
    +1856             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "ENCRYPTED PRIVATE KEY");
    +1857         }
    +1858     }
    +1859 
    +1860     // x. PEM PKCS#8 plain private key of DSA private key object
    +1861     if (formatType == "PKCS8PRV" &&
    +1862         typeof KJUR.crypto.DSA != "undefined" &&
    +1863         keyObjOrHex instanceof KJUR.crypto.DSA &&
    +1864         keyObjOrHex.isPrivate  == true) {
    +1865 
    +1866         var keyObj = new KJUR.asn1.DERInteger({'bigint': keyObjOrHex.x});
    +1867         var keyHex = keyObj.getEncodedHex();
    +1868 
    +1869         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    +1870             "seq": [
    +1871                 {"int": 0},
    +1872                 {"seq": [
    +1873                     {"oid": {"name": "dsa"}},
    +1874                     {"seq": [
    +1875                         {"int": {"bigint": keyObjOrHex.p}},
    +1876                         {"int": {"bigint": keyObjOrHex.q}},
    +1877                         {"int": {"bigint": keyObjOrHex.g}}
    +1878                     ]}
    +1879                 ]},
    +1880                 {"octstr": {"hex": keyHex}}
    +1881             ]
    +1882         });
    +1883 
    +1884         var asn1Hex = asn1Obj.getEncodedHex();
    +1885         if (passwd === undefined || passwd == null) {
    +1886             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PRIVATE KEY");
    +1887         } else {
    +1888             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
    +1889             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "ENCRYPTED PRIVATE KEY");
    +1890         }
    +1891     }
     1892 
    -1893         var keyObj = new KJUR.asn1.ASN1Util.newObject({
    -1894             "seq": [
    -1895                 {"int": 1},
    -1896                 {"octstr": {"hex": keyObjOrHex.prvKeyHex}},
    -1897                 {"tag": ['a1', true, {"bitstr": {"hex": "00" + keyObjOrHex.pubKeyHex}}]}
    -1898             ]
    -1899         });
    -1900         var keyHex = keyObj.getEncodedHex();
    -1901 
    -1902         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    -1903             "seq": [
    -1904                 {"int": 0},
    -1905                 {"seq": [
    -1906                     {"oid": {"name": "ecPublicKey"}},
    -1907                     {"oid": {"name": keyObjOrHex.curveName}}
    -1908                 ]},
    -1909                 {"octstr": {"hex": keyHex}}
    -1910             ]
    -1911         });
    +1893     throw "unsupported object nor format";
    +1894 };
    +1895 
    +1896 // -- PUBLIC METHODS FOR CSR -------------------------------------------------------
    +1897 
    +1898 /**
    +1899  * get RSAKey/DSA/ECDSA public key object from PEM formatted PKCS#10 CSR string
    +1900  * @name getKeyFromCSRPEM
    +1901  * @memberOf KEYUTIL
    +1902  * @function
    +1903  * @param {String} csrPEM PEM formatted PKCS#10 CSR string
    +1904  * @return {Object} RSAKey/DSA/ECDSA public key object
    +1905  * @since keyutil 1.0.5
    +1906  */
    +1907 KEYUTIL.getKeyFromCSRPEM = function(csrPEM) {
    +1908     var csrHex = ASN1HEX.pemToHex(csrPEM, "CERTIFICATE REQUEST");
    +1909     var key = KEYUTIL.getKeyFromCSRHex(csrHex);
    +1910     return key;
    +1911 };
     1912 
    -1913         var asn1Hex = asn1Obj.getEncodedHex();
    -1914         if (passwd === undefined || passwd == null) {
    -1915             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PRIVATE KEY");
    -1916         } else {
    -1917             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
    -1918             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "ENCRYPTED PRIVATE KEY");
    -1919         }
    -1920     }
    -1921 
    -1922     // x. PEM PKCS#8 plain private key of DSA private key object
    -1923     if (formatType == "PKCS8PRV" &&
    -1924         typeof KJUR.crypto.DSA != "undefined" &&
    -1925         keyObjOrHex instanceof KJUR.crypto.DSA &&
    -1926         keyObjOrHex.isPrivate  == true) {
    +1913 /**
    +1914  * get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#10 CSR
    +1915  * @name getKeyFromCSRHex
    +1916  * @memberOf KEYUTIL
    +1917  * @function
    +1918  * @param {String} csrHex hexadecimal string of PKCS#10 CSR
    +1919  * @return {Object} RSAKey/DSA/ECDSA public key object
    +1920  * @since keyutil 1.0.5
    +1921  */
    +1922 KEYUTIL.getKeyFromCSRHex = function(csrHex) {
    +1923     var info = KEYUTIL.parseCSRHex(csrHex);
    +1924     var key = KEYUTIL.getKey(info.p8pubkeyhex, null, "pkcs8pub");
    +1925     return key;
    +1926 };
     1927 
    -1928         var keyObj = new KJUR.asn1.DERInteger({'bigint': keyObjOrHex.x});
    -1929         var keyHex = keyObj.getEncodedHex();
    -1930 
    -1931         var asn1Obj = KJUR.asn1.ASN1Util.newObject({
    -1932             "seq": [
    -1933                 {"int": 0},
    -1934                 {"seq": [
    -1935                     {"oid": {"name": "dsa"}},
    -1936                     {"seq": [
    -1937                         {"int": {"bigint": keyObjOrHex.p}},
    -1938                         {"int": {"bigint": keyObjOrHex.q}},
    -1939                         {"int": {"bigint": keyObjOrHex.g}}
    -1940                     ]}
    -1941                 ]},
    -1942                 {"octstr": {"hex": keyHex}}
    -1943             ]
    -1944         });
    +1928 /**
    +1929  * parse hexadecimal string of PKCS#10 CSR (certificate signing request)
    +1930  * @name parseCSRHex
    +1931  * @memberOf KEYUTIL
    +1932  * @function
    +1933  * @param {String} csrHex hexadecimal string of PKCS#10 CSR
    +1934  * @return {Array} associative array of parsed CSR
    +1935  * @since keyutil 1.0.5
    +1936  * @description
    +1937  * Resulted associative array has following properties:
    +1938  * <ul>
    +1939  * <li>p8pubkeyhex - hexadecimal string of subject public key in PKCS#8</li>
    +1940  * </ul>
    +1941  */
    +1942 KEYUTIL.parseCSRHex = function(csrHex) {
    +1943     var result = {};
    +1944     var h = csrHex;
     1945 
    -1946         var asn1Hex = asn1Obj.getEncodedHex();
    -1947         if (passwd === undefined || passwd == null) {
    -1948             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex, "PRIVATE KEY");
    -1949         } else {
    -1950             var asn1Hex2 = _getEncryptedPKCS8(asn1Hex, passwd);
    -1951             return ns1.ASN1Util.getPEMStringFromHex(asn1Hex2, "ENCRYPTED PRIVATE KEY");
    -1952         }
    -1953     }
    -1954 
    -1955     throw "unsupported object nor format";
    -1956 };
    +1946     // 1. sequence
    +1947     if (h.substr(0, 2) != "30")
    +1948         throw "malformed CSR(code:001)"; // not sequence
    +1949 
    +1950     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    +1951     if (a1.length < 1)
    +1952         throw "malformed CSR(code:002)"; // short length
    +1953 
    +1954     // 2. 2nd sequence
    +1955     if (h.substr(a1[0], 2) != "30")
    +1956         throw "malformed CSR(code:003)"; // not sequence
     1957 
    -1958 // -- PUBLIC METHODS FOR CSR -------------------------------------------------------
    -1959 
    -1960 /**
    -1961  * get RSAKey/DSA/ECDSA public key object from PEM formatted PKCS#10 CSR string
    -1962  * @name getKeyFromCSRPEM
    -1963  * @memberOf KEYUTIL
    -1964  * @function
    -1965  * @param {String} csrPEM PEM formatted PKCS#10 CSR string
    -1966  * @return {Object} RSAKey/DSA/ECDSA public key object
    -1967  * @since keyutil 1.0.5
    -1968  */
    -1969 KEYUTIL.getKeyFromCSRPEM = function(csrPEM) {
    -1970     var csrHex = KEYUTIL.getHexFromPEM(csrPEM, "CERTIFICATE REQUEST");
    -1971     var key = KEYUTIL.getKeyFromCSRHex(csrHex);
    -1972     return key;
    -1973 };
    -1974 
    -1975 /**
    -1976  * get RSAKey/DSA/ECDSA public key object from hexadecimal string of PKCS#10 CSR
    -1977  * @name getKeyFromCSRHex
    -1978  * @memberOf KEYUTIL
    -1979  * @function
    -1980  * @param {String} csrHex hexadecimal string of PKCS#10 CSR
    -1981  * @return {Object} RSAKey/DSA/ECDSA public key object
    -1982  * @since keyutil 1.0.5
    -1983  */
    -1984 KEYUTIL.getKeyFromCSRHex = function(csrHex) {
    -1985     var info = KEYUTIL.parseCSRHex(csrHex);
    -1986     var key = KEYUTIL.getKey(info.p8pubkeyhex, null, "pkcs8pub");
    -1987     return key;
    -1988 };
    -1989 
    -1990 /**
    -1991  * parse hexadecimal string of PKCS#10 CSR (certificate signing request)
    -1992  * @name parseCSRHex
    -1993  * @memberOf KEYUTIL
    -1994  * @function
    -1995  * @param {String} csrHex hexadecimal string of PKCS#10 CSR
    -1996  * @return {Array} associative array of parsed CSR
    -1997  * @since keyutil 1.0.5
    -1998  * @description
    -1999  * Resulted associative array has following properties:
    -2000  * <ul>
    -2001  * <li>p8pubkeyhex - hexadecimal string of subject public key in PKCS#8</li>
    -2002  * </ul>
    -2003  */
    -2004 KEYUTIL.parseCSRHex = function(csrHex) {
    -2005     var result = {};
    -2006     var h = csrHex;
    -2007 
    -2008     // 1. sequence
    -2009     if (h.substr(0, 2) != "30")
    -2010         throw "malformed CSR(code:001)"; // not sequence
    -2011 
    -2012     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    -2013     if (a1.length < 1)
    -2014         throw "malformed CSR(code:002)"; // short length
    -2015 
    -2016     // 2. 2nd sequence
    -2017     if (h.substr(a1[0], 2) != "30")
    -2018         throw "malformed CSR(code:003)"; // not sequence
    -2019 
    -2020     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(h, a1[0]);
    -2021     if (a2.length < 3)
    -2022         throw "malformed CSR(code:004)"; // 2nd seq short elem
    -2023 
    -2024     result.p8pubkeyhex = ASN1HEX.getHexOfTLV_AtObj(h, a2[2]);
    -2025 
    -2026     return result;
    -2027 };
    -2028 
    -2029 // -- OTHER STATIC PUBLIC METHODS  -------------------------------------------------
    -2030 
    -2031 /**
    -2032  * convert from RSAKey/KJUR.crypto.ECDSA public/private key object to RFC 7517 JSON Web Key(JWK)
    -2033  * @name getJWKFromKey
    -2034  * @memberOf KEYUTIL
    -2035  * @function
    -2036  * @static
    -2037  * @param {Object} RSAKey/KJUR.crypto.ECDSA public/private key object
    -2038  * @return {Object} JWK object
    -2039  * @since keyutil 1.0.13 jsrsasign 5.0.14
    -2040  * @description
    -2041  * This static method convert from RSAKey/KJUR.crypto.ECDSA public/private key object 
    -2042  * to RFC 7517 JSON Web Key(JWK)
    -2043  * @example
    -2044  * kp1 = KEYUTIL.generateKeypair("EC", "P-256");
    -2045  * jwkPrv1 = KEYUTIL.getJWKFromKey(kp1.prvKeyObj);
    -2046  * jwkPub1 = KEYUTIL.getJWKFromKey(kp1.pubKeyObj);
    -2047  *
    -2048  * kp2 = KEYUTIL.generateKeypair("RSA", 2048);
    -2049  * jwkPrv2 = KEYUTIL.getJWKFromKey(kp2.prvKeyObj);
    -2050  * jwkPub2 = KEYUTIL.getJWKFromKey(kp2.pubKeyObj);
    -2051  *
    -2052  * // if you need RFC 7636 JWK thumprint as kid do like this:
    -2053  * jwkPub2.kid = KJUR.jws.JWS.getJWKthumbprint(jwkPub2);
    -2054  */
    -2055 KEYUTIL.getJWKFromKey = function(keyObj) {
    -2056     var jwk = {};
    -2057     if (keyObj instanceof RSAKey && keyObj.isPrivate) {
    -2058 	jwk.kty = "RSA";
    -2059 	jwk.n = hextob64u(keyObj.n.toString(16));
    -2060 	jwk.e = hextob64u(keyObj.e.toString(16));
    -2061 	jwk.d = hextob64u(keyObj.d.toString(16));
    -2062 	jwk.p = hextob64u(keyObj.p.toString(16));
    -2063 	jwk.q = hextob64u(keyObj.q.toString(16));
    -2064 	jwk.dp = hextob64u(keyObj.dmp1.toString(16));
    -2065 	jwk.dq = hextob64u(keyObj.dmq1.toString(16));
    -2066 	jwk.qi = hextob64u(keyObj.coeff.toString(16));
    -2067 	return jwk;
    -2068     } else if (keyObj instanceof RSAKey && keyObj.isPublic) {
    -2069 	jwk.kty = "RSA";
    -2070 	jwk.n = hextob64u(keyObj.n.toString(16));
    -2071 	jwk.e = hextob64u(keyObj.e.toString(16));
    -2072 	return jwk;
    -2073     } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPrivate) {
    -2074 	var name = keyObj.getShortNISTPCurveName();
    -2075 	if (name !== "P-256" && name !== "P-384")
    -2076 	    throw "unsupported curve name for JWT: " + name;
    -2077 	var xy = keyObj.getPublicKeyXYHex();
    -2078 	jwk.kty = "EC";
    -2079 	jwk.crv =  name;
    -2080 	jwk.x = hextob64u(xy.x);
    -2081 	jwk.y = hextob64u(xy.y);
    -2082 	jwk.d = hextob64u(keyObj.prvKeyHex);
    -2083 	return jwk;
    -2084     } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPublic) {
    -2085 	var name = keyObj.getShortNISTPCurveName();
    -2086 	if (name !== "P-256" && name !== "P-384")
    -2087 	    throw "unsupported curve name for JWT: " + name;
    -2088 	var xy = keyObj.getPublicKeyXYHex();
    -2089 	jwk.kty = "EC";
    -2090 	jwk.crv =  name;
    -2091 	jwk.x = hextob64u(xy.x);
    -2092 	jwk.y = hextob64u(xy.y);
    -2093 	return jwk;
    -2094     }
    -2095     throw "not supported key object";
    -2096 };
    -2097 
    -2098 
    -2099 
    \ No newline at end of file +1958
    var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(h, a1[0]); +1959 if (a2.length < 3) +1960 throw "malformed CSR(code:004)"; // 2nd seq short elem +1961 +1962 result.p8pubkeyhex = ASN1HEX.getHexOfTLV_AtObj(h, a2[2]); +1963 +1964 return result; +1965 }; +1966 +1967 // -- OTHER STATIC PUBLIC METHODS ------------------------------------------------- +1968 +1969 /** +1970 * convert from RSAKey/KJUR.crypto.ECDSA public/private key object to RFC 7517 JSON Web Key(JWK) +1971 * @name getJWKFromKey +1972 * @memberOf KEYUTIL +1973 * @function +1974 * @static +1975 * @param {Object} RSAKey/KJUR.crypto.ECDSA public/private key object +1976 * @return {Object} JWK object +1977 * @since keyutil 1.0.13 jsrsasign 5.0.14 +1978 * @description +1979 * This static method convert from RSAKey/KJUR.crypto.ECDSA public/private key object +1980 * to RFC 7517 JSON Web Key(JWK) +1981 * @example +1982 * kp1 = KEYUTIL.generateKeypair("EC", "P-256"); +1983 * jwkPrv1 = KEYUTIL.getJWKFromKey(kp1.prvKeyObj); +1984 * jwkPub1 = KEYUTIL.getJWKFromKey(kp1.pubKeyObj); +1985 * +1986 * kp2 = KEYUTIL.generateKeypair("RSA", 2048); +1987 * jwkPrv2 = KEYUTIL.getJWKFromKey(kp2.prvKeyObj); +1988 * jwkPub2 = KEYUTIL.getJWKFromKey(kp2.pubKeyObj); +1989 * +1990 * // if you need RFC 7636 JWK thumprint as kid do like this: +1991 * jwkPub2.kid = KJUR.jws.JWS.getJWKthumbprint(jwkPub2); +1992 */ +1993 KEYUTIL.getJWKFromKey = function(keyObj) { +1994 var jwk = {}; +1995 if (keyObj instanceof RSAKey && keyObj.isPrivate) { +1996 jwk.kty = "RSA"; +1997 jwk.n = hextob64u(keyObj.n.toString(16)); +1998 jwk.e = hextob64u(keyObj.e.toString(16)); +1999 jwk.d = hextob64u(keyObj.d.toString(16)); +2000 jwk.p = hextob64u(keyObj.p.toString(16)); +2001 jwk.q = hextob64u(keyObj.q.toString(16)); +2002 jwk.dp = hextob64u(keyObj.dmp1.toString(16)); +2003 jwk.dq = hextob64u(keyObj.dmq1.toString(16)); +2004 jwk.qi = hextob64u(keyObj.coeff.toString(16)); +2005 return jwk; +2006 } else if (keyObj instanceof RSAKey && keyObj.isPublic) { +2007 jwk.kty = "RSA"; +2008 jwk.n = hextob64u(keyObj.n.toString(16)); +2009 jwk.e = hextob64u(keyObj.e.toString(16)); +2010 return jwk; +2011 } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPrivate) { +2012 var name = keyObj.getShortNISTPCurveName(); +2013 if (name !== "P-256" && name !== "P-384") +2014 throw "unsupported curve name for JWT: " + name; +2015 var xy = keyObj.getPublicKeyXYHex(); +2016 jwk.kty = "EC"; +2017 jwk.crv = name; +2018 jwk.x = hextob64u(xy.x); +2019 jwk.y = hextob64u(xy.y); +2020 jwk.d = hextob64u(keyObj.prvKeyHex); +2021 return jwk; +2022 } else if (keyObj instanceof KJUR.crypto.ECDSA && keyObj.isPublic) { +2023 var name = keyObj.getShortNISTPCurveName(); +2024 if (name !== "P-256" && name !== "P-384") +2025 throw "unsupported curve name for JWT: " + name; +2026 var xy = keyObj.getPublicKeyXYHex(); +2027 jwk.kty = "EC"; +2028 jwk.crv = name; +2029 jwk.x = hextob64u(xy.x); +2030 jwk.y = hextob64u(xy.y); +2031 return jwk; +2032 } +2033 throw "not supported key object"; +2034 }; +2035 +2036 +2037
    \ No newline at end of file diff --git a/api/symbols/src/rsapem-1.1.js.html b/api/symbols/src/rsapem-1.1.js.html index 04fd7b4f..3032a0dc 100644 --- a/api/symbols/src/rsapem-1.1.js.html +++ b/api/symbols/src/rsapem-1.1.js.html @@ -5,106 +5,230 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 /*! rsapem-1.1.js (c) 2012 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! rsapem-1.2.0.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
    -  3 //
    -  4 // rsa-pem.js - adding function for reading/writing PKCS#1 PEM private key
    -  5 //              to RSAKey class.
    -  6 //
    -  7 // version: 1.1.1 (2013-Apr-12)
    -  8 //
    -  9 // Copyright (c) 2010-2013 Kenji Urushima (kenji.urushima@gmail.com)
    - 10 //
    - 11 // This software is licensed under the terms of the MIT License.
    - 12 // http://kjur.github.com/jsrsasign/license/
    - 13 //
    - 14 // The above copyright and license notice shall be 
    - 15 // included in all copies or substantial portions of the Software.
    - 16 // 
    - 17 //
    - 18 // Depends on:
    - 19 //
    - 20 //
    - 21 //
    - 22 // _RSApem_pemToBase64(sPEM)
    - 23 //
    - 24 //   removing PEM header, PEM footer and space characters including
    - 25 //   new lines from PEM formatted RSA private key string.
    - 26 //
    - 27 
    - 28 /**
    - 29  * @fileOverview
    - 30  * @name rsapem-1.1.js
    - 31  * @author Kenji Urushima kenji.urushima@gmail.com
    - 32  * @version 1.1
    - 33  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
    - 34  */
    - 35 function _rsapem_pemToBase64(sPEMPrivateKey) {
    - 36   var s = sPEMPrivateKey;
    - 37   s = s.replace("-----BEGIN RSA PRIVATE KEY-----", "");
    - 38   s = s.replace("-----END RSA PRIVATE KEY-----", "");
    - 39   s = s.replace(/[ \n]+/g, "");
    - 40   return s;
    - 41 }
    - 42 
    - 43 function _rsapem_getPosArrayOfChildrenFromHex(hPrivateKey) {
    - 44   var a = new Array();
    - 45   var v1 = ASN1HEX.getStartPosOfV_AtObj(hPrivateKey, 0);
    - 46   var n1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, v1);
    - 47   var e1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, n1);
    - 48   var d1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, e1);
    - 49   var p1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, d1);
    - 50   var q1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, p1);
    - 51   var dp1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, q1);
    - 52   var dq1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, dp1);
    - 53   var co1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, dq1);
    - 54   a.push(v1, n1, e1, d1, p1, q1, dp1, dq1, co1);
    - 55   return a;
    - 56 }
    - 57 
    - 58 function _rsapem_getHexValueArrayOfChildrenFromHex(hPrivateKey) {
    - 59   var posArray = _rsapem_getPosArrayOfChildrenFromHex(hPrivateKey);
    - 60   var v =  ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[0]);
    - 61   var n =  ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[1]);
    - 62   var e =  ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[2]);
    - 63   var d =  ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[3]);
    - 64   var p =  ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[4]);
    - 65   var q =  ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[5]);
    - 66   var dp = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[6]);
    - 67   var dq = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[7]);
    - 68   var co = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[8]);
    - 69   var a = new Array();
    - 70   a.push(v, n, e, d, p, q, dp, dq, co);
    - 71   return a;
    - 72 }
    - 73 
    - 74 /**
    - 75  * read RSA private key from a ASN.1 hexadecimal string
    - 76  * @name readPrivateKeyFromASN1HexString
    - 77  * @memberOf RSAKey#
    - 78  * @function
    - 79  * @param {String} keyHex ASN.1 hexadecimal string of PKCS#1 private key.
    - 80  * @since 1.1.1
    - 81  */
    - 82 function _rsapem_readPrivateKeyFromASN1HexString(keyHex) {
    - 83   var a = _rsapem_getHexValueArrayOfChildrenFromHex(keyHex);
    - 84   this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]);
    - 85 }
    - 86 
    - 87 /**
    - 88  * read PKCS#1 private key from a string
    - 89  * @name readPrivateKeyFromPEMString
    - 90  * @memberOf RSAKey#
    - 91  * @function
    - 92  * @param {String} keyPEM string of PKCS#1 private key.
    - 93  */
    - 94 function _rsapem_readPrivateKeyFromPEMString(keyPEM) {
    - 95   var keyB64 = _rsapem_pemToBase64(keyPEM);
    - 96   var keyHex = b64tohex(keyB64) // depends base64.js
    - 97   var a = _rsapem_getHexValueArrayOfChildrenFromHex(keyHex);
    - 98   this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]);
    - 99 }
    -100 
    -101 RSAKey.prototype.readPrivateKeyFromPEMString = _rsapem_readPrivateKeyFromPEMString;
    -102 RSAKey.prototype.readPrivateKeyFromASN1HexString = _rsapem_readPrivateKeyFromASN1HexString;
    -103 
    \ No newline at end of file + 3
    /* + 4 * rsapem.js - Cryptographic Algorithm Provider class + 5 * + 6 * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com) + 7 * + 8 * This software is licensed under the terms of the MIT License. + 9 * http://kjur.github.com/jsrsasign/license + 10 * + 11 * The above copyright and license notice shall be + 12 * included in all copies or substantial portions of the Software. + 13 */ + 14 + 15 /** + 16 * @fileOverview + 17 * @name rsapem-1.1.js + 18 * @author Kenji Urushima kenji.urushima@gmail.com + 19 * @version 1.2.0 (2017-Jan-21) + 20 * @since jsrsasign 1.0 + 21 * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a> + 22 */ + 23 + 24 /** + 25 * static method to extract Base64 string from PKCS#5 PEM RSA private key.<br/> + 26 * @name pemToBase64 + 27 * @memberOf RSAKey + 28 * @function + 29 * @param {String} sPEMPrivateKey PEM PKCS#1/5 s private key string + 30 * @return {String} Base64 string of private key + 31 * @description + 32 * removing PEM header, PEM footer and space characters including + 33 * new lines from PEM formatted RSA private key string. + 34 * @example + 35 * RSAKey.pemToBase64("----BEGIN PRIVATE KEY-...") → "MIICW..." + 36 */ + 37 RSAKey.pemToBase64 = function(sPEMPrivateKey) { + 38 var s = sPEMPrivateKey; + 39 s = s.replace("-----BEGIN RSA PRIVATE KEY-----", ""); + 40 s = s.replace("-----END RSA PRIVATE KEY-----", ""); + 41 s = s.replace(/[ \n]+/g, ""); + 42 return s; + 43 }; + 44 + 45 /** + 46 * static method to get array of field positions from hexadecimal PKCS#5 RSA private key.<br/> + 47 * @name getPosArrayOfChildrenFromHex + 48 * @memberOf RSAKey + 49 * @function + 50 * @param {String} sPEMPrivateKey PEM PKCS#1/5 s private key string + 51 * @return {Array} array of field positions + 52 * @example + 53 * RSAKey.getPosArrayOfChildrenFromHex("3082...") → [8, 32, ...] + 54 */ + 55 RSAKey.getPosArrayOfChildrenFromHex = function(hPrivateKey) { + 56 var a = new Array(); + 57 var idx_v = ASN1HEX.getStartPosOfV_AtObj(hPrivateKey, 0); + 58 var idx_n = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_v); + 59 var idx_e = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_n); + 60 var idx_d = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_e); + 61 var idx_p = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_d); + 62 var idx_q = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_p); + 63 var idx_dp = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_q); + 64 var idx_dq = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_dp); + 65 var idx_co = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_dq); + 66 a.push(idx_v, idx_n, idx_e, idx_d, idx_p, idx_q, idx_dp, idx_dq, idx_co); + 67 return a; + 68 }; + 69 + 70 /** + 71 * static method to get array of hex field values from hexadecimal PKCS#5 RSA private key.<br/> + 72 * @name getHexValueArrayOfChildrenFromHex + 73 * @memberOf RSAKey + 74 * @function + 75 * @param {String} sPEMPrivateKey PEM PKCS#1/5 s private key string + 76 * @return {Array} array of field hex value + 77 * @example + 78 * RSAKey.getHexValueArrayOfChildrenFromHex("3082...") → ["00", "3b42...", ...] + 79 */ + 80 RSAKey.getHexValueArrayOfChildrenFromHex = function(hPrivateKey) { + 81 var posArray = RSAKey.getPosArrayOfChildrenFromHex(hPrivateKey); + 82 var h_v = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[0]); + 83 var h_n = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[1]); + 84 var h_e = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[2]); + 85 var h_d = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[3]); + 86 var h_p = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[4]); + 87 var h_q = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[5]); + 88 var h_dp = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[6]); + 89 var h_dq = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[7]); + 90 var h_co = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[8]); + 91 var a = new Array(); + 92 a.push(h_v, h_n, h_e, h_d, h_p, h_q, h_dp, h_dq, h_co); + 93 return a; + 94 }; + 95 + 96 /** + 97 * read PKCS#1 private key from a string<br/> + 98 * @name readPrivateKeyFromPEMString + 99 * @memberOf RSAKey# +100 * @function +101 * @param {String} keyPEM string of PKCS#1 private key. +102 */ +103 RSAKey.prototype.readPrivateKeyFromPEMString = function(keyPEM) { +104 var keyB64 = RSAKey.pemToBase64(keyPEM); +105 var keyHex = b64tohex(keyB64) // depends base64.js +106 var a = RSAKey.getHexValueArrayOfChildrenFromHex(keyHex); +107 this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]); +108 }; +109 +110 /** +111 * (DEPRECATED) read RSA private key from a ASN.1 hexadecimal string<br/> +112 * @name readPrivateKeyFromASN1HexString +113 * @memberOf RSAKey# +114 * @function +115 * @param {String} keyHex ASN.1 hexadecimal string of PKCS#1 private key. +116 * @since rsapem 1.1.1 +117 * @deprecated since jsrsasign 7.1.0 rsapem 1.2.0, please use {@link RSAKey.readPKCS5PrvKeyHex} instead. +118 */ +119 RSAKey.prototype.readPrivateKeyFromASN1HexString = function(keyHex) { +120 this.readPKCS5PrvKeyHex(keyHex); +121 }; +122 +123 /** +124 * read an ASN.1 hexadecimal string of PKCS#1/5 plain RSA private key<br/> +125 * @name readPKCS5PrvKeyHex +126 * @memberOf RSAKey# +127 * @function +128 * @param {String} h hexadecimal string of PKCS#1/5 plain RSA private key +129 * @since jsrsasign 7.1.0 rsapem 1.2.0 +130 * @see {@link RSAKey.readPrivateKeyFromASN1HexString} former method +131 */ +132 RSAKey.prototype.readPKCS5PrvKeyHex = function(h) { +133 var a = RSAKey.getHexValueArrayOfChildrenFromHex(h); +134 this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]); +135 }; +136 +137 /** +138 * read an ASN.1 hexadecimal string of PKCS#8 plain RSA private key<br/> +139 * @name readPKCS8PrvKeyHex +140 * @memberOf RSAKey# +141 * @function +142 * @param {String} h hexadecimal string of PKCS#8 plain RSA private key +143 * @since jsrsasign 7.1.0 rsapem 1.2.0 +144 */ +145 RSAKey.prototype.readPKCS8PrvKeyHex = function(h) { +146 var hN, hE, hD, hP, hQ, hDP, hDQ, hCO; +147 var _ASN1HEX = ASN1HEX; +148 var _getVbyList = _ASN1HEX.getVbyList; +149 +150 if (_ASN1HEX.isASN1HEX(h) === false) +151 throw "not ASN.1 hex string"; +152 +153 try { +154 hN = _getVbyList(h, 0, [2, 0, 1], "02"); +155 hE = _getVbyList(h, 0, [2, 0, 2], "02"); +156 hD = _getVbyList(h, 0, [2, 0, 3], "02"); +157 hP = _getVbyList(h, 0, [2, 0, 4], "02"); +158 hQ = _getVbyList(h, 0, [2, 0, 5], "02"); +159 hDP = _getVbyList(h, 0, [2, 0, 6], "02"); +160 hDQ = _getVbyList(h, 0, [2, 0, 7], "02"); +161 hCO = _getVbyList(h, 0, [2, 0, 8], "02"); +162 } catch(ex) { +163 throw "malformed PKCS#8 plain RSA private key"; +164 } +165 +166 this.setPrivateEx(hN, hE, hD, hP, hQ, hDP, hDQ, hCO); +167 }; +168 +169 /** +170 * read an ASN.1 hexadecimal string of PKCS#5 RSA public key<br/> +171 * @name readPKCS5PubKeyHex +172 * @memberOf RSAKey# +173 * @function +174 * @param {String} h hexadecimal string of PKCS#5 public key +175 * @since jsrsasign 7.1.0 rsapem 1.2.0 +176 */ +177 RSAKey.prototype.readPKCS5PubKeyHex = function(h) { +178 if (ASN1HEX.isASN1HEX(h) === false) +179 throw "keyHex is not ASN.1 hex string"; +180 var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0); +181 if (aIdx.length !== 2 || +182 h.substr(aIdx[0], 2) !== "02" || +183 h.substr(aIdx[1], 2) !== "02") +184 throw "wrong hex for PKCS#5 public key"; +185 var hN = ASN1HEX.getHexOfV_AtObj(h, aIdx[0]); +186 var hE = ASN1HEX.getHexOfV_AtObj(h, aIdx[1]); +187 this.setPublic(hN, hE); +188 }; +189 +190 /** +191 * read an ASN.1 hexadecimal string of PKCS#8 RSA public key<br/> +192 * @name readPKCS8PubKeyHex +193 * @memberOf RSAKey# +194 * @function +195 * @param {String} h hexadecimal string of PKCS#8 public key +196 * @since jsrsasign 7.1.0 rsapem 1.2.0 +197 */ +198 RSAKey.prototype.readPKCS8PubKeyHex = function(h) { +199 if (ASN1HEX.isASN1HEX(h) === false) +200 throw "not ASN.1 hex string"; +201 +202 // 06092a864886f70d010101: OBJECT IDENTIFIER rsaEncryption (1 2 840 113549 1 1 1) +203 if (ASN1HEX.getDecendantHexTLVByNthList(h, 0, [0, 0]) !== "06092a864886f70d010101") +204 throw "not PKCS8 RSA public key"; +205 +206 var p5hex = ASN1HEX.getDecendantHexTLVByNthList(h, 0, [1, 0]); +207 this.readPKCS5PubKeyHex(p5hex); +208 }; +209 +210 /** +211 * read an ASN.1 hexadecimal string of X.509 RSA public key certificate<br/> +212 * @name readCertPubKeyHex +213 * @memberOf RSAKey# +214 * @function +215 * @param {String} h hexadecimal string of X.509 RSA public key certificate +216 * @param {Integer} nthPKI nth index of publicKeyInfo. (DEFAULT: 6 for X509v3) +217 * @since jsrsasign 7.1.0 rsapem 1.2.0 +218 */ +219 RSAKey.prototype.readCertPubKeyHex = function(h, nthPKI) { +220 if (nthPKI !== 5) nthPKI = 6; +221 if (ASN1HEX.isASN1HEX(h) === false) +222 throw "not ASN.1 hex string"; +223 +224 var p8hex = ASN1HEX.getDecendantHexTLVByNthList(h, 0, [0, nthPKI]); +225 this.readPKCS8PubKeyHex(p8hex); +226 }; +227
    \ No newline at end of file diff --git a/api/symbols/src/x509-1.1.js.html b/api/symbols/src/x509-1.1.js.html index c281a7ec..482b310d 100644 --- a/api/symbols/src/x509-1.1.js.html +++ b/api/symbols/src/x509-1.1.js.html @@ -5,12 +5,12 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 /*! x509-1.1.10.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
    +	
      1 /*! x509-1.1.11.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
       2  */
       3 /*
       4  * x509.js - X509 class to read subject public key from certificate.
       5  *
    -  6  * Copyright (c) 2010-2016 Kenji Urushima (kenji.urushima@gmail.com)
    +  6  * Copyright (c) 2010-2017 Kenji Urushima (kenji.urushima@gmail.com)
       7  *
       8  * This software is licensed under the terms of the MIT License.
       9  * http://kjur.github.com/jsrsasign/license
    @@ -23,7 +23,7 @@
      16  * @fileOverview
      17  * @name x509-1.1.js
      18  * @author Kenji Urushima kenji.urushima@gmail.com
    - 19  * @version x509 1.1.10 (2016-Nov-19)
    + 19  * @version x509 1.1.11 (2017-Jan-21)
      20  * @since jsrsasign 1.x.x
      21  * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
      22  */
    @@ -88,7 +88,7 @@
      81  *   <li>reading PEM certificate - {@link X509#readCertPEM}</li>
      82  *   <li>get all certificate information - {@link X509#getInfo}</li>
      83  *   <li>get Base64 from PEM certificate - {@link X509.pemToBase64}</li>
    - 84  *   <li>get hexadecimal string from PEM certificate - {@link X509.pemToHex}</li>
    + 84  *   <li>get hexadecimal string from PEM certificate - {@link X509.pemToHex} (DEPRECATED)</li>
      85  *   </ul>
      86  * </li>
      87  * </ul>
    @@ -248,7 +248,7 @@
     241      * x.readCertPEM(sCertPEM); // read certificate
     242      */
     243     this.readCertPEM = function(sCertPEM) {
    -244         var hCert = X509.pemToHex(sCertPEM);
    +244         var hCert = ASN1HEX.pemToHex(sCertPEM);
     245         var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
     246         var rsa = new RSAKey();
     247         rsa.setPublic(a[0], a[1]);
    @@ -259,7 +259,7 @@
     252     };
     253 
     254     this.readCertPEMWithoutRSAInit = function(sCertPEM) {
    -255         var hCert = X509.pemToHex(sCertPEM);
    +255         var hCert = ASN1HEX.pemToHex(sCertPEM);
     256         var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
     257         if (typeof this.subjectPublicKeyRSA.setPublic === "function") {
     258             this.subjectPublicKeyRSA.setPublic(a[0], a[1]);
    @@ -408,920 +408,931 @@
     401  * @function
     402  * @param {String} sCertPEM PEM formatted RSA/ECDSA/DSA X.509 certificate
     403  * @return {String} hexadecimal string of PEM certificate
    -404  * @example
    -405  * hex = X509.pemToHex(certPEM);
    -406  */
    -407 X509.pemToHex = function(sCertPEM) {
    -408     var b64Cert = X509.pemToBase64(sCertPEM);
    -409     var hCert = b64tohex(b64Cert);
    -410     return hCert;
    -411 };
    -412 
    -413 /**
    -414  * get a string index of contents of subjectPublicKeyInfo BITSTRING value from hexadecimal certificate<br/>
    -415  * @name getSubjectPublicKeyPosFromCertHex
    -416  * @memberOf X509
    -417  * @function
    -418  * @param {String} hexadecimal string of DER RSA/ECDSA/DSA X.509 certificate
    -419  * @return {Integer} string index of key contents
    -420  * @example
    -421  * idx = X509.getSubjectPublicKeyPosFromCertHex("3082...");
    -422  */
    -423 // NOTE: Without BITSTRING encapsulation.
    -424 X509.getSubjectPublicKeyPosFromCertHex = function(hCert) {
    -425     var pInfo = X509.getSubjectPublicKeyInfoPosFromCertHex(hCert);
    -426     if (pInfo == -1) return -1;
    -427     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pInfo);
    -428     if (a.length != 2) return -1;
    -429     var pBitString = a[1];
    -430     if (hCert.substring(pBitString, pBitString + 2) != '03') return -1;
    -431     var pBitStringV = ASN1HEX.getStartPosOfV_AtObj(hCert, pBitString);
    -432 
    -433     if (hCert.substring(pBitStringV, pBitStringV + 2) != '00') return -1;
    -434     return pBitStringV + 2;
    -435 };
    -436 
    -437 /**
    -438  * get a string index of subjectPublicKeyInfo field from hexadecimal certificate<br/>
    -439  * @name getSubjectPublicKeyInfoPosFromCertHex
    -440  * @memberOf X509
    -441  * @function
    -442  * @param {String} hexadecimal string of DER RSA/ECDSA/DSA X.509 certificate
    -443  * @return {Integer} string index of subjectPublicKeyInfo field
    -444  * @description
    -445  * This static method gets a string index of subjectPublicKeyInfo field from hexadecimal certificate.<br/>
    -446  * NOTE1: privateKeyUsagePeriod field of X509v2 not supported.<br/>
    -447  * NOTE2: X.509v1 and X.509v3 certificate are supported.<br/>
    -448  * @example
    -449  * idx = X509.getSubjectPublicKeyInfoPosFromCertHex("3082...");
    -450  */
    -451 X509.getSubjectPublicKeyInfoPosFromCertHex = function(hCert) {
    -452     var pTbsCert = ASN1HEX.getStartPosOfV_AtObj(hCert, 0);
    -453     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pTbsCert);
    -454     if (a.length < 1) return -1;
    -455     if (hCert.substring(a[0], a[0] + 10) == "a003020102") { // v3
    -456         if (a.length < 6) return -1;
    -457         return a[6];
    -458     } else {
    -459         if (a.length < 5) return -1;
    -460         return a[5];
    -461     }
    -462 };
    -463 
    -464 X509.getPublicKeyHexArrayFromCertHex = function(hCert) {
    -465     var p = X509.getSubjectPublicKeyPosFromCertHex(hCert);
    -466     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, p);
    -467     if (a.length != 2) return [];
    -468     var hN = ASN1HEX.getHexOfV_AtObj(hCert, a[0]);
    -469     var hE = ASN1HEX.getHexOfV_AtObj(hCert, a[1]);
    -470     if (hN != null && hE != null) {
    -471         return [hN, hE];
    -472     } else {
    -473         return [];
    -474     }
    -475 };
    -476 
    -477 X509.getHexTbsCertificateFromCert = function(hCert) {
    -478     var pTbsCert = ASN1HEX.getStartPosOfV_AtObj(hCert, 0);
    -479     return pTbsCert;
    -480 };
    -481 
    -482 X509.getPublicKeyHexArrayFromCertPEM = function(sCertPEM) {
    -483     var hCert = X509.pemToHex(sCertPEM);
    -484     var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
    -485     return a;
    -486 };
    -487 
    -488 /**
    -489  * get distinguished name string in OpenSSL online format from hexadecimal string of ASN.1 DER X.500 name<br/>
    -490  * @name hex2dn
    -491  * @memberOf X509
    -492  * @function
    -493  * @param {String} hex hexadecimal string of ASN.1 DER distinguished name
    -494  * @param {Integer} idx index of hexadecimal string (DEFAULT=0)
    -495  * @return {String} OpenSSL online format distinguished name
    -496  * @description
    -497  * This static method converts from a hexadecimal string of 
    -498  * distinguished name (DN)
    -499  * specified by 'hex' and 'idx' to OpenSSL oneline string representation (ex. /C=US/O=a).
    -500  * @example
    -501  * X509.hex2dn("3031310b3...") → /C=US/O=a/CN=b2+OU=b1
    -502  */
    -503 X509.hex2dn = function(hex, idx) {
    -504     if (idx === undefined) idx = 0;
    -505     if (hex.substr(idx, 2) !== "30") throw "malformed DN";
    -506 
    -507     var a = new Array();
    -508 
    -509     var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
    -510     for (var i = 0; i < aIdx.length; i++) {
    -511 	a.push(X509.hex2rdn(hex, aIdx[i]));
    -512     }
    -513 
    -514     a = a.map(function(s) { return s.replace("/", "\\/"); });
    -515     return "/" + a.join("/");
    -516 };
    -517 
    -518 /**
    -519  * get relative distinguished name string in OpenSSL online format from hexadecimal string of ASN.1 DER RDN<br/>
    -520  * @name hex2rdn
    -521  * @memberOf X509
    -522  * @function
    -523  * @param {String} hex hexadecimal string of ASN.1 DER concludes relative distinguished name
    -524  * @param {Integer} idx index of hexadecimal string (DEFAULT=0)
    -525  * @return {String} OpenSSL online format relative distinguished name
    -526  * @description
    -527  * This static method converts from a hexadecimal string of 
    -528  * relative distinguished name (RDN)
    -529  * specified by 'hex' and 'idx' to LDAP string representation (ex. O=test+CN=test).<br/>
    -530  * NOTE: Multi-valued RDN is supported since jsnrsasign 6.2.2 x509 1.1.10.
    -531  * @example
    -532  * X509.hex2rdn("310a3008060355040a0c0161") → O=a
    -533  * X509.hex2rdn("31143008060355040a0c01613008060355040a0c0162") → O=a+O=b
    -534  */
    -535 X509.hex2rdn = function(hex, idx) {
    -536     if (idx === undefined) idx = 0;
    -537     if (hex.substr(idx, 2) !== "31") throw "malformed RDN";
    -538 
    -539     var a = new Array();
    -540 
    -541     var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
    -542     for (var i = 0; i < aIdx.length; i++) {
    -543 	a.push(X509.hex2attrTypeValue(hex, aIdx[i]));
    -544     }
    -545 
    -546     a = a.map(function(s) { return s.replace("+", "\\+"); });
    -547     return a.join("+");
    -548 };
    -549 
    -550 /**
    -551  * get string from hexadecimal string of ASN.1 DER AttributeTypeAndValue<br/>
    -552  * @name hex2attrTypeValue
    -553  * @memberOf X509
    -554  * @function
    -555  * @param {String} hex hexadecimal string of ASN.1 DER concludes AttributeTypeAndValue
    -556  * @param {Integer} idx index of hexadecimal string (DEFAULT=0)
    -557  * @return {String} string representation of AttributeTypeAndValue (ex. C=US)
    -558  * @description
    -559  * This static method converts from a hexadecimal string of AttributeTypeAndValue
    -560  * specified by 'hex' and 'idx' to LDAP string representation (ex. C=US).
    -561  * @example
    -562  * X509.hex2attrTypeValue("3008060355040a0c0161") → O=a
    -563  * X509.hex2attrTypeValue("300806035504060c0161") → C=a
    -564  * X509.hex2attrTypeValue("...3008060355040a0c0161...", 128) → O=a
    -565  */
    -566 X509.hex2attrTypeValue = function(hex, idx) {
    -567     if (idx === undefined) idx = 0;
    -568     if (hex.substr(idx, 2) !== "30") throw "malformed attribute type and value";
    -569 
    -570     var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
    -571     if (aIdx.length !== 2 || hex.substr(aIdx[0], 2) !== "06")
    -572 	"malformed attribute type and value";
    -573 
    -574     var oidHex = ASN1HEX.getHexOfV_AtObj(hex, aIdx[0]);
    -575     var oidInt = KJUR.asn1.ASN1Util.oidHexToInt(oidHex);
    -576     var atype = KJUR.asn1.x509.OID.oid2atype(oidInt);
    -577 
    -578     var hV = ASN1HEX.getHexOfV_AtObj(hex, aIdx[1]);
    -579     var rawV = hextorstr(hV);
    -580 
    -581     return atype + "=" + rawV;
    -582 };
    -583 
    -584 /**
    -585  * get RSAKey/ECDSA public key object from PEM certificate string
    -586  * @name getPublicKeyFromCertPEM
    -587  * @memberOf X509
    -588  * @function
    -589  * @param {String} sCertPEM PEM formatted RSA/ECDSA/DSA X.509 certificate
    -590  * @return returns RSAKey/KJUR.crypto.{ECDSA,DSA} object of public key
    -591  * @since x509 1.1.1
    -592  * @description
    -593  * NOTE: DSA is also supported since x509 1.1.2.
    -594  */
    -595 X509.getPublicKeyFromCertPEM = function(sCertPEM) {
    -596     var info = X509.getPublicKeyInfoPropOfCertPEM(sCertPEM);
    -597 
    -598     if (info.algoid == "2a864886f70d010101") { // RSA
    -599         var aRSA = KEYUTIL.parsePublicRawRSAKeyHex(info.keyhex);
    -600         var key = new RSAKey();
    -601         key.setPublic(aRSA.n, aRSA.e);
    -602         return key;
    -603     } else if (info.algoid == "2a8648ce3d0201") { // ECC
    -604         var curveName = KJUR.crypto.OID.oidhex2name[info.algparam];
    -605         var key = new KJUR.crypto.ECDSA({'curve': curveName, 'info': info.keyhex});
    -606         key.setPublicKeyHex(info.keyhex);
    -607         return key;
    -608     } else if (info.algoid == "2a8648ce380401") { // DSA 1.2.840.10040.4.1
    -609         var p = ASN1HEX.getVbyList(info.algparam, 0, [0], "02");
    -610         var q = ASN1HEX.getVbyList(info.algparam, 0, [1], "02");
    -611         var g = ASN1HEX.getVbyList(info.algparam, 0, [2], "02");
    -612         var y = ASN1HEX.getHexOfV_AtObj(info.keyhex, 0);
    -613         y = y.substr(2);
    -614         var key = new KJUR.crypto.DSA();
    -615         key.setPublic(new BigInteger(p, 16),
    -616                       new BigInteger(q, 16),
    -617                       new BigInteger(g, 16),
    -618                       new BigInteger(y, 16));
    -619         return key;
    -620     } else {
    -621         throw "unsupported key";
    -622     }
    -623 };
    -624 
    -625 /**
    -626  * get public key information from PEM certificate
    -627  * @name getPublicKeyInfoPropOfCertPEM
    -628  * @memberOf X509
    -629  * @function
    -630  * @param {String} sCertPEM string of PEM formatted certificate
    -631  * @return {Hash} hash of information for public key
    -632  * @since x509 1.1.1
    -633  * @description
    -634  * Resulted associative array has following properties:<br/>
    -635  * <ul>
    -636  * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
    -637  * <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
    -638  * <li>keyhex - hexadecimal string of key in the certificate</li>
    -639  * </ul>
    -640  * NOTE: X509v1 certificate is also supported since x509.js 1.1.9.
    -641  */
    -642 X509.getPublicKeyInfoPropOfCertPEM = function(sCertPEM) {
    -643     var result = {};
    -644     result.algparam = null;
    -645     var hCert = X509.pemToHex(sCertPEM);
    -646 
    -647     // 1. Certificate ASN.1
    -648     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
    -649     if (a1.length != 3)
    -650         throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
    -651 
    -652     // 2. tbsCertificate
    -653     if (hCert.substr(a1[0], 2) != "30")
    -654         throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
    -655 
    -656     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
    +404  * @deprecated from x509 1.1.11 jsrsasign 7.0.1. please move to {@link ASN1HEX.pemToHex}
    +405  * @description
    +406  * CAUTION: now X509.pemToHex deprecated and is planed to remove in jsrsasign 8.0.0.
    +407  * @example
    +408  * hex = X509.pemToHex(certPEM);
    +409  */
    +410 X509.pemToHex = function(sCertPEM) {
    +411     return ASN1HEX.pemToHex(sCertPEM);
    +412 };
    +413 
    +414 /**
    +415  * get a string index of contents of subjectPublicKeyInfo BITSTRING value from hexadecimal certificate<br/>
    +416  * @name getSubjectPublicKeyPosFromCertHex
    +417  * @memberOf X509
    +418  * @function
    +419  * @param {String} hexadecimal string of DER RSA/ECDSA/DSA X.509 certificate
    +420  * @return {Integer} string index of key contents
    +421  * @example
    +422  * idx = X509.getSubjectPublicKeyPosFromCertHex("3082...");
    +423  */
    +424 // NOTE: Without BITSTRING encapsulation.
    +425 X509.getSubjectPublicKeyPosFromCertHex = function(hCert) {
    +426     var pInfo = X509.getSubjectPublicKeyInfoPosFromCertHex(hCert);
    +427     if (pInfo == -1) return -1;
    +428     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pInfo);
    +429     if (a.length != 2) return -1;
    +430     var pBitString = a[1];
    +431     if (hCert.substring(pBitString, pBitString + 2) != '03') return -1;
    +432     var pBitStringV = ASN1HEX.getStartPosOfV_AtObj(hCert, pBitString);
    +433 
    +434     if (hCert.substring(pBitStringV, pBitStringV + 2) != '00') return -1;
    +435     return pBitStringV + 2;
    +436 };
    +437 
    +438 /**
    +439  * get a string index of subjectPublicKeyInfo field from hexadecimal certificate<br/>
    +440  * @name getSubjectPublicKeyInfoPosFromCertHex
    +441  * @memberOf X509
    +442  * @function
    +443  * @param {String} hexadecimal string of DER RSA/ECDSA/DSA X.509 certificate
    +444  * @return {Integer} string index of subjectPublicKeyInfo field
    +445  * @description
    +446  * This static method gets a string index of subjectPublicKeyInfo field from hexadecimal certificate.<br/>
    +447  * NOTE1: privateKeyUsagePeriod field of X509v2 not supported.<br/>
    +448  * NOTE2: X.509v1 and X.509v3 certificate are supported.<br/>
    +449  * @example
    +450  * idx = X509.getSubjectPublicKeyInfoPosFromCertHex("3082...");
    +451  */
    +452 X509.getSubjectPublicKeyInfoPosFromCertHex = function(hCert) {
    +453     var pTbsCert = ASN1HEX.getStartPosOfV_AtObj(hCert, 0);
    +454     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pTbsCert);
    +455     if (a.length < 1) return -1;
    +456     if (hCert.substring(a[0], a[0] + 10) == "a003020102") { // v3
    +457         if (a.length < 6) return -1;
    +458         return a[6];
    +459     } else {
    +460         if (a.length < 5) return -1;
    +461         return a[5];
    +462     }
    +463 };
    +464 
    +465 X509.getPublicKeyHexArrayFromCertHex = function(hCert) {
    +466     var p = X509.getSubjectPublicKeyPosFromCertHex(hCert);
    +467     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, p);
    +468     if (a.length != 2) return [];
    +469     var hN = ASN1HEX.getHexOfV_AtObj(hCert, a[0]);
    +470     var hE = ASN1HEX.getHexOfV_AtObj(hCert, a[1]);
    +471     if (hN != null && hE != null) {
    +472         return [hN, hE];
    +473     } else {
    +474         return [];
    +475     }
    +476 };
    +477 
    +478 X509.getHexTbsCertificateFromCert = function(hCert) {
    +479     var pTbsCert = ASN1HEX.getStartPosOfV_AtObj(hCert, 0);
    +480     return pTbsCert;
    +481 };
    +482 
    +483 X509.getPublicKeyHexArrayFromCertPEM = function(sCertPEM) {
    +484     var hCert = ASN1HEX.pemToHex(sCertPEM);
    +485     var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
    +486     return a;
    +487 };
    +488 
    +489 /**
    +490  * get distinguished name string in OpenSSL online format from hexadecimal string of ASN.1 DER X.500 name<br/>
    +491  * @name hex2dn
    +492  * @memberOf X509
    +493  * @function
    +494  * @param {String} hex hexadecimal string of ASN.1 DER distinguished name
    +495  * @param {Integer} idx index of hexadecimal string (DEFAULT=0)
    +496  * @return {String} OpenSSL online format distinguished name
    +497  * @description
    +498  * This static method converts from a hexadecimal string of 
    +499  * distinguished name (DN)
    +500  * specified by 'hex' and 'idx' to OpenSSL oneline string representation (ex. /C=US/O=a).
    +501  * @example
    +502  * X509.hex2dn("3031310b3...") → /C=US/O=a/CN=b2+OU=b1
    +503  */
    +504 X509.hex2dn = function(hex, idx) {
    +505     if (idx === undefined) idx = 0;
    +506     if (hex.substr(idx, 2) !== "30") throw "malformed DN";
    +507 
    +508     var a = new Array();
    +509 
    +510     var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
    +511     for (var i = 0; i < aIdx.length; i++) {
    +512 	a.push(X509.hex2rdn(hex, aIdx[i]));
    +513     }
    +514 
    +515     a = a.map(function(s) { return s.replace("/", "\\/"); });
    +516     return "/" + a.join("/");
    +517 };
    +518 
    +519 /**
    +520  * get relative distinguished name string in OpenSSL online format from hexadecimal string of ASN.1 DER RDN<br/>
    +521  * @name hex2rdn
    +522  * @memberOf X509
    +523  * @function
    +524  * @param {String} hex hexadecimal string of ASN.1 DER concludes relative distinguished name
    +525  * @param {Integer} idx index of hexadecimal string (DEFAULT=0)
    +526  * @return {String} OpenSSL online format relative distinguished name
    +527  * @description
    +528  * This static method converts from a hexadecimal string of 
    +529  * relative distinguished name (RDN)
    +530  * specified by 'hex' and 'idx' to LDAP string representation (ex. O=test+CN=test).<br/>
    +531  * NOTE: Multi-valued RDN is supported since jsnrsasign 6.2.2 x509 1.1.10.
    +532  * @example
    +533  * X509.hex2rdn("310a3008060355040a0c0161") → O=a
    +534  * X509.hex2rdn("31143008060355040a0c01613008060355040a0c0162") → O=a+O=b
    +535  */
    +536 X509.hex2rdn = function(hex, idx) {
    +537     if (idx === undefined) idx = 0;
    +538     if (hex.substr(idx, 2) !== "31") throw "malformed RDN";
    +539 
    +540     var a = new Array();
    +541 
    +542     var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
    +543     for (var i = 0; i < aIdx.length; i++) {
    +544 	a.push(X509.hex2attrTypeValue(hex, aIdx[i]));
    +545     }
    +546 
    +547     a = a.map(function(s) { return s.replace("+", "\\+"); });
    +548     return a.join("+");
    +549 };
    +550 
    +551 /**
    +552  * get string from hexadecimal string of ASN.1 DER AttributeTypeAndValue<br/>
    +553  * @name hex2attrTypeValue
    +554  * @memberOf X509
    +555  * @function
    +556  * @param {String} hex hexadecimal string of ASN.1 DER concludes AttributeTypeAndValue
    +557  * @param {Integer} idx index of hexadecimal string (DEFAULT=0)
    +558  * @return {String} string representation of AttributeTypeAndValue (ex. C=US)
    +559  * @description
    +560  * This static method converts from a hexadecimal string of AttributeTypeAndValue
    +561  * specified by 'hex' and 'idx' to LDAP string representation (ex. C=US).
    +562  * @example
    +563  * X509.hex2attrTypeValue("3008060355040a0c0161") → O=a
    +564  * X509.hex2attrTypeValue("300806035504060c0161") → C=a
    +565  * X509.hex2attrTypeValue("...3008060355040a0c0161...", 128) → O=a
    +566  */
    +567 X509.hex2attrTypeValue = function(hex, idx) {
    +568     if (idx === undefined) idx = 0;
    +569     if (hex.substr(idx, 2) !== "30") throw "malformed attribute type and value";
    +570 
    +571     var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
    +572     if (aIdx.length !== 2 || hex.substr(aIdx[0], 2) !== "06")
    +573 	"malformed attribute type and value";
    +574 
    +575     var oidHex = ASN1HEX.getHexOfV_AtObj(hex, aIdx[0]);
    +576     var oidInt = KJUR.asn1.ASN1Util.oidHexToInt(oidHex);
    +577     var atype = KJUR.asn1.x509.OID.oid2atype(oidInt);
    +578 
    +579     var hV = ASN1HEX.getHexOfV_AtObj(hex, aIdx[1]);
    +580     var rawV = hextorstr(hV);
    +581 
    +582     return atype + "=" + rawV;
    +583 };
    +584 
    +585 /**
    +586  * get RSA/DSA/ECDSA public key object from X.509 certificate hexadecimal string<br/>
    +587  * @name getPublicKeyFromCertHex
    +588  * @memberOf X509
    +589  * @function
    +590  * @param {String} h hexadecimal string of X.509 certificate for RSA/ECDSA/DSA public key
    +591  * @return returns RSAKey/KJUR.crypto.{ECDSA,DSA} object of public key
    +592  * @since jsrasign 7.1.0 x509 1.1.11
    +593  */
    +594 X509.getPublicKeyFromCertHex = function(h) {
    +595     var key, hKEYOID, hItem1;
    +596     var nthPKI = 6; // for publicKeyInfo index is 6 for v3 or 5 for v1
    +597     var _ASN1HEX = ASN1HEX;
    +598     var _getVbyList = _ASN1HEX.getVbyList;
    +599 
    +600     hItem1 = _ASN1HEX.getDecendantHexTLVByNthList(h, 0, [0, 0]);
    +601     if (hItem1 !== "a003020102") { // tbsCert first item is version(=v3)
    +602 	nthPKI = 5;
    +603     }
    +604 
    +605     hKEYOID = _getVbyList(h, 0, [0, nthPKI, 0, 0], "06");
    +606     if (hKEYOID === "2a864886f70d010101") {    // RSA
    +607         key = new RSAKey();
    +608     } else if (hKEYOID === "2a8648ce380401") { // DSA
    +609         key = new KJUR.crypto.DSA();
    +610     } else if (hKEYOID === "2a8648ce3d0201") { // CC
    +611         key = new KJUR.crypto.ECDSA();
    +612     } else {
    +613         throw "unsupported public key in X.509 cert";
    +614     }
    +615     key.readCertPubKeyHex(h, nthPKI);
    +616     return key;
    +617 };
    +618 
    +619 /**
    +620  * get RSA/DSA/ECDSA public key object from PEM certificate string
    +621  * @name getPublicKeyFromCertPEM
    +622  * @memberOf X509
    +623  * @function
    +624  * @param {String} sCertPEM PEM formatted RSA/ECDSA/DSA X.509 certificate
    +625  * @return returns RSAKey/KJUR.crypto.{ECDSA,DSA} object of public key
    +626  * @since x509 1.1.1
    +627  * @description
    +628  * NOTE: DSA is also supported since x509 1.1.2.
    +629  */
    +630 X509.getPublicKeyFromCertPEM = function(sCertPEM) {
    +631     var _ASN1HEX = ASN1HEX;
    +632     var h = _ASN1HEX.pemToHex(sCertPEM);
    +633     return X509.getPublicKeyFromCertHex(h);
    +634 };
    +635 
    +636 /**
    +637  * get public key information from PEM certificate
    +638  * @name getPublicKeyInfoPropOfCertPEM
    +639  * @memberOf X509
    +640  * @function
    +641  * @param {String} sCertPEM string of PEM formatted certificate
    +642  * @return {Hash} hash of information for public key
    +643  * @since x509 1.1.1
    +644  * @description
    +645  * Resulted associative array has following properties:<br/>
    +646  * <ul>
    +647  * <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
    +648  * <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
    +649  * <li>keyhex - hexadecimal string of key in the certificate</li>
    +650  * </ul>
    +651  * NOTE: X509v1 certificate is also supported since x509.js 1.1.9.
    +652  */
    +653 X509.getPublicKeyInfoPropOfCertPEM = function(sCertPEM) {
    +654     var result = {};
    +655     result.algparam = null;
    +656     var hCert = ASN1HEX.pemToHex(sCertPEM);
     657 
    -658     // 3. subjectPublicKeyInfo
    -659     var idx_spi = 6; // subjectPublicKeyInfo index in tbsCert for v3 cert
    -660     if (hCert.substr(a2[0], 2) !== "a0") idx_spi = 5;
    -661 
    -662     if (a2.length < idx_spi + 1)
    -663         throw "malformed X.509 certificate PEM (code:003)"; // no subjPubKeyInfo
    -664 
    -665     var a3 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a2[idx_spi]);
    +658     // 1. Certificate ASN.1
    +659     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
    +660     if (a1.length != 3)
    +661         throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
    +662 
    +663     // 2. tbsCertificate
    +664     if (hCert.substr(a1[0], 2) != "30")
    +665         throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
     666 
    -667     if (a3.length != 2)
    -668         throw "malformed X.509 certificate PEM (code:004)"; // not AlgId and PubKey
    -669 
    -670     // 4. AlgId
    -671     var a4 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a3[0]);
    +667     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
    +668 
    +669     // 3. subjectPublicKeyInfo
    +670     var idx_spi = 6; // subjectPublicKeyInfo index in tbsCert for v3 cert
    +671     if (hCert.substr(a2[0], 2) !== "a0") idx_spi = 5;
     672 
    -673     if (a4.length != 2)
    -674         throw "malformed X.509 certificate PEM (code:005)"; // not 2 item in AlgId
    +673     if (a2.length < idx_spi + 1)
    +674         throw "malformed X.509 certificate PEM (code:003)"; // no subjPubKeyInfo
     675 
    -676     result.algoid = ASN1HEX.getHexOfV_AtObj(hCert, a4[0]);
    +676     var a3 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a2[idx_spi]);
     677 
    -678     if (hCert.substr(a4[1], 2) == "06") { // EC
    -679         result.algparam = ASN1HEX.getHexOfV_AtObj(hCert, a4[1]);
    -680     } else if (hCert.substr(a4[1], 2) == "30") { // DSA
    -681         result.algparam = ASN1HEX.getHexOfTLV_AtObj(hCert, a4[1]);
    -682     }
    +678     if (a3.length != 2)
    +679         throw "malformed X.509 certificate PEM (code:004)"; // not AlgId and PubKey
    +680 
    +681     // 4. AlgId
    +682     var a4 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a3[0]);
     683 
    -684     // 5. Public Key Hex
    -685     if (hCert.substr(a3[1], 2) != "03")
    -686         throw "malformed X.509 certificate PEM (code:006)"; // not bitstring
    -687 
    -688     var unusedBitAndKeyHex = ASN1HEX.getHexOfV_AtObj(hCert, a3[1]);
    -689     result.keyhex = unusedBitAndKeyHex.substr(2);
    -690 
    -691     return result;
    -692 };
    -693 
    -694 /**
    -695  * get position of subjectPublicKeyInfo field from HEX certificate
    -696  * @name getPublicKeyInfoPosOfCertHEX
    -697  * @memberOf X509
    -698  * @function
    -699  * @param {String} hCert hexadecimal string of certificate
    -700  * @return {Integer} position in hexadecimal string
    -701  * @since x509 1.1.4
    -702  * @description
    -703  * get position for SubjectPublicKeyInfo field in the hexadecimal string of
    -704  * certificate.
    -705  */
    -706 X509.getPublicKeyInfoPosOfCertHEX = function(hCert) {
    -707     // 1. Certificate ASN.1
    -708     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
    -709     if (a1.length != 3)
    -710         throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
    -711 
    -712     // 2. tbsCertificate
    -713     if (hCert.substr(a1[0], 2) != "30")
    -714         throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
    -715 
    -716     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
    -717 
    -718     // 3. subjectPublicKeyInfo
    -719     if (a2.length < 7)
    -720         throw "malformed X.509 certificate PEM (code:003)"; // no subjPubKeyInfo
    -721 
    -722     return a2[6];
    -723 };
    -724 
    -725 /**
    -726  * get array of X.509 V3 extension value information in hex string of certificate
    -727  * @name getV3ExtInfoListOfCertHex
    -728  * @memberOf X509
    -729  * @function
    -730  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -731  * @return {Array} array of result object by {@link X509.getV3ExtInfoListOfCertHex}
    -732  * @since x509 1.1.5
    -733  * @description
    -734  * This method will get all extension information of a X.509 certificate.
    -735  * Items of resulting array has following properties:
    -736  * <ul>
    -737  * <li>posTLV - index of ASN.1 TLV for the extension. same as 'pos' argument.</li>
    -738  * <li>oid - dot noted string of extension oid (ex. 2.5.29.14)</li>
    -739  * <li>critical - critical flag value for this extension</li>
    -740  * <li>posV - index of ASN.1 TLV for the extension value.
    -741  * This is a position of a content of ENCAPSULATED OCTET STRING.</li>
    -742  * </ul>
    -743  * @example
    -744  * hCert = X509.pemToHex(certGithubPEM);
    -745  * a = X509.getV3ExtInfoListOfCertHex(hCert);
    -746  * // Then a will be an array of like following:
    -747  * [{posTLV: 1952, oid: "2.5.29.35", critical: false, posV: 1968},
    -748  *  {posTLV: 1974, oid: "2.5.29.19", critical: true, posV: 1986}, ...]
    -749  */
    -750 X509.getV3ExtInfoListOfCertHex = function(hCert) {
    -751     // 1. Certificate ASN.1
    -752     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
    -753     if (a1.length != 3)
    -754         throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
    -755 
    -756     // 2. tbsCertificate
    -757     if (hCert.substr(a1[0], 2) != "30")
    -758         throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
    -759 
    -760     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
    -761 
    -762     // 3. v3Extension EXPLICIT Tag [3]
    -763     // ver, seri, alg, iss, validity, subj, spki, (iui,) (sui,) ext
    -764     if (a2.length < 8)
    -765         throw "malformed X.509 certificate PEM (code:003)"; // tbsCert num field too short
    +684     if (a4.length != 2)
    +685         throw "malformed X.509 certificate PEM (code:005)"; // not 2 item in AlgId
    +686 
    +687     result.algoid = ASN1HEX.getHexOfV_AtObj(hCert, a4[0]);
    +688 
    +689     if (hCert.substr(a4[1], 2) == "06") { // EC
    +690         result.algparam = ASN1HEX.getHexOfV_AtObj(hCert, a4[1]);
    +691     } else if (hCert.substr(a4[1], 2) == "30") { // DSA
    +692         result.algparam = ASN1HEX.getHexOfTLV_AtObj(hCert, a4[1]);
    +693     }
    +694 
    +695     // 5. Public Key Hex
    +696     if (hCert.substr(a3[1], 2) != "03")
    +697         throw "malformed X.509 certificate PEM (code:006)"; // not bitstring
    +698 
    +699     var unusedBitAndKeyHex = ASN1HEX.getHexOfV_AtObj(hCert, a3[1]);
    +700     result.keyhex = unusedBitAndKeyHex.substr(2);
    +701 
    +702     return result;
    +703 };
    +704 
    +705 /**
    +706  * get position of subjectPublicKeyInfo field from HEX certificate
    +707  * @name getPublicKeyInfoPosOfCertHEX
    +708  * @memberOf X509
    +709  * @function
    +710  * @param {String} hCert hexadecimal string of certificate
    +711  * @return {Integer} position in hexadecimal string
    +712  * @since x509 1.1.4
    +713  * @description
    +714  * get position for SubjectPublicKeyInfo field in the hexadecimal string of
    +715  * certificate.
    +716  */
    +717 X509.getPublicKeyInfoPosOfCertHEX = function(hCert) {
    +718     // 1. Certificate ASN.1
    +719     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
    +720     if (a1.length != 3)
    +721         throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
    +722 
    +723     // 2. tbsCertificate
    +724     if (hCert.substr(a1[0], 2) != "30")
    +725         throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
    +726 
    +727     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
    +728 
    +729     // 3. subjectPublicKeyInfo
    +730     if (a2.length < 7)
    +731         throw "malformed X.509 certificate PEM (code:003)"; // no subjPubKeyInfo
    +732 
    +733     return a2[6];
    +734 };
    +735 
    +736 /**
    +737  * get array of X.509 V3 extension value information in hex string of certificate
    +738  * @name getV3ExtInfoListOfCertHex
    +739  * @memberOf X509
    +740  * @function
    +741  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +742  * @return {Array} array of result object by {@link X509.getV3ExtInfoListOfCertHex}
    +743  * @since x509 1.1.5
    +744  * @description
    +745  * This method will get all extension information of a X.509 certificate.
    +746  * Items of resulting array has following properties:
    +747  * <ul>
    +748  * <li>posTLV - index of ASN.1 TLV for the extension. same as 'pos' argument.</li>
    +749  * <li>oid - dot noted string of extension oid (ex. 2.5.29.14)</li>
    +750  * <li>critical - critical flag value for this extension</li>
    +751  * <li>posV - index of ASN.1 TLV for the extension value.
    +752  * This is a position of a content of ENCAPSULATED OCTET STRING.</li>
    +753  * </ul>
    +754  * @example
    +755  * hCert = ASN1HEX.pemToHex(certGithubPEM);
    +756  * a = X509.getV3ExtInfoListOfCertHex(hCert);
    +757  * // Then a will be an array of like following:
    +758  * [{posTLV: 1952, oid: "2.5.29.35", critical: false, posV: 1968},
    +759  *  {posTLV: 1974, oid: "2.5.29.19", critical: true, posV: 1986}, ...]
    +760  */
    +761 X509.getV3ExtInfoListOfCertHex = function(hCert) {
    +762     // 1. Certificate ASN.1
    +763     var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
    +764     if (a1.length != 3)
    +765         throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
     766 
    -767     if (hCert.substr(a2[7], 2) != "a3")
    -768         throw "malformed X.509 certificate PEM (code:004)"; // not [3] tag
    -769 
    -770     var a3 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a2[7]);
    -771     if (a3.length != 1)
    -772         throw "malformed X.509 certificate PEM (code:005)"; // [3]tag numChild!=1
    -773 
    -774     // 4. v3Extension SEQUENCE
    -775     if (hCert.substr(a3[0], 2) != "30")
    -776         throw "malformed X.509 certificate PEM (code:006)"; // not SEQ
    +767     // 2. tbsCertificate
    +768     if (hCert.substr(a1[0], 2) != "30")
    +769         throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
    +770 
    +771     var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
    +772 
    +773     // 3. v3Extension EXPLICIT Tag [3]
    +774     // ver, seri, alg, iss, validity, subj, spki, (iui,) (sui,) ext
    +775     if (a2.length < 8)
    +776         throw "malformed X.509 certificate PEM (code:003)"; // tbsCert num field too short
     777 
    -778     var a4 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a3[0]);
    -779 
    -780     // 5. v3Extension item position
    -781     var numExt = a4.length;
    -782     var aInfo = new Array(numExt);
    -783     for (var i = 0; i < numExt; i++) {
    -784 	aInfo[i] = X509.getV3ExtItemInfo_AtObj(hCert, a4[i]);
    -785     }
    -786     return aInfo;
    -787 };
    +778     if (hCert.substr(a2[7], 2) != "a3")
    +779         throw "malformed X.509 certificate PEM (code:004)"; // not [3] tag
    +780 
    +781     var a3 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a2[7]);
    +782     if (a3.length != 1)
    +783         throw "malformed X.509 certificate PEM (code:005)"; // [3]tag numChild!=1
    +784 
    +785     // 4. v3Extension SEQUENCE
    +786     if (hCert.substr(a3[0], 2) != "30")
    +787         throw "malformed X.509 certificate PEM (code:006)"; // not SEQ
     788 
    -789 /**
    -790  * get X.509 V3 extension value information at the specified position
    -791  * @name getV3ExtItemInfo_AtObj
    -792  * @memberOf X509
    -793  * @function
    -794  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -795  * @param {Integer} pos index of hexadecimal string for the extension
    -796  * @return {Object} properties for the extension
    -797  * @since x509 1.1.5
    -798  * @description
    -799  * This method will get some information of a X.509 V extension
    -800  * which is referred by an index of hexadecimal string of X.509
    -801  * certificate.
    -802  * Resulting object has following properties:
    -803  * <ul>
    -804  * <li>posTLV - index of ASN.1 TLV for the extension. same as 'pos' argument.</li>
    -805  * <li>oid - dot noted string of extension oid (ex. 2.5.29.14)</li>
    -806  * <li>critical - critical flag value for this extension</li>
    -807  * <li>posV - index of ASN.1 TLV for the extension value.
    -808  * This is a position of a content of ENCAPSULATED OCTET STRING.</li>
    -809  * </ul>
    -810  * This method is used by {@link X509.getV3ExtInfoListOfCertHex} internally.
    -811  */
    -812 X509.getV3ExtItemInfo_AtObj = function(hCert, pos) {
    -813     var info = {};
    -814 
    -815     // posTLV - extension TLV
    -816     info.posTLV = pos;
    -817 
    -818     var a  = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pos);
    -819     if (a.length != 2 && a.length != 3)
    -820         throw "malformed X.509v3 Ext (code:001)"; // oid,(critical,)val
    -821 
    -822     // oid - extension OID
    -823     if (hCert.substr(a[0], 2) != "06")
    -824         throw "malformed X.509v3 Ext (code:002)"; // not OID "06"
    -825     var valueHex = ASN1HEX.getHexOfV_AtObj(hCert, a[0]);
    -826     info.oid = ASN1HEX.hextooidstr(valueHex);
    -827 
    -828     // critical - extension critical flag
    -829     info.critical = false; // critical false by default
    -830     if (a.length == 3) info.critical = true;
    -831 
    -832     // posV - content TLV position of encapsulated
    -833     //        octet string of V3 extension value.
    -834     var posExtV = a[a.length - 1];
    -835     if (hCert.substr(posExtV, 2) != "04")
    -836         throw "malformed X.509v3 Ext (code:003)"; // not EncapOctet "04"
    -837     info.posV = ASN1HEX.getStartPosOfV_AtObj(hCert, posExtV);
    +789     var a4 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a3[0]);
    +790 
    +791     // 5. v3Extension item position
    +792     var numExt = a4.length;
    +793     var aInfo = new Array(numExt);
    +794     for (var i = 0; i < numExt; i++) {
    +795 	aInfo[i] = X509.getV3ExtItemInfo_AtObj(hCert, a4[i]);
    +796     }
    +797     return aInfo;
    +798 };
    +799 
    +800 /**
    +801  * get X.509 V3 extension value information at the specified position
    +802  * @name getV3ExtItemInfo_AtObj
    +803  * @memberOf X509
    +804  * @function
    +805  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +806  * @param {Integer} pos index of hexadecimal string for the extension
    +807  * @return {Object} properties for the extension
    +808  * @since x509 1.1.5
    +809  * @description
    +810  * This method will get some information of a X.509 V extension
    +811  * which is referred by an index of hexadecimal string of X.509
    +812  * certificate.
    +813  * Resulting object has following properties:
    +814  * <ul>
    +815  * <li>posTLV - index of ASN.1 TLV for the extension. same as 'pos' argument.</li>
    +816  * <li>oid - dot noted string of extension oid (ex. 2.5.29.14)</li>
    +817  * <li>critical - critical flag value for this extension</li>
    +818  * <li>posV - index of ASN.1 TLV for the extension value.
    +819  * This is a position of a content of ENCAPSULATED OCTET STRING.</li>
    +820  * </ul>
    +821  * This method is used by {@link X509.getV3ExtInfoListOfCertHex} internally.
    +822  */
    +823 X509.getV3ExtItemInfo_AtObj = function(hCert, pos) {
    +824     var info = {};
    +825 
    +826     // posTLV - extension TLV
    +827     info.posTLV = pos;
    +828 
    +829     var a  = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pos);
    +830     if (a.length != 2 && a.length != 3)
    +831         throw "malformed X.509v3 Ext (code:001)"; // oid,(critical,)val
    +832 
    +833     // oid - extension OID
    +834     if (hCert.substr(a[0], 2) != "06")
    +835         throw "malformed X.509v3 Ext (code:002)"; // not OID "06"
    +836     var valueHex = ASN1HEX.getHexOfV_AtObj(hCert, a[0]);
    +837     info.oid = ASN1HEX.hextooidstr(valueHex);
     838 
    -839     return info;
    -840 };
    -841 
    -842 /**
    -843  * get X.509 V3 extension value ASN.1 TLV for specified oid or name
    -844  * @name getHexOfTLV_V3ExtValue
    -845  * @memberOf X509
    -846  * @function
    -847  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -848  * @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
    -849  * @return {String} hexadecimal string of extension ASN.1 TLV
    -850  * @since x509 1.1.6
    -851  * @description
    -852  * This method will get X.509v3 extension value of ASN.1 TLV
    -853  * which is specifyed by extension name or oid.
    -854  * If there is no such extension in the certificate, it returns null.
    -855  * @example
    -856  * hExtValue = X509.getHexOfTLV_V3ExtValue(hCert, "keyUsage");
    -857  * // hExtValue will be such like '030205a0'.
    -858  */
    -859 X509.getHexOfTLV_V3ExtValue = function(hCert, oidOrName) {
    -860     var pos = X509.getPosOfTLV_V3ExtValue(hCert, oidOrName);
    -861     if (pos == -1) return null;
    -862     return ASN1HEX.getHexOfTLV_AtObj(hCert, pos);
    -863 };
    -864 
    -865 /**
    -866  * get X.509 V3 extension value ASN.1 V for specified oid or name
    -867  * @name getHexOfV_V3ExtValue
    -868  * @memberOf X509
    -869  * @function
    -870  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -871  * @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
    -872  * @return {String} hexadecimal string of extension ASN.1 TLV
    -873  * @since x509 1.1.6
    -874  * @description
    -875  * This method will get X.509v3 extension value of ASN.1 value
    -876  * which is specifyed by extension name or oid.
    -877  * If there is no such extension in the certificate, it returns null.
    -878  * Available extension names and oids are defined
    -879  * in the {@link KJUR.asn1.x509.OID} class.
    -880  * @example
    -881  * hExtValue = X509.getHexOfV_V3ExtValue(hCert, "keyUsage");
    -882  * // hExtValue will be such like '05a0'.
    -883  */
    -884 X509.getHexOfV_V3ExtValue = function(hCert, oidOrName) {
    -885     var pos = X509.getPosOfTLV_V3ExtValue(hCert, oidOrName);
    -886     if (pos == -1) return null;
    -887     return ASN1HEX.getHexOfV_AtObj(hCert, pos);
    -888 };
    -889 
    -890 /**
    -891  * get index in the certificate hexa string for specified oid or name specified extension
    -892  * @name getPosOfTLV_V3ExtValue
    -893  * @memberOf X509
    -894  * @function
    -895  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -896  * @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
    -897  * @return {Integer} index in the hexadecimal string of certficate for specified extension
    -898  * @since x509 1.1.6
    -899  * @description
    -900  * This method will get X.509v3 extension value of ASN.1 V(value)
    -901  * which is specifyed by extension name or oid.
    -902  * If there is no such extension in the certificate,
    -903  * it returns -1.
    -904  * Available extension names and oids are defined
    -905  * in the {@link KJUR.asn1.x509.OID} class.
    -906  * @example
    -907  * idx = X509.getPosOfV_V3ExtValue(hCert, "keyUsage");
    -908  * // The 'idx' will be index in the string for keyUsage value ASN.1 TLV.
    -909  */
    -910 X509.getPosOfTLV_V3ExtValue = function(hCert, oidOrName) {
    -911     var oid = oidOrName;
    -912     if (! oidOrName.match(/^[0-9.]+$/)) oid = KJUR.asn1.x509.OID.name2oid(oidOrName);
    -913     if (oid == '') return -1;
    -914 
    -915     var infoList = X509.getV3ExtInfoListOfCertHex(hCert);
    -916     for (var i = 0; i < infoList.length; i++) {
    -917 	var info = infoList[i];
    -918 	if (info.oid == oid) return info.posV;
    -919     }
    -920     return -1;
    -921 };
    -922 
    -923 /* ======================================================================
    -924  *   Specific V3 Extensions
    -925  * ====================================================================== */
    -926 
    -927 /**
    -928  * get BasicConstraints extension value as object in the certificate
    -929  * @name getExtBasicConstraints
    -930  * @memberOf X509
    -931  * @function
    -932  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -933  * @return {Object} associative array which may have "cA" and "pathLen" parameters
    -934  * @since x509 1.1.7
    -935  * @description
    -936  * This method will get basic constraints extension value as object with following paramters.
    -937  * <ul>
    -938  * <li>cA - CA flag whether CA or not</li>
    -939  * <li>pathLen - maximum intermediate certificate length</li>
    -940  * </ul>
    -941  * There are use cases for return values:
    -942  * <ul>
    -943  * <li>{cA:true, pathLen:3} - cA flag is true and pathLen is 3</li>
    -944  * <li>{cA:true} - cA flag is true and no pathLen</li>
    -945  * <li>{} - basic constraints has no value in case of end entity certificate</li>
    -946  * <li>null - there is no basic constraints extension</li>
    -947  * </ul>
    -948  * @example
    -949  * obj = X509.getExtBasicConstraints(hCert);
    -950  */
    -951 X509.getExtBasicConstraints = function(hCert) {
    -952     var hBC = X509.getHexOfV_V3ExtValue(hCert, "basicConstraints");
    -953     if (hBC === null) return null;
    -954     if (hBC === '') return {};
    -955     if (hBC === '0101ff') return { "cA": true };
    -956     if (hBC.substr(0, 8) === '0101ff02') {
    -957 	var pathLexHex = ASN1HEX.getHexOfV_AtObj(hBC, 6);
    -958 	var pathLen = parseInt(pathLexHex, 16);
    -959 	return { "cA": true, "pathLen": pathLen };
    -960     }
    -961     throw "unknown error";
    -962 };
    -963 
    -964 X509.KEYUSAGE_NAME = [
    -965     "digitalSignature",
    -966     "nonRepudiation",
    -967     "keyEncipherment",
    -968     "dataEncipherment",
    -969     "keyAgreement",
    -970     "keyCertSign",
    -971     "cRLSign",
    -972     "encipherOnly",
    -973     "decipherOnly"
    -974 ];
    -975 
    -976 /**
    -977  * get KeyUsage extension value as binary string in the certificate
    -978  * @name getExtKeyUsageBin
    -979  * @memberOf X509
    -980  * @function
    -981  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -982  * @return {String} binary string of key usage bits (ex. '101')
    -983  * @since x509 1.1.6
    -984  * @description
    -985  * This method will get key usage extension value
    -986  * as binary string such like '101'.
    -987  * Key usage bits definition is in the RFC 5280.
    -988  * If there is no key usage extension in the certificate,
    -989  * it returns empty string (i.e. '').
    -990  * @example
    -991  * bKeyUsage = X509.getExtKeyUsageBin(hCert);
    -992  * // bKeyUsage will be such like '101'.
    -993  * // 1 - digitalSignature
    -994  * // 0 - nonRepudiation
    -995  * // 1 - keyEncipherment
    -996  */
    -997 X509.getExtKeyUsageBin = function(hCert) {
    -998     var hKeyUsage = X509.getHexOfV_V3ExtValue(hCert, "keyUsage");
    -999     if (hKeyUsage == '') return '';
    -1000     if (hKeyUsage.length % 2 != 0 || hKeyUsage.length <= 2)
    -1001 	throw "malformed key usage value";
    -1002     var unusedBits = parseInt(hKeyUsage.substr(0, 2));
    -1003     var bKeyUsage = parseInt(hKeyUsage.substr(2), 16).toString(2);
    -1004     return bKeyUsage.substr(0, bKeyUsage.length - unusedBits);
    -1005 };
    -1006 
    -1007 /**
    -1008  * get KeyUsage extension value as names in the certificate
    -1009  * @name getExtKeyUsageString
    -1010  * @memberOf X509
    -1011  * @function
    -1012  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1013  * @return {String} comma separated string of key usage
    -1014  * @since x509 1.1.6
    -1015  * @description
    -1016  * This method will get key usage extension value
    -1017  * as comma separated string of usage names.
    -1018  * If there is no key usage extension in the certificate,
    -1019  * it returns empty string (i.e. '').
    -1020  * @example
    -1021  * sKeyUsage = X509.getExtKeyUsageString(hCert);
    -1022  * // sKeyUsage will be such like 'digitalSignature,keyEncipherment'.
    -1023  */
    -1024 X509.getExtKeyUsageString = function(hCert) {
    -1025     var bKeyUsage = X509.getExtKeyUsageBin(hCert);
    -1026     var a = new Array();
    -1027     for (var i = 0; i < bKeyUsage.length; i++) {
    -1028 	if (bKeyUsage.substr(i, 1) == "1") a.push(X509.KEYUSAGE_NAME[i]);
    -1029     }
    -1030     return a.join(",");
    -1031 };
    -1032 
    -1033 /**
    -1034  * get subjectKeyIdentifier value as hexadecimal string in the certificate
    -1035  * @name getExtSubjectKeyIdentifier
    -1036  * @memberOf X509
    -1037  * @function
    -1038  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1039  * @return {String} hexadecimal string of subject key identifier or null
    -1040  * @since jsrsasign 5.0.10 x509 1.1.8
    -1041  * @description
    -1042  * This method will get subject key identifier extension value
    -1043  * as hexadecimal string.
    -1044  * If there is no its extension in the certificate,
    -1045  * it returns null.
    -1046  * @example
    -1047  * skid = X509.getExtSubjectKeyIdentifier(hCert);
    -1048  */
    -1049 X509.getExtSubjectKeyIdentifier = function(hCert) {
    -1050     var hSKID = X509.getHexOfV_V3ExtValue(hCert, "subjectKeyIdentifier");
    -1051     return hSKID;
    -1052 };
    -1053 
    -1054 /**
    -1055  * get authorityKeyIdentifier value as JSON object in the certificate
    -1056  * @name getExtAuthorityKeyIdentifier
    -1057  * @memberOf X509
    -1058  * @function
    -1059  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1060  * @return {Object} JSON object of authority key identifier or null
    -1061  * @since jsrsasign 5.0.10 x509 1.1.8
    -1062  * @description
    -1063  * This method will get authority key identifier extension value
    -1064  * as JSON object.
    -1065  * If there is no its extension in the certificate,
    -1066  * it returns null.
    -1067  * <br>
    -1068  * NOTE: Currently this method only supports keyIdentifier so that
    -1069  * authorityCertIssuer and authorityCertSerialNumber will not
    -1070  * be return in the JSON object.
    -1071  * @example
    -1072  * akid = X509.getExtAuthorityKeyIdentifier(hCert);
    -1073  * // returns following JSON object
    -1074  * { kid: "1234abcd..." }
    -1075  */
    -1076 X509.getExtAuthorityKeyIdentifier = function(hCert) {
    -1077     var result = {};
    -1078     var hAKID = X509.getHexOfTLV_V3ExtValue(hCert, "authorityKeyIdentifier");
    -1079     if (hAKID === null) return null;
    -1080 
    -1081     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hAKID, 0);
    -1082     for (var i = 0; i < a.length; i++) {
    -1083 	if (hAKID.substr(a[i], 2) === "80")
    -1084 	    result.kid = ASN1HEX.getHexOfV_AtObj(hAKID, a[i]);
    -1085     }
    -1086 
    -1087     return result;
    -1088 };
    -1089 
    -1090 /**
    -1091  * get extKeyUsage value as array of name string in the certificate
    -1092  * @name getExtExtKeyUsageName
    -1093  * @memberOf X509
    -1094  * @function
    -1095  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1096  * @return {Object} array of extended key usage ID name or oid
    -1097  * @since jsrsasign 5.0.10 x509 1.1.8
    -1098  * @description
    -1099  * This method will get extended key usage extension value
    -1100  * as array of name or OID string.
    -1101  * If there is no its extension in the certificate,
    -1102  * it returns null.
    -1103  * <br>
    -1104  * NOTE: Supported extended key usage ID names are defined in
    -1105  * name2oidList parameter in asn1x509.js file.
    -1106  * @example
    -1107  * eku = X509.getExtExtKeyUsageName(hCert);
    -1108  * // returns following array:
    -1109  * ["serverAuth", "clientAuth", "0.1.2.3.4.5"]
    -1110  */
    -1111 X509.getExtExtKeyUsageName = function(hCert) {
    -1112     var result = new Array();
    -1113     var h = X509.getHexOfTLV_V3ExtValue(hCert, "extKeyUsage");
    -1114     if (h === null) return null;
    -1115 
    -1116     var a = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    -1117     for (var i = 0; i < a.length; i++) {
    -1118 	var hex = ASN1HEX.getHexOfV_AtObj(h, a[i]);
    -1119 	var oid = KJUR.asn1.ASN1Util.oidHexToInt(hex);
    -1120 	var name = KJUR.asn1.x509.OID.oid2name(oid);
    -1121 	result.push(name);
    -1122     }
    -1123 
    -1124     return result;
    -1125 };
    +839     // critical - extension critical flag
    +840     info.critical = false; // critical false by default
    +841     if (a.length == 3) info.critical = true;
    +842 
    +843     // posV - content TLV position of encapsulated
    +844     //        octet string of V3 extension value.
    +845     var posExtV = a[a.length - 1];
    +846     if (hCert.substr(posExtV, 2) != "04")
    +847         throw "malformed X.509v3 Ext (code:003)"; // not EncapOctet "04"
    +848     info.posV = ASN1HEX.getStartPosOfV_AtObj(hCert, posExtV);
    +849 
    +850     return info;
    +851 };
    +852 
    +853 /**
    +854  * get X.509 V3 extension value ASN.1 TLV for specified oid or name
    +855  * @name getHexOfTLV_V3ExtValue
    +856  * @memberOf X509
    +857  * @function
    +858  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +859  * @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
    +860  * @return {String} hexadecimal string of extension ASN.1 TLV
    +861  * @since x509 1.1.6
    +862  * @description
    +863  * This method will get X.509v3 extension value of ASN.1 TLV
    +864  * which is specifyed by extension name or oid.
    +865  * If there is no such extension in the certificate, it returns null.
    +866  * @example
    +867  * hExtValue = X509.getHexOfTLV_V3ExtValue(hCert, "keyUsage");
    +868  * // hExtValue will be such like '030205a0'.
    +869  */
    +870 X509.getHexOfTLV_V3ExtValue = function(hCert, oidOrName) {
    +871     var pos = X509.getPosOfTLV_V3ExtValue(hCert, oidOrName);
    +872     if (pos == -1) return null;
    +873     return ASN1HEX.getHexOfTLV_AtObj(hCert, pos);
    +874 };
    +875 
    +876 /**
    +877  * get X.509 V3 extension value ASN.1 V for specified oid or name
    +878  * @name getHexOfV_V3ExtValue
    +879  * @memberOf X509
    +880  * @function
    +881  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +882  * @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
    +883  * @return {String} hexadecimal string of extension ASN.1 TLV
    +884  * @since x509 1.1.6
    +885  * @description
    +886  * This method will get X.509v3 extension value of ASN.1 value
    +887  * which is specifyed by extension name or oid.
    +888  * If there is no such extension in the certificate, it returns null.
    +889  * Available extension names and oids are defined
    +890  * in the {@link KJUR.asn1.x509.OID} class.
    +891  * @example
    +892  * hExtValue = X509.getHexOfV_V3ExtValue(hCert, "keyUsage");
    +893  * // hExtValue will be such like '05a0'.
    +894  */
    +895 X509.getHexOfV_V3ExtValue = function(hCert, oidOrName) {
    +896     var pos = X509.getPosOfTLV_V3ExtValue(hCert, oidOrName);
    +897     if (pos == -1) return null;
    +898     return ASN1HEX.getHexOfV_AtObj(hCert, pos);
    +899 };
    +900 
    +901 /**
    +902  * get index in the certificate hexa string for specified oid or name specified extension
    +903  * @name getPosOfTLV_V3ExtValue
    +904  * @memberOf X509
    +905  * @function
    +906  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +907  * @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
    +908  * @return {Integer} index in the hexadecimal string of certficate for specified extension
    +909  * @since x509 1.1.6
    +910  * @description
    +911  * This method will get X.509v3 extension value of ASN.1 V(value)
    +912  * which is specifyed by extension name or oid.
    +913  * If there is no such extension in the certificate,
    +914  * it returns -1.
    +915  * Available extension names and oids are defined
    +916  * in the {@link KJUR.asn1.x509.OID} class.
    +917  * @example
    +918  * idx = X509.getPosOfV_V3ExtValue(hCert, "keyUsage");
    +919  * // The 'idx' will be index in the string for keyUsage value ASN.1 TLV.
    +920  */
    +921 X509.getPosOfTLV_V3ExtValue = function(hCert, oidOrName) {
    +922     var oid = oidOrName;
    +923     if (! oidOrName.match(/^[0-9.]+$/)) oid = KJUR.asn1.x509.OID.name2oid(oidOrName);
    +924     if (oid == '') return -1;
    +925 
    +926     var infoList = X509.getV3ExtInfoListOfCertHex(hCert);
    +927     for (var i = 0; i < infoList.length; i++) {
    +928 	var info = infoList[i];
    +929 	if (info.oid == oid) return info.posV;
    +930     }
    +931     return -1;
    +932 };
    +933 
    +934 /* ======================================================================
    +935  *   Specific V3 Extensions
    +936  * ====================================================================== */
    +937 
    +938 /**
    +939  * get BasicConstraints extension value as object in the certificate
    +940  * @name getExtBasicConstraints
    +941  * @memberOf X509
    +942  * @function
    +943  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +944  * @return {Object} associative array which may have "cA" and "pathLen" parameters
    +945  * @since x509 1.1.7
    +946  * @description
    +947  * This method will get basic constraints extension value as object with following paramters.
    +948  * <ul>
    +949  * <li>cA - CA flag whether CA or not</li>
    +950  * <li>pathLen - maximum intermediate certificate length</li>
    +951  * </ul>
    +952  * There are use cases for return values:
    +953  * <ul>
    +954  * <li>{cA:true, pathLen:3} - cA flag is true and pathLen is 3</li>
    +955  * <li>{cA:true} - cA flag is true and no pathLen</li>
    +956  * <li>{} - basic constraints has no value in case of end entity certificate</li>
    +957  * <li>null - there is no basic constraints extension</li>
    +958  * </ul>
    +959  * @example
    +960  * obj = X509.getExtBasicConstraints(hCert);
    +961  */
    +962 X509.getExtBasicConstraints = function(hCert) {
    +963     var hBC = X509.getHexOfV_V3ExtValue(hCert, "basicConstraints");
    +964     if (hBC === null) return null;
    +965     if (hBC === '') return {};
    +966     if (hBC === '0101ff') return { "cA": true };
    +967     if (hBC.substr(0, 8) === '0101ff02') {
    +968 	var pathLexHex = ASN1HEX.getHexOfV_AtObj(hBC, 6);
    +969 	var pathLen = parseInt(pathLexHex, 16);
    +970 	return { "cA": true, "pathLen": pathLen };
    +971     }
    +972     throw "unknown error";
    +973 };
    +974 
    +975 X509.KEYUSAGE_NAME = [
    +976     "digitalSignature",
    +977     "nonRepudiation",
    +978     "keyEncipherment",
    +979     "dataEncipherment",
    +980     "keyAgreement",
    +981     "keyCertSign",
    +982     "cRLSign",
    +983     "encipherOnly",
    +984     "decipherOnly"
    +985 ];
    +986 
    +987 /**
    +988  * get KeyUsage extension value as binary string in the certificate
    +989  * @name getExtKeyUsageBin
    +990  * @memberOf X509
    +991  * @function
    +992  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +993  * @return {String} binary string of key usage bits (ex. '101')
    +994  * @since x509 1.1.6
    +995  * @description
    +996  * This method will get key usage extension value
    +997  * as binary string such like '101'.
    +998  * Key usage bits definition is in the RFC 5280.
    +999  * If there is no key usage extension in the certificate,
    +1000  * it returns empty string (i.e. '').
    +1001  * @example
    +1002  * bKeyUsage = X509.getExtKeyUsageBin(hCert);
    +1003  * // bKeyUsage will be such like '101'.
    +1004  * // 1 - digitalSignature
    +1005  * // 0 - nonRepudiation
    +1006  * // 1 - keyEncipherment
    +1007  */
    +1008 X509.getExtKeyUsageBin = function(hCert) {
    +1009     var hKeyUsage = X509.getHexOfV_V3ExtValue(hCert, "keyUsage");
    +1010     if (hKeyUsage == '') return '';
    +1011     if (hKeyUsage.length % 2 != 0 || hKeyUsage.length <= 2)
    +1012 	throw "malformed key usage value";
    +1013     var unusedBits = parseInt(hKeyUsage.substr(0, 2));
    +1014     var bKeyUsage = parseInt(hKeyUsage.substr(2), 16).toString(2);
    +1015     return bKeyUsage.substr(0, bKeyUsage.length - unusedBits);
    +1016 };
    +1017 
    +1018 /**
    +1019  * get KeyUsage extension value as names in the certificate
    +1020  * @name getExtKeyUsageString
    +1021  * @memberOf X509
    +1022  * @function
    +1023  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +1024  * @return {String} comma separated string of key usage
    +1025  * @since x509 1.1.6
    +1026  * @description
    +1027  * This method will get key usage extension value
    +1028  * as comma separated string of usage names.
    +1029  * If there is no key usage extension in the certificate,
    +1030  * it returns empty string (i.e. '').
    +1031  * @example
    +1032  * sKeyUsage = X509.getExtKeyUsageString(hCert);
    +1033  * // sKeyUsage will be such like 'digitalSignature,keyEncipherment'.
    +1034  */
    +1035 X509.getExtKeyUsageString = function(hCert) {
    +1036     var bKeyUsage = X509.getExtKeyUsageBin(hCert);
    +1037     var a = new Array();
    +1038     for (var i = 0; i < bKeyUsage.length; i++) {
    +1039 	if (bKeyUsage.substr(i, 1) == "1") a.push(X509.KEYUSAGE_NAME[i]);
    +1040     }
    +1041     return a.join(",");
    +1042 };
    +1043 
    +1044 /**
    +1045  * get subjectKeyIdentifier value as hexadecimal string in the certificate
    +1046  * @name getExtSubjectKeyIdentifier
    +1047  * @memberOf X509
    +1048  * @function
    +1049  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +1050  * @return {String} hexadecimal string of subject key identifier or null
    +1051  * @since jsrsasign 5.0.10 x509 1.1.8
    +1052  * @description
    +1053  * This method will get subject key identifier extension value
    +1054  * as hexadecimal string.
    +1055  * If there is no its extension in the certificate,
    +1056  * it returns null.
    +1057  * @example
    +1058  * skid = X509.getExtSubjectKeyIdentifier(hCert);
    +1059  */
    +1060 X509.getExtSubjectKeyIdentifier = function(hCert) {
    +1061     var hSKID = X509.getHexOfV_V3ExtValue(hCert, "subjectKeyIdentifier");
    +1062     return hSKID;
    +1063 };
    +1064 
    +1065 /**
    +1066  * get authorityKeyIdentifier value as JSON object in the certificate
    +1067  * @name getExtAuthorityKeyIdentifier
    +1068  * @memberOf X509
    +1069  * @function
    +1070  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +1071  * @return {Object} JSON object of authority key identifier or null
    +1072  * @since jsrsasign 5.0.10 x509 1.1.8
    +1073  * @description
    +1074  * This method will get authority key identifier extension value
    +1075  * as JSON object.
    +1076  * If there is no its extension in the certificate,
    +1077  * it returns null.
    +1078  * <br>
    +1079  * NOTE: Currently this method only supports keyIdentifier so that
    +1080  * authorityCertIssuer and authorityCertSerialNumber will not
    +1081  * be return in the JSON object.
    +1082  * @example
    +1083  * akid = X509.getExtAuthorityKeyIdentifier(hCert);
    +1084  * // returns following JSON object
    +1085  * { kid: "1234abcd..." }
    +1086  */
    +1087 X509.getExtAuthorityKeyIdentifier = function(hCert) {
    +1088     var result = {};
    +1089     var hAKID = X509.getHexOfTLV_V3ExtValue(hCert, "authorityKeyIdentifier");
    +1090     if (hAKID === null) return null;
    +1091 
    +1092     var a = ASN1HEX.getPosArrayOfChildren_AtObj(hAKID, 0);
    +1093     for (var i = 0; i < a.length; i++) {
    +1094 	if (hAKID.substr(a[i], 2) === "80")
    +1095 	    result.kid = ASN1HEX.getHexOfV_AtObj(hAKID, a[i]);
    +1096     }
    +1097 
    +1098     return result;
    +1099 };
    +1100 
    +1101 /**
    +1102  * get extKeyUsage value as array of name string in the certificate
    +1103  * @name getExtExtKeyUsageName
    +1104  * @memberOf X509
    +1105  * @function
    +1106  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +1107  * @return {Object} array of extended key usage ID name or oid
    +1108  * @since jsrsasign 5.0.10 x509 1.1.8
    +1109  * @description
    +1110  * This method will get extended key usage extension value
    +1111  * as array of name or OID string.
    +1112  * If there is no its extension in the certificate,
    +1113  * it returns null.
    +1114  * <br>
    +1115  * NOTE: Supported extended key usage ID names are defined in
    +1116  * name2oidList parameter in asn1x509.js file.
    +1117  * @example
    +1118  * eku = X509.getExtExtKeyUsageName(hCert);
    +1119  * // returns following array:
    +1120  * ["serverAuth", "clientAuth", "0.1.2.3.4.5"]
    +1121  */
    +1122 X509.getExtExtKeyUsageName = function(hCert) {
    +1123     var result = new Array();
    +1124     var h = X509.getHexOfTLV_V3ExtValue(hCert, "extKeyUsage");
    +1125     if (h === null) return null;
     1126 
    -1127 /**
    -1128  * get subjectAltName value as array of string in the certificate
    -1129  * @name getExtSubjectAltName
    -1130  * @memberOf X509
    -1131  * @function
    -1132  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1133  * @return {Object} array of alt names
    -1134  * @since jsrsasign 5.0.10 x509 1.1.8
    -1135  * @description
    -1136  * This method will get subject alt name extension value
    -1137  * as array of name.
    -1138  * If there is no its extension in the certificate,
    -1139  * it returns null.
    -1140  * <br>
    -1141  * NOTE: Currently this method supports only dNSName so that
    -1142  * other name type such like iPAddress or generalName will not be returned.
    -1143  * @example
    -1144  * san = X509.getExtSubjectAltName(hCert);
    -1145  * // returns following array:
    -1146  * ["example.com", "example.org"]
    -1147  */
    -1148 X509.getExtSubjectAltName = function(hCert) {
    -1149     var result = new Array();
    -1150     var h = X509.getHexOfTLV_V3ExtValue(hCert, "subjectAltName");
    -1151 
    -1152     var a = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    -1153     for (var i = 0; i < a.length; i++) {
    -1154 	if (h.substr(a[i], 2) === "82") {
    -1155 	    var fqdn = hextoutf8(ASN1HEX.getHexOfV_AtObj(h, a[i]));
    -1156 	    result.push(fqdn);
    -1157 	}
    -1158     }
    -1159 
    -1160     return result;
    -1161 };
    +1127     var a = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    +1128     for (var i = 0; i < a.length; i++) {
    +1129 	var hex = ASN1HEX.getHexOfV_AtObj(h, a[i]);
    +1130 	var oid = KJUR.asn1.ASN1Util.oidHexToInt(hex);
    +1131 	var name = KJUR.asn1.x509.OID.oid2name(oid);
    +1132 	result.push(name);
    +1133     }
    +1134 
    +1135     return result;
    +1136 };
    +1137 
    +1138 /**
    +1139  * get subjectAltName value as array of string in the certificate
    +1140  * @name getExtSubjectAltName
    +1141  * @memberOf X509
    +1142  * @function
    +1143  * @param {String} hCert hexadecimal string of X.509 certificate binary
    +1144  * @return {Object} array of alt names
    +1145  * @since jsrsasign 5.0.10 x509 1.1.8
    +1146  * @description
    +1147  * This method will get subject alt name extension value
    +1148  * as array of name.
    +1149  * If there is no its extension in the certificate,
    +1150  * it returns null.
    +1151  * <br>
    +1152  * NOTE: Currently this method supports only dNSName so that
    +1153  * other name type such like iPAddress or generalName will not be returned.
    +1154  * @example
    +1155  * san = X509.getExtSubjectAltName(hCert);
    +1156  * // returns following array:
    +1157  * ["example.com", "example.org"]
    +1158  */
    +1159 X509.getExtSubjectAltName = function(hCert) {
    +1160     var result = new Array();
    +1161     var h = X509.getHexOfTLV_V3ExtValue(hCert, "subjectAltName");
     1162 
    -1163 /**
    -1164  * get array of string for fullName URIs in cRLDistributionPoints(CDP) in the certificate
    -1165  * @name getExtCRLDistributionPointsURI
    -1166  * @memberOf X509
    -1167  * @function
    -1168  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1169  * @return {Object} array of fullName URIs of CDP of the certificate
    -1170  * @since jsrsasign 5.0.10 x509 1.1.8
    -1171  * @description
    -1172  * This method will get all fullName URIs of cRLDistributionPoints extension
    -1173  * in the certificate as array of URI string.
    -1174  * If there is no its extension in the certificate,
    -1175  * it returns null.
    -1176  * <br>
    -1177  * NOTE: Currently this method supports only fullName URI so that
    -1178  * other parameters will not be returned.
    -1179  * @example
    -1180  * cdpuri = X509.getExtCRLDistributionPointsURI(hCert);
    -1181  * // returns following array:
    -1182  * ["http://example.com/aaa.crl", "http://example.org/aaa.crl"]
    -1183  */
    -1184 X509.getExtCRLDistributionPointsURI = function(hCert) {
    -1185     var result = new Array();
    -1186     var h = X509.getHexOfTLV_V3ExtValue(hCert, "cRLDistributionPoints");
    -1187 
    -1188     var a = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0);
    -1189     for (var i = 0; i < a.length; i++) {
    -1190 	var hDP = ASN1HEX.getHexOfTLV_AtObj(h, a[i]);
    -1191 
    -1192 	var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hDP, 0);
    -1193 	for (var j = 0; j < a1.length; j++) {
    -1194 	    if (hDP.substr(a1[j], 2) === "a0") {
    -1195 		var hDPN = ASN1HEX.getHexOfV_AtObj(hDP, a1[j]);
    -1196 		if (hDPN.substr(0, 2) === "a0") {
    -1197 		    var hFullName = ASN1HEX.getHexOfV_AtObj(hDPN, 0);
    -1198 		    if (hFullName.substr(0, 2) === "86") {
    -1199 			var hURI = ASN1HEX.getHexOfV_AtObj(hFullName, 0);
    -1200 			var uri = hextoutf8(hURI);
    -1201 			result.push(uri);
    -1202 		    }
    -1203 		}
    -1204 	    }
    -1205 	}
    -1206     }
    -1207 
    -1208     return result;
    -1209 };
    -1210 
    -1211 /**
    -1212  * get AuthorityInfoAccess extension value in the certificate as associative array
    -1213  * @name getExtAIAInfo
    -1214  * @memberOf X509
    -1215  * @function
    -1216  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1217  * @return {Object} associative array of AIA extension properties
    -1218  * @since x509 1.1.6
    -1219  * @description
    -1220  * This method will get authority info access value
    -1221  * as associate array which has following properties:
    -1222  * <ul>
    -1223  * <li>ocsp - array of string for OCSP responder URL</li>
    -1224  * <li>caissuer - array of string for caIssuer value (i.e. CA certificates URL)</li>
    -1225  * </ul>
    -1226  * If there is no key usage extension in the certificate,
    -1227  * it returns null;
    -1228  * @example
    -1229  * oAIA = X509.getExtAIAInfo(hCert);
    -1230  * // result will be such like:
    -1231  * // oAIA.ocsp = ["http://ocsp.foo.com"];
    -1232  * // oAIA.caissuer = ["http://rep.foo.com/aaa.p8m"];
    -1233  */
    -1234 X509.getExtAIAInfo = function(hCert) {
    -1235     var result = {};
    -1236     result.ocsp = [];
    -1237     result.caissuer = [];
    -1238     var pos1 = X509.getPosOfTLV_V3ExtValue(hCert, "authorityInfoAccess");
    -1239     if (pos1 == -1) return null;
    -1240     if (hCert.substr(pos1, 2) != "30") // extnValue SEQUENCE
    -1241 	throw "malformed AIA Extn Value";
    -1242 
    -1243     var posAccDescList = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pos1);
    -1244     for (var i = 0; i < posAccDescList.length; i++) {
    -1245 	var p = posAccDescList[i];
    -1246 	var posAccDescChild = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, p);
    -1247 	if (posAccDescChild.length != 2)
    -1248 	    throw "malformed AccessDescription of AIA Extn";
    -1249 	var pOID = posAccDescChild[0];
    -1250 	var pName = posAccDescChild[1];
    -1251 	if (ASN1HEX.getHexOfV_AtObj(hCert, pOID) == "2b06010505073001") {
    -1252 	    if (hCert.substr(pName, 2) == "86") {
    -1253 		result.ocsp.push(hextoutf8(ASN1HEX.getHexOfV_AtObj(hCert, pName)));
    -1254 	    }
    -1255 	}
    -1256 	if (ASN1HEX.getHexOfV_AtObj(hCert, pOID) == "2b06010505073002") {
    -1257 	    if (hCert.substr(pName, 2) == "86") {
    -1258 		result.caissuer.push(hextoutf8(ASN1HEX.getHexOfV_AtObj(hCert, pName)));
    -1259 	    }
    -1260 	}
    -1261     }
    -1262     return result;
    -1263 };
    -1264 
    -1265 /**
    -1266  * get signature algorithm name from hexadecimal certificate data
    -1267  * @name getSignatureAlgorithmName
    -1268  * @memberOf X509
    -1269  * @function
    -1270  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1271  * @return {String} signature algorithm name (ex. SHA1withRSA, SHA256withECDSA)
    -1272  * @since x509 1.1.7
    -1273  * @description
    -1274  * This method will get signature algorithm name of certificate:
    -1275  * @example
    -1276  * algName = X509.getSignatureAlgorithmName(hCert);
    -1277  */
    -1278 X509.getSignatureAlgorithmName = function(hCert) {
    -1279     var sigAlgOidHex = ASN1HEX.getDecendantHexVByNthList(hCert, 0, [1, 0]);
    -1280     var sigAlgOidInt = KJUR.asn1.ASN1Util.oidHexToInt(sigAlgOidHex);
    -1281     var sigAlgName = KJUR.asn1.x509.OID.oid2name(sigAlgOidInt);
    -1282     return sigAlgName;
    -1283 };
    -1284 
    -1285 /**
    -1286  * get signature value in hexadecimal string
    -1287  * @name getSignatureValueHex
    -1288  * @memberOf X509
    -1289  * @function
    -1290  * @param {String} hCert hexadecimal string of X.509 certificate binary
    -1291  * @return {String} signature value hexadecimal string without BitString unused bits
    -1292  * @since x509 1.1.7
    -1293  * @description
    -1294  * This method will get signature value of certificate:
    -1295  * @example
    -1296  * sigHex = X509.getSignatureValueHex(hCert);
    -1297  */
    -1298 X509.getSignatureValueHex = function(hCert) {
    -1299     var h = ASN1HEX.getDecendantHexVByNthList(hCert, 0, [2]);
    -1300     if (h.substr(0, 2) !== "00")
    -1301 	throw "can't get signature value";
    -1302     return h.substr(2);
    -1303 };
    -1304 
    -1305 X509.getSerialNumberHex = function(hCert) {
    -1306     return ASN1HEX.getDecendantHexVByNthList(hCert, 0, [0, 1]);
    -1307 };
    -1308 
    -1309 /*
    -1310   X509.prototype.readCertPEM = _x509_readCertPEM;
    -1311   X509.prototype.readCertPEMWithoutRSAInit = _x509_readCertPEMWithoutRSAInit;
    -1312   X509.prototype.getSerialNumberHex = _x509_getSerialNumberHex;
    -1313   X509.prototype.getIssuerHex = _x509_getIssuerHex;
    -1314   X509.prototype.getSubjectHex = _x509_getSubjectHex;
    -1315   X509.prototype.getIssuerString = _x509_getIssuerString;
    -1316   X509.prototype.getSubjectString = _x509_getSubjectString;
    -1317   X509.prototype.getNotBefore = _x509_getNotBefore;
    -1318   X509.prototype.getNotAfter = _x509_getNotAfter;
    -1319 */
    -1320 
    \ No newline at end of file +1163
    var a = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0); +1164 for (var i = 0; i < a.length; i++) { +1165 if (h.substr(a[i], 2) === "82") { +1166 var fqdn = hextoutf8(ASN1HEX.getHexOfV_AtObj(h, a[i])); +1167 result.push(fqdn); +1168 } +1169 } +1170 +1171 return result; +1172 }; +1173 +1174 /** +1175 * get array of string for fullName URIs in cRLDistributionPoints(CDP) in the certificate +1176 * @name getExtCRLDistributionPointsURI +1177 * @memberOf X509 +1178 * @function +1179 * @param {String} hCert hexadecimal string of X.509 certificate binary +1180 * @return {Object} array of fullName URIs of CDP of the certificate +1181 * @since jsrsasign 5.0.10 x509 1.1.8 +1182 * @description +1183 * This method will get all fullName URIs of cRLDistributionPoints extension +1184 * in the certificate as array of URI string. +1185 * If there is no its extension in the certificate, +1186 * it returns null. +1187 * <br> +1188 * NOTE: Currently this method supports only fullName URI so that +1189 * other parameters will not be returned. +1190 * @example +1191 * cdpuri = X509.getExtCRLDistributionPointsURI(hCert); +1192 * // returns following array: +1193 * ["http://example.com/aaa.crl", "http://example.org/aaa.crl"] +1194 */ +1195 X509.getExtCRLDistributionPointsURI = function(hCert) { +1196 var result = new Array(); +1197 var h = X509.getHexOfTLV_V3ExtValue(hCert, "cRLDistributionPoints"); +1198 +1199 var a = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0); +1200 for (var i = 0; i < a.length; i++) { +1201 var hDP = ASN1HEX.getHexOfTLV_AtObj(h, a[i]); +1202 +1203 var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hDP, 0); +1204 for (var j = 0; j < a1.length; j++) { +1205 if (hDP.substr(a1[j], 2) === "a0") { +1206 var hDPN = ASN1HEX.getHexOfV_AtObj(hDP, a1[j]); +1207 if (hDPN.substr(0, 2) === "a0") { +1208 var hFullName = ASN1HEX.getHexOfV_AtObj(hDPN, 0); +1209 if (hFullName.substr(0, 2) === "86") { +1210 var hURI = ASN1HEX.getHexOfV_AtObj(hFullName, 0); +1211 var uri = hextoutf8(hURI); +1212 result.push(uri); +1213 } +1214 } +1215 } +1216 } +1217 } +1218 +1219 return result; +1220 }; +1221 +1222 /** +1223 * get AuthorityInfoAccess extension value in the certificate as associative array +1224 * @name getExtAIAInfo +1225 * @memberOf X509 +1226 * @function +1227 * @param {String} hCert hexadecimal string of X.509 certificate binary +1228 * @return {Object} associative array of AIA extension properties +1229 * @since x509 1.1.6 +1230 * @description +1231 * This method will get authority info access value +1232 * as associate array which has following properties: +1233 * <ul> +1234 * <li>ocsp - array of string for OCSP responder URL</li> +1235 * <li>caissuer - array of string for caIssuer value (i.e. CA certificates URL)</li> +1236 * </ul> +1237 * If there is no key usage extension in the certificate, +1238 * it returns null; +1239 * @example +1240 * oAIA = X509.getExtAIAInfo(hCert); +1241 * // result will be such like: +1242 * // oAIA.ocsp = ["http://ocsp.foo.com"]; +1243 * // oAIA.caissuer = ["http://rep.foo.com/aaa.p8m"]; +1244 */ +1245 X509.getExtAIAInfo = function(hCert) { +1246 var result = {}; +1247 result.ocsp = []; +1248 result.caissuer = []; +1249 var pos1 = X509.getPosOfTLV_V3ExtValue(hCert, "authorityInfoAccess"); +1250 if (pos1 == -1) return null; +1251 if (hCert.substr(pos1, 2) != "30") // extnValue SEQUENCE +1252 throw "malformed AIA Extn Value"; +1253 +1254 var posAccDescList = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pos1); +1255 for (var i = 0; i < posAccDescList.length; i++) { +1256 var p = posAccDescList[i]; +1257 var posAccDescChild = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, p); +1258 if (posAccDescChild.length != 2) +1259 throw "malformed AccessDescription of AIA Extn"; +1260 var pOID = posAccDescChild[0]; +1261 var pName = posAccDescChild[1]; +1262 if (ASN1HEX.getHexOfV_AtObj(hCert, pOID) == "2b06010505073001") { +1263 if (hCert.substr(pName, 2) == "86") { +1264 result.ocsp.push(hextoutf8(ASN1HEX.getHexOfV_AtObj(hCert, pName))); +1265 } +1266 } +1267 if (ASN1HEX.getHexOfV_AtObj(hCert, pOID) == "2b06010505073002") { +1268 if (hCert.substr(pName, 2) == "86") { +1269 result.caissuer.push(hextoutf8(ASN1HEX.getHexOfV_AtObj(hCert, pName))); +1270 } +1271 } +1272 } +1273 return result; +1274 }; +1275 +1276 /** +1277 * get signature algorithm name from hexadecimal certificate data +1278 * @name getSignatureAlgorithmName +1279 * @memberOf X509 +1280 * @function +1281 * @param {String} hCert hexadecimal string of X.509 certificate binary +1282 * @return {String} signature algorithm name (ex. SHA1withRSA, SHA256withECDSA) +1283 * @since x509 1.1.7 +1284 * @description +1285 * This method will get signature algorithm name of certificate: +1286 * @example +1287 * algName = X509.getSignatureAlgorithmName(hCert); +1288 */ +1289 X509.getSignatureAlgorithmName = function(hCert) { +1290 var sigAlgOidHex = ASN1HEX.getDecendantHexVByNthList(hCert, 0, [1, 0]); +1291 var sigAlgOidInt = KJUR.asn1.ASN1Util.oidHexToInt(sigAlgOidHex); +1292 var sigAlgName = KJUR.asn1.x509.OID.oid2name(sigAlgOidInt); +1293 return sigAlgName; +1294 }; +1295 +1296 /** +1297 * get signature value in hexadecimal string +1298 * @name getSignatureValueHex +1299 * @memberOf X509 +1300 * @function +1301 * @param {String} hCert hexadecimal string of X.509 certificate binary +1302 * @return {String} signature value hexadecimal string without BitString unused bits +1303 * @since x509 1.1.7 +1304 * @description +1305 * This method will get signature value of certificate: +1306 * @example +1307 * sigHex = X509.getSignatureValueHex(hCert); +1308 */ +1309 X509.getSignatureValueHex = function(hCert) { +1310 var h = ASN1HEX.getDecendantHexVByNthList(hCert, 0, [2]); +1311 if (h.substr(0, 2) !== "00") +1312 throw "can't get signature value"; +1313 return h.substr(2); +1314 }; +1315 +1316 X509.getSerialNumberHex = function(hCert) { +1317 return ASN1HEX.getDecendantHexVByNthList(hCert, 0, [0, 1]); +1318 }; +1319 +1320 /* +1321 X509.prototype.readCertPEM = _x509_readCertPEM; +1322 X509.prototype.readCertPEMWithoutRSAInit = _x509_readCertPEMWithoutRSAInit; +1323 X509.prototype.getSerialNumberHex = _x509_getSerialNumberHex; +1324 X509.prototype.getIssuerHex = _x509_getIssuerHex; +1325 X509.prototype.getSubjectHex = _x509_getSubjectHex; +1326 X509.prototype.getIssuerString = _x509_getIssuerString; +1327 X509.prototype.getSubjectString = _x509_getSubjectString; +1328 X509.prototype.getNotBefore = _x509_getNotBefore; +1329 X509.prototype.getNotAfter = _x509_getNotAfter; +1330 */ +1331
    \ No newline at end of file diff --git a/asn1cades-1.0.js b/asn1cades-1.0.js index c1807561..2f5d02cb 100755 --- a/asn1cades-1.0.js +++ b/asn1cades-1.0.js @@ -1,9 +1,9 @@ -/*! asn1cades-1.0.0.js (c) 2013-2014 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! asn1cades-1.0.1.js (c) 2014-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * asn1cades.js - ASN.1 DER encoder classes for RFC 5126 CAdES long term signature * - * Copyright (c) 2014 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2014-2017 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license @@ -16,7 +16,7 @@ * @fileOverview * @name asn1cades-1.0.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version 1.0.0 (2014-May-28) + * @version 1.0.1 (2017-Jan-14) * @since jsrsasign 4.7.0 * @license MIT License */ @@ -513,7 +513,7 @@ KJUR.asn1.cades.OtherHash = function(params) { this.setByCertPEM = function(certPEM) { if (certPEM.indexOf("-----BEGIN ") == -1) throw "certPEM not to seem PEM format"; - var hex = X509.pemToHex(certPEM); + var hex = ASN1HEX.pemToHex(certPEM); var hash = KJUR.crypto.Util.hashHex(hex, this.alg); this.dOtherHash = new nD.OtherHashAlgAndValue({alg: this.alg, hash: hash}); diff --git a/asn1cms-1.0.js b/asn1cms-1.0.js index 7c3edf8f..86183f03 100755 --- a/asn1cms-1.0.js +++ b/asn1cms-1.0.js @@ -1,9 +1,9 @@ -/*! asn1cms-1.0.2.js (c) 2013-2014 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! asn1cms-1.0.3.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * asn1cms.js - ASN.1 DER encoder classes for Cryptographic Message Syntax(CMS) * - * Copyright (c) 2014 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license @@ -16,7 +16,7 @@ * @fileOverview * @name asn1cms-1.0.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version 1.0.2 (2014-Jun-07) + * @version 1.0.3 (2017-Jan-14) * @since jsrsasign 4.2.4 * @license MIT License */ @@ -264,7 +264,7 @@ KJUR.asn1.cms.SigningCertificate = function(params) { this.setCerts = function(listPEM) { var list = []; for (var i = 0; i < listPEM.length; i++) { - var hex = KEYUTIL.getHexFromPEM(listPEM[i]); + var hex = ASN1HEX.pemToHex(listPEM[i]); var certHashHex = nY.Util.hashHex(hex, 'sha1'); var dCertHash = new nA.DEROctetString({hex: certHashHex}); dCertHash.getEncodedHex(); @@ -334,7 +334,7 @@ KJUR.asn1.cms.SigningCertificateV2 = function(params) { this.setCerts = function(listPEM, hashAlg) { var list = []; for (var i = 0; i < listPEM.length; i++) { - var hex = KEYUTIL.getHexFromPEM(listPEM[i]); + var hex = ASN1HEX.pemToHex(listPEM[i]); var a = []; if (hashAlg != "sha256") @@ -405,7 +405,7 @@ KJUR.asn1.cms.IssuerAndSerialNumber = function(params) { * @since asn1cms 1.0.1 */ this.setByCertPEM = function(certPEM) { - var certHex = KEYUTIL.getHexFromPEM(certPEM); + var certHex = ASN1HEX.pemToHex(certPEM); var x = new X509(); x.hex = certHex; var issuerTLVHex = x.getIssuerHex(); @@ -837,7 +837,7 @@ KJUR.asn1.cms.SignedData = function(params) { this.signerInfoList = [new nC.SignerInfo()]; this.addCertificatesByPEM = function(certPEM) { - var hex = KEYUTIL.getHexFromPEM(certPEM); + var hex = ASN1HEX.pemToHex(certPEM); var o = new nA.ASN1Object(); o.hTLV = hex; this.certificateList.push(o); diff --git a/asn1csr-1.0.js b/asn1csr-1.0.js index b32b3a6a..49401c1c 100644 --- a/asn1csr-1.0.js +++ b/asn1csr-1.0.js @@ -1,9 +1,9 @@ -/*! asn1csr-1.0.2.js (c) 2015-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! asn1csr-1.0.3.js (c) 2015-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * asn1csr.js - ASN.1 DER encoder classes for PKCS#10 CSR * - * Copyright (c) 2015-2016 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2015-2017 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license @@ -16,7 +16,7 @@ * @fileOverview * @name asn1csr-1.0.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version 1.0.2 (2016-Nov-26) + * @version 1.0.3 (2017-Jan-14) * @since jsrsasign 4.9.0 * @license MIT License */ @@ -413,7 +413,7 @@ KJUR.asn1.csr.CSRUtil.getInfo = function(sPEM) { if (sPEM.indexOf("-----BEGIN CERTIFICATE REQUEST") == -1) throw "argument is not PEM file"; - var hex = KEYUTIL.getHexFromPEM(sPEM, "CERTIFICATE REQUEST"); + var hex = ASN1HEX.pemToHex(sPEM, "CERTIFICATE REQUEST"); result.subject.hex = ASN1HEX.getDecendantHexTLVByNthList(hex, 0, [0, 1]); result.subject.name = X509.hex2dn(result.subject.hex); diff --git a/asn1hex-1.1.js b/asn1hex-1.1.js index f0360926..14e0147b 100644 --- a/asn1hex-1.1.js +++ b/asn1hex-1.1.js @@ -1,9 +1,9 @@ -/*! asn1hex-1.1.8.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! asn1hex-1.1.9.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * asn1hex.js - Hexadecimal represented ASN.1 string library * - * Copyright (c) 2010-2016 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2010-2017 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license/ @@ -16,7 +16,7 @@ * @fileOverview * @name asn1hex-1.1.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version asn1hex 1.1.8 (2016-Dec-03) + * @version asn1hex 1.1.9 (2017-Jan-14) * @license MIT License */ @@ -461,7 +461,7 @@ ASN1HEX.hextooidstr = function(hex) { * INTEGER 01 * INTEGER 02 * // 5) ASN.1 DUMP FOR X.509 CERTIFICATE - * ASN1HEX.dump(X509.pemToHex(certPEM)) + * ASN1HEX.dump(ASN1HEX.pemToHex(certPEM)) * ↓ * SEQUENCE * SEQUENCE @@ -648,3 +648,42 @@ ASN1HEX.isASN1HEX = function(hex) { return false; }; + +/** + * get hexacedimal string from PEM format data
    + * @name pemToHex + * @memberOf ASN1HEX + * @function + * @param {String} s PEM formatted string + * @param {String} sHead PEM header string without BEGIN/END(OPTION) + * @return {String} hexadecimal string data of PEM contents + * @since jsrsasign 7.0.1 asn1hex 1.1.9 + * @description + * This static method gets a hexacedimal string of contents + * from PEM format data. You can explicitly specify PEM header + * by sHead argument. + * Any space characters such as white space or new line + * will be omitted.
    + * NOTE: Now {@link KEYUTIL.getHexFromPEM} and {@link X509.pemToHex} + * have been deprecated since jsrsasign 7.0.1. + * Please use this method instead. + * @example + * ASN1HEX.pemToHex("-----BEGIN PUBLIC KEY...") → "3082..." + * ASN1HEX.pemToHex("-----BEGIN CERTIFICATE...", "CERTIFICATE") → "3082..." + * ASN1HEX.pemToHex(" \r\n-----BEGIN DSA PRIVATE KEY...") → "3082..." + */ +ASN1HEX.pemToHex = function(s, sHead) { + if (s.indexOf("-----BEGIN ") == -1) + throw "can't find PEM header: " + sHead; + + if (sHead !== undefined) { + s = s.replace("-----BEGIN " + sHead + "-----", ""); + s = s.replace("-----END " + sHead + "-----", ""); + } else { + s = s.replace(/-----BEGIN [^-]+-----/, ''); + s = s.replace(/-----END [^-]+-----/, ''); + } + var sB64 = s.replace(/\s+/g, ''); + var dataHex = b64tohex(sB64); + return dataHex; +}; diff --git a/asn1x509-1.0.js b/asn1x509-1.0.js index 5eb326cc..69c23419 100644 --- a/asn1x509-1.0.js +++ b/asn1x509-1.0.js @@ -1,9 +1,9 @@ -/*! asn1x509-1.0.19.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! asn1x509-1.0.20.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * asn1x509.js - ASN.1 DER encoder classes for X.509 certificate * - * Copyright (c) 2013-2016 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license @@ -16,7 +16,7 @@ * @fileOverview * @name asn1x509-1.0.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version 1.0.19 (2016-Nov-26) + * @version 1.0.20 (2017-Jan-14) * @since jsrsasign 2.1 * @license MIT License */ @@ -1474,12 +1474,12 @@ KJUR.asn1.x509.X500Name = function(params) { if (params.certissuer !== undefined) { var x = new X509(); - x.hex = X509.pemToHex(params.certissuer); + x.hex = ASN1HEX.pemToHex(params.certissuer); this.hTLV = x.getIssuerHex(); } if (params.certsubject !== undefined) { var x = new X509(); - x.hex = X509.pemToHex(params.certsubject); + x.hex = ASN1HEX.pemToHex(params.certsubject); this.hTLV = x.getSubjectHex(); } } @@ -1847,10 +1847,10 @@ KJUR.asn1.x509.SubjectPublicKeyInfo = function(params) { var rsaB64 = s.replace(/\s+/g, ''); var rsaWA = CryptoJS.enc.Base64.parse(rsaB64); var rsaP8Hex = CryptoJS.enc.Hex.stringify(rsaWA); - var a = _rsapem_getHexValueArrayOfChildrenFromHex(rsaP8Hex); + var a = RSAKey.getHexValueArrayOfChildrenFromHex(rsaP8Hex); var hBitStrVal = a[1]; var rsaHex = hBitStrVal.substr(2); - var a3 = _rsapem_getHexValueArrayOfChildrenFromHex(rsaHex); + var a3 = RSAKey.getHexValueArrayOfChildrenFromHex(rsaHex); var rsaKey = new RSAKey(); rsaKey.setPublic(a3[0], a3[1]); this.setRSAKey(rsaKey); @@ -2122,7 +2122,7 @@ KJUR.asn1.x509.GeneralName = function(params) { } if (certStr.indexOf("-----BEGIN ") != -1) { - certHex = X509.pemToHex(certStr); + certHex = ASN1HEX.pemToHex(certStr); } if (certHex == null) throw "certissuer param not cert"; @@ -2142,7 +2142,7 @@ KJUR.asn1.x509.GeneralName = function(params) { certHex == certStr; } if (certStr.indexOf("-----BEGIN ") != -1) { - certHex = X509.pemToHex(certStr); + certHex = ASN1HEX.pemToHex(certStr); } if (certHex == null) throw "certsubj param not cert"; var x = new X509(); diff --git a/bower.json b/bower.json index eba4ea67..867d5678 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "7.0.0", + "version": "7.1.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/dsa-2.0.js b/dsa-2.0.js index 8bff3119..16ad95e5 100755 --- a/dsa-2.0.js +++ b/dsa-2.0.js @@ -1,206 +1,373 @@ -/*! dsa-2.0.0.js (c) 2016 Kenji Urushimma | kjur.github.com/jsrsasign/license - */ -/* - * dsa.js - new DSA class - * - * Copyright (c) 2016 Kenji Urushima (kenji.urushima@gmail.com) - * - * This software is licensed under the terms of the MIT License. - * http://kjur.github.com/jsrsasign/license - * - * The above copyright and license notice shall be - * included in all copies or substantial portions of the Software. - */ - -/** - * @fileOverview - * @name dsa-2.0.js - * @author Kenji Urushima kenji.urushima@gmail.com - * @version dsa 2.0.0 (2016-Dec-24) - * @since jsrsasign 7.0.0 - * @license MIT License - */ - -if (typeof KJUR == "undefined" || !KJUR) KJUR = {}; -if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {}; - -/** - * class for DSA signing and verification - * @name KJUR.crypto.DSA - * @class class for DSA signing and verifcation - * @since jsrsasign 7.0.0 dsa 2.0.0 - * @description - *

    - * CAUTION: Most of the case, you don't need to use this class. - * Please use {@link KJUR.crypto.Signature} class instead. - *

    - *

    - * NOTE: Until jsrsasign 6.2.3, DSA class have used codes from openpgpjs library 1.0.0 - * licenced under LGPL licence. To avoid license issue dsa-2.0.js was re-written with - * my own codes in jsrsasign 7.0.0. - * Some random number generators used in dsa-2.0.js was newly defined - * in KJUR.crypto.Util class. Now all of LGPL codes are removed. - *

    - */ -KJUR.crypto.DSA = function() { - this.p = null; - this.q = null; - this.g = null; - this.y = null; - this.x = null; - this.type = "DSA"; - - //=========================== - // PUBLIC METHODS - //=========================== - - /** - * set DSA private key by key parameters - * @name setPrivate - * @memberOf KJUR.crypto.DSA# - * @function - * @param {BigInteger} p prime P - * @param {BigInteger} q sub prime Q - * @param {BigInteger} g base G - * @param {BigInteger} y public key Y - * @param {BigInteger} x private key X - * @since jsrsasign 7.0.0 dsa 2.0.0 - */ - this.setPrivate = function(p, q, g, y, x) { - this.isPrivate = true; - this.p = p; - this.q = q; - this.g = g; - this.y = y; - this.x = x; - }; - - /** - * set DSA public key by key parameters - * @name setPublic - * @memberOf KJUR.crypto.DSA# - * @function - * @param {BigInteger} p prime P - * @param {BigInteger} q sub prime Q - * @param {BigInteger} g base G - * @param {BigInteger} y public key Y - * @since jsrsasign 7.0.0 dsa 2.0.0 - */ - this.setPublic = function(p, q, g, y) { - this.isPublic = true; - this.p = p; - this.q = q; - this.g = g; - this.y = y; - this.x = null; - }; - - /** - * sign to hashed message by this DSA private key object - * @name signWithMessageHash - * @memberOf KJUR.crypto.DSA# - * @function - * @param {String} sHashHex hexadecimal string of hashed message - * @return {String} hexadecimal string of ASN.1 encoded DSA signature value - * @since jsrsasign 7.0.0 dsa 2.0.0 - */ - this.signWithMessageHash = function(sHashHex) { - var p = this.p; // parameter p - var q = this.q; // parameter q - var g = this.g; // parameter g - var y = this.y; // public key (p q g y) - var x = this.x; // private key - - // NIST FIPS 186-4 4.5 DSA Per-Message Secret Number (p18) - // 1. get random k where 0 < k < q - var k = KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE), - q.subtract(BigInteger.ONE)); - - // NIST FIPS 186-4 4.6 DSA Signature Generation (p19) - // 2. get z where the left most min(N, outlen) bits of Hash(M) - var hZ = sHashHex.substr(0, q.bitLength() / 4); - var z = new BigInteger(hZ, 16); - - // 3. get r where (g^k mod p) mod q, r != 0 - var r = (g.modPow(k,p)).mod(q); - - // 4. get s where k^-1 (z + xr) mod q, s != 0 - var s = (k.modInverse(q).multiply(z.add(x.multiply(r)))).mod(q); - - // 5. signature (r, s) - var result = KJUR.asn1.ASN1Util.jsonToASN1HEX({ - "seq": [{"int": {"bigint": r}}, {"int": {"bigint": s}}] - }); - return result; - }; - - /** - * verify signature by this DSA public key object - * @name verifyWithMessageHash - * @memberOf KJUR.crypto.DSA# - * @function - * @param {String} sHashHex hexadecimal string of hashed message - * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value - * @return {Boolean} true if the signature is valid otherwise false. - * @since jsrsasign 7.0.0 dsa 2.0.0 - */ - this.verifyWithMessageHash = function(sHashHex, hSigVal) { - var p = this.p; // parameter p - var q = this.q; // parameter q - var g = this.g; // parameter g - var y = this.y; // public key (p q g y) - - // 1. parse ASN.1 signature (r, s) - var rs = this.parseASN1Signature(hSigVal); - var r = rs[0]; - var s = rs[1]; - - // NIST FIPS 186-4 4.6 DSA Signature Generation (p19) - // 2. get z where the left most min(N, outlen) bits of Hash(M) - var hZ = sHashHex.substr(0, q.bitLength() / 4); - var z = new BigInteger(hZ, 16); - - // NIST FIPS 186-4 4.7 DSA Signature Validation (p19) - // 3.1. 0 < r < q - if (BigInteger.ZERO.compareTo(r) > 0 || r.compareTo(q) > 0) - throw "invalid DSA signature"; - - // 3.2. 0 < s < q - if (BigInteger.ZERO.compareTo(s) > 0 || s.compareTo(q) > 0) - throw "invalid DSA signature"; - - // 4. get w where w = s^-1 mod q - var w = s.modInverse(q); - - // 5. get u1 where u1 = z w mod q - var u1 = z.multiply(w).mod(q); - - // 6. get u2 where u2 = r w mod q - var u2 = r.multiply(w).mod(q); - - // 7. get v where v = ((g^u1 y^u2) mod p) mod q - var v = g.modPow(u1,p).multiply(y.modPow(u2,p)).mod(p).mod(q); - - // 8. signature is valid when v == r - return v.compareTo(r) == 0; - }; - - /** - * parse hexadecimal ASN.1 DSA signature value - * @name parseASN1Signature - * @memberOf KJUR.crypto.DSA# - * @function - * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value - * @return {Array} array [r, s] of DSA signature value. Both r and s are BigInteger. - * @since jsrsasign 7.0.0 dsa 2.0.0 - */ - this.parseASN1Signature = function(hSigVal) { - try { - var r = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [0], "02"), 16); - var s = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [1], "02"), 16); - return [r, s]; - } catch (ex) { - throw "malformed ASN.1 DSA signature"; - } - } -} +/*! dsa-2.1.0.js (c) 2016-2017 Kenji Urushimma | kjur.github.com/jsrsasign/license + */ +/* + * dsa.js - new DSA class + * + * Copyright (c) 2016-2017 Kenji Urushima (kenji.urushima@gmail.com) + * + * This software is licensed under the terms of the MIT License. + * http://kjur.github.com/jsrsasign/license + * + * The above copyright and license notice shall be + * included in all copies or substantial portions of the Software. + */ + +/** + * @fileOverview + * @name dsa-2.0.js + * @author Kenji Urushima kenji.urushima@gmail.com + * @version dsa 2.1.0 (2017-Jan-21) + * @since jsrsasign 7.0.0 + * @license MIT License + */ + +if (typeof KJUR == "undefined" || !KJUR) KJUR = {}; +if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {}; + +/** + * class for DSA signing and verification + * @name KJUR.crypto.DSA + * @class class for DSA signing and verifcation + * @since jsrsasign 7.0.0 dsa 2.0.0 + * @description + *

    + * CAUTION: Most of the case, you don't need to use this class. + * Please use {@link KJUR.crypto.Signature} class instead. + *

    + *

    + * NOTE: Until jsrsasign 6.2.3, DSA class have used codes from openpgpjs library 1.0.0 + * licenced under LGPL licence. To avoid license issue dsa-2.0.js was re-written with + * my own codes in jsrsasign 7.0.0. + * Some random number generators used in dsa-2.0.js was newly defined + * in KJUR.crypto.Util class. Now all of LGPL codes are removed. + *

    + */ +KJUR.crypto.DSA = function() { + this.p = null; + this.q = null; + this.g = null; + this.y = null; + this.x = null; + this.type = "DSA"; + this.isPrivate = false; + this.isPublic = false; + + //=========================== + // PUBLIC METHODS + //=========================== + + /** + * set DSA private key by key parameters of BigInteger object + * @name setPrivate + * @memberOf KJUR.crypto.DSA# + * @function + * @param {BigInteger} p prime P parameter + * @param {BigInteger} q sub prime Q parameter + * @param {BigInteger} g base G parameter + * @param {BigInteger} y public key Y or null + * @param {BigInteger} x private key X + * @since jsrsasign 7.0.0 dsa 2.0.0 + */ + this.setPrivate = function(p, q, g, y, x) { + this.isPrivate = true; + this.p = p; + this.q = q; + this.g = g; + this.y = y; + this.x = x; + }; + + /** + * set DSA private key by key parameters of hexadecimal string + * @name setPrivateHex + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} hP prime P parameter + * @param {String} hQ sub prime Q parameter + * @param {String} hG base G parameter + * @param {String} hY public key Y or null + * @param {String} hX private key X + * @since jsrsasign 7.1.0 dsa 2.1.0 + */ + this.setPrivateHex = function(hP, hQ, hG, hY, hX) { + var biP, biQ, biG, biY, biX; + biP = new BigInteger(hP, 16); + biQ = new BigInteger(hQ, 16); + biG = new BigInteger(hG, 16); + if (typeof hY === "string" && hY.length > 1) { + biY = new BigInteger(hY, 16); + } else { + biY = null; + } + biX = new BigInteger(hX, 16); + this.setPrivate(biP, biQ, biG, biY, biX); + }; + + /** + * set DSA public key by key parameters of BigInteger object + * @name setPublic + * @memberOf KJUR.crypto.DSA# + * @function + * @param {BigInteger} p prime P parameter + * @param {BigInteger} q sub prime Q parameter + * @param {BigInteger} g base G parameter + * @param {BigInteger} y public key Y + * @since jsrsasign 7.0.0 dsa 2.0.0 + */ + this.setPublic = function(p, q, g, y) { + this.isPublic = true; + this.p = p; + this.q = q; + this.g = g; + this.y = y; + this.x = null; + }; + + /** + * set DSA public key by key parameters of hexadecimal string + * @name setPublicHex + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} hP prime P parameter + * @param {String} hQ sub prime Q parameter + * @param {String} hG base G parameter + * @param {String} hY public key Y + * @since jsrsasign 7.1.0 dsa 2.1.0 + */ + this.setPublicHex = function(hP, hQ, hG, hY) { + var biP, biQ, biG, biY; + biP = new BigInteger(hP, 16); + biQ = new BigInteger(hQ, 16); + biG = new BigInteger(hG, 16); + biY = new BigInteger(hY, 16); + this.setPublic(biP, biQ, biG, biY); + }; + + /** + * sign to hashed message by this DSA private key object + * @name signWithMessageHash + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} sHashHex hexadecimal string of hashed message + * @return {String} hexadecimal string of ASN.1 encoded DSA signature value + * @since jsrsasign 7.0.0 dsa 2.0.0 + */ + this.signWithMessageHash = function(sHashHex) { + var p = this.p; // parameter p + var q = this.q; // parameter q + var g = this.g; // parameter g + var y = this.y; // public key (p q g y) + var x = this.x; // private key + + // NIST FIPS 186-4 4.5 DSA Per-Message Secret Number (p18) + // 1. get random k where 0 < k < q + var k = KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE), + q.subtract(BigInteger.ONE)); + + // NIST FIPS 186-4 4.6 DSA Signature Generation (p19) + // 2. get z where the left most min(N, outlen) bits of Hash(M) + var hZ = sHashHex.substr(0, q.bitLength() / 4); + var z = new BigInteger(hZ, 16); + + // 3. get r where (g^k mod p) mod q, r != 0 + var r = (g.modPow(k,p)).mod(q); + + // 4. get s where k^-1 (z + xr) mod q, s != 0 + var s = (k.modInverse(q).multiply(z.add(x.multiply(r)))).mod(q); + + // 5. signature (r, s) + var result = KJUR.asn1.ASN1Util.jsonToASN1HEX({ + "seq": [{"int": {"bigint": r}}, {"int": {"bigint": s}}] + }); + return result; + }; + + /** + * verify signature by this DSA public key object + * @name verifyWithMessageHash + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} sHashHex hexadecimal string of hashed message + * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value + * @return {Boolean} true if the signature is valid otherwise false. + * @since jsrsasign 7.0.0 dsa 2.0.0 + */ + this.verifyWithMessageHash = function(sHashHex, hSigVal) { + var p = this.p; // parameter p + var q = this.q; // parameter q + var g = this.g; // parameter g + var y = this.y; // public key (p q g y) + + // 1. parse ASN.1 signature (r, s) + var rs = this.parseASN1Signature(hSigVal); + var r = rs[0]; + var s = rs[1]; + + // NIST FIPS 186-4 4.6 DSA Signature Generation (p19) + // 2. get z where the left most min(N, outlen) bits of Hash(M) + var hZ = sHashHex.substr(0, q.bitLength() / 4); + var z = new BigInteger(hZ, 16); + + // NIST FIPS 186-4 4.7 DSA Signature Validation (p19) + // 3.1. 0 < r < q + if (BigInteger.ZERO.compareTo(r) > 0 || r.compareTo(q) > 0) + throw "invalid DSA signature"; + + // 3.2. 0 < s < q + if (BigInteger.ZERO.compareTo(s) > 0 || s.compareTo(q) > 0) + throw "invalid DSA signature"; + + // 4. get w where w = s^-1 mod q + var w = s.modInverse(q); + + // 5. get u1 where u1 = z w mod q + var u1 = z.multiply(w).mod(q); + + // 6. get u2 where u2 = r w mod q + var u2 = r.multiply(w).mod(q); + + // 7. get v where v = ((g^u1 y^u2) mod p) mod q + var v = g.modPow(u1,p).multiply(y.modPow(u2,p)).mod(p).mod(q); + + // 8. signature is valid when v == r + return v.compareTo(r) == 0; + }; + + /** + * parse hexadecimal ASN.1 DSA signature value + * @name parseASN1Signature + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value + * @return {Array} array [r, s] of DSA signature value. Both r and s are BigInteger. + * @since jsrsasign 7.0.0 dsa 2.0.0 + */ + this.parseASN1Signature = function(hSigVal) { + try { + var r = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [0], "02"), 16); + var s = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [1], "02"), 16); + return [r, s]; + } catch (ex) { + throw "malformed ASN.1 DSA signature"; + } + } + + /** + * read an ASN.1 hexadecimal string of PKCS#1/5 plain DSA private key
    + * @name readPKCS5PrvKeyHex + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} h hexadecimal string of PKCS#1/5 DSA private key + * @since jsrsasign 7.1.0 dsa 2.1.0 + */ + this.readPKCS5PrvKeyHex = function(h) { + var hP, hQ, hG, hY, hX; + var _ASN1HEX = ASN1HEX; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + try { + hP = _getVbyList(h, 0, [1], "02"); + hQ = _getVbyList(h, 0, [2], "02"); + hG = _getVbyList(h, 0, [3], "02"); + hY = _getVbyList(h, 0, [4], "02"); + hX = _getVbyList(h, 0, [5], "02"); + } catch(ex) { + console.log("EXCEPTION:" + ex); + throw "malformed PKCS#1/5 plain DSA private key"; + } + + this.setPrivateHex(hP, hQ, hG, hY, hX); + }; + + /** + * read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key
    + * @name readPKCS8PrvKeyHex + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} h hexadecimal string of PKCS#8 DSA private key + * @since jsrsasign 7.1.0 dsa 2.1.0 + */ + this.readPKCS8PrvKeyHex = function(h) { + var hP, hQ, hG, hX; + var _ASN1HEX = ASN1HEX; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + try { + hP = _getVbyList(h, 0, [1, 1, 0], "02"); + hQ = _getVbyList(h, 0, [1, 1, 1], "02"); + hG = _getVbyList(h, 0, [1, 1, 2], "02"); + hX = _getVbyList(h, 0, [2, 0], "02"); + } catch(ex) { + console.log("EXCEPTION:" + ex); + throw "malformed PKCS#8 plain DSA private key"; + } + + this.setPrivateHex(hP, hQ, hG, null, hX); + }; + + /** + * read an ASN.1 hexadecimal string of PKCS#8 plain DSA private key
    + * @name readPKCS8PubKeyHex + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} h hexadecimal string of PKCS#8 DSA private key + * @since jsrsasign 7.1.0 dsa 2.1.0 + */ + this.readPKCS8PubKeyHex = function(h) { + var hP, hQ, hG, hY; + var _ASN1HEX = ASN1HEX; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + try { + hP = _getVbyList(h, 0, [0, 1, 0], "02"); + hQ = _getVbyList(h, 0, [0, 1, 1], "02"); + hG = _getVbyList(h, 0, [0, 1, 2], "02"); + hY = _getVbyList(h, 0, [1, 0], "02"); + } catch(ex) { + console.log("EXCEPTION:" + ex); + throw "malformed PKCS#8 DSA public key"; + } + + this.setPublicHex(hP, hQ, hG, hY); + }; + + /** + * read an ASN.1 hexadecimal string of X.509 DSA public key certificate
    + * @name readCertPubKeyHex + * @memberOf KJUR.crypto.DSA# + * @function + * @param {String} h hexadecimal string of X.509 DSA public key certificate + * @param {Integer} nthPKI nth index of publicKeyInfo. (DEFAULT: 6 for X509v3) + * @since jsrsasign 7.1.0 dsa 2.1.0 + */ + this.readCertPubKeyHex = function(h, nthPKI) { + if (nthPKI !== 5) nthPKI = 6; + var hP, hQ, hG, hY; + var _ASN1HEX = ASN1HEX; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + try { + hP = _getVbyList(h, 0, [0, nthPKI, 0, 1, 0], "02"); + hQ = _getVbyList(h, 0, [0, nthPKI, 0, 1, 1], "02"); + hG = _getVbyList(h, 0, [0, nthPKI, 0, 1, 2], "02"); + hY = _getVbyList(h, 0, [0, nthPKI, 1, 0], "02"); + } catch(ex) { + console.log("EXCEPTION:" + ex); + throw "malformed X.509 certificate DSA public key"; + } + + this.setPublicHex(hP, hQ, hG, hY); + }; +} diff --git a/ecdsa-modified-1.0.js b/ecdsa-modified-1.0.js index d79e2d88..a4fe7ea0 100644 --- a/ecdsa-modified-1.0.js +++ b/ecdsa-modified-1.0.js @@ -1,9 +1,9 @@ -/*! ecdsa-modified-1.0.5.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE +/*! ecdsa-modified-1.1.0.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE */ /* * ecdsa-modified.js - modified Bitcoin.ECDSA class * - * Copyright (c) 2013-2016 Stefan Thomas (github.com/justmoon) + * Copyright (c) 2013-2017 Stefan Thomas (github.com/justmoon) * Kenji Urushima (kenji.urushima@gmail.com) * LICENSE * https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE @@ -13,7 +13,7 @@ * @fileOverview * @name ecdsa-modified-1.0.js * @author Stefan Thomas (github.com/justmoon) and Kenji Urushima (kenji.urushima@gmail.com) - * @version 1.0.5 (2016-Aug-11) + * @version 1.1.0 (2017-Jan-21) * @since jsrsasign 4.0 * @license MIT License */ @@ -52,6 +52,8 @@ KJUR.crypto.ECDSA = function(params) { var P_OVER_FOUR = null; this.type = "EC"; + this.isPrivate = false; + this.isPublic = false; function implShamirsTrick(P, k, Q, l) { var m = Math.max(k.bitLength(), l.bitLength()); @@ -398,6 +400,144 @@ KJUR.crypto.ECDSA = function(params) { return {r: r, s: s, i: i}; }; + /** + * read an ASN.1 hexadecimal string of PKCS#1/5 plain ECC private key
    + * @name readPKCS5PrvKeyHex + * @memberOf KJUR.crypto.ECDSA# + * @function + * @param {String} h hexadecimal string of PKCS#1/5 ECC private key + * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0 + */ + this.readPKCS5PrvKeyHex = function(h) { + var _ASN1HEX = ASN1HEX; + var _getName = KJUR.crypto.ECDSA.getName; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + var hCurve, hPrv, hPub; + try { + hCurve = _getVbyList(h, 0, [2, 0], "06"); + hPrv = _getVbyList(h, 0, [1], "04"); + try { + hPub = _getVbyList(h, 0, [3, 0], "03").substr(2); + } catch(ex) {}; + } catch(ex) { + throw "malformed PKCS#1/5 plain ECC private key"; + } + + this.curveName = _getName(hCurve); + if (this.curveName === undefined) throw "unsupported curve name"; + + this.setNamedCurve(this.curveName); + this.setPublicKeyHex(hPub); + this.setPrivateKeyHex(hPrv); + this.isPublic = false; + }; + + /** + * read an ASN.1 hexadecimal string of PKCS#8 plain ECC private key
    + * @name readPKCS8PrvKeyHex + * @memberOf KJUR.crypto.ECDSA# + * @function + * @param {String} h hexadecimal string of PKCS#8 ECC private key + * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0 + */ + this.readPKCS8PrvKeyHex = function(h) { + var _ASN1HEX = ASN1HEX; + var _getName = KJUR.crypto.ECDSA.getName; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + var hECOID, hCurve, hPrv, hPub; + try { + hECOID = _getVbyList(h, 0, [1, 0], "06"); + hCurve = _getVbyList(h, 0, [1, 1], "06"); + hPrv = _getVbyList(h, 0, [2, 0, 1], "04"); + try { + hPub = _getVbyList(h, 0, [2, 0, 2, 0], "03").substr(2); + } catch(ex) {}; + } catch(ex) { + throw "malformed PKCS#8 plain ECC private key"; + } + + this.curveName = _getName(hCurve); + if (this.curveName === undefined) throw "unsupported curve name"; + + this.setNamedCurve(this.curveName); + this.setPublicKeyHex(hPub); + this.setPrivateKeyHex(hPrv); + this.isPublic = false; + }; + + /** + * read an ASN.1 hexadecimal string of PKCS#8 ECC public key
    + * @name readPKCS8PubKeyHex + * @memberOf KJUR.crypto.ECDSA# + * @function + * @param {String} h hexadecimal string of PKCS#8 ECC public key + * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0 + */ + this.readPKCS8PubKeyHex = function(h) { + var _ASN1HEX = ASN1HEX; + var _getName = KJUR.crypto.ECDSA.getName; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + var hECOID, hCurve, hPub; + try { + hECOID = _getVbyList(h, 0, [0, 0], "06"); + hCurve = _getVbyList(h, 0, [0, 1], "06"); + hPub = _getVbyList(h, 0, [1], "03").substr(2); + } catch(ex) { + throw "malformed PKCS#8 ECC public key"; + } + + this.curveName = _getName(hCurve); + if (this.curveName === null) throw "unsupported curve name"; + + this.setNamedCurve(this.curveName); + this.setPublicKeyHex(hPub); + }; + + /** + * read an ASN.1 hexadecimal string of X.509 ECC public key certificate
    + * @name readCertPubKeyHex + * @memberOf KJUR.crypto.ECDSA# + * @function + * @param {String} h hexadecimal string of X.509 ECC public key certificate + * @param {Integer} nthPKI nth index of publicKeyInfo. (DEFAULT: 6 for X509v3) + * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0 + */ + this.readCertPubKeyHex = function(h, nthPKI) { + if (nthPKI !== 5) nthPKI = 6; + var _ASN1HEX = ASN1HEX; + var _getName = KJUR.crypto.ECDSA.getName; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + var hCurve, hPub; + try { + hCurve = _getVbyList(h, 0, [0, nthPKI, 0, 1], "06"); + hPub = _getVbyList(h, 0, [0, nthPKI, 1], "03").substr(2); + } catch(ex) { + throw "malformed X.509 certificate ECC public key"; + } + + this.curveName = _getName(hCurve); + if (this.curveName === null) throw "unsupported curve name"; + + this.setNamedCurve(this.curveName); + this.setPublicKeyHex(hPub); + }; + /* * Recover a public key from a signature. * @@ -501,8 +641,8 @@ KJUR.crypto.ECDSA = function(params) { if (this.curveName === undefined) this.curveName = curveName; this.setNamedCurve(this.curveName); if (params !== undefined) { - if (params['prv'] !== undefined) this.setPrivateKeyHex(params['prv']); - if (params['pub'] !== undefined) this.setPublicKeyHex(params['pub']); + if (params.prv !== undefined) this.setPrivateKeyHex(params.prv); + if (params.pub !== undefined) this.setPublicKeyHex(params.pub); } }; @@ -653,3 +793,33 @@ KJUR.crypto.ECDSA.biRSSigToASN1Sig = function(biR, biS) { return derSeq.getEncodedHex(); }; +/** + * static method to get normalized EC curve name from curve name or hexadecimal OID value + * @name getName + * @memberOf KJUR.crypto.ECDSA + * @function + * @static + * @param {String} s curve name (ex. P-256) or hexadecimal OID value (ex. 2a86...) + * @return {String} normalized EC curve name (ex. secp256r1) + * @since jsrsasign 7.1.0 ecdsa-modified 1.1.0 + * @description + * This static method returns normalized EC curve name + * which is supported in jsrsasign + * from curve name or hexadecimal OID value. + * When curve is not supported in jsrsasign, this method returns null. + * Normalized name will be "secp*" in jsrsasign. + * @example + * KJUR.crypto.ECDSA.getName("2b8104000a") → "secp256k1" + * KJUR.crypto.ECDSA.getName("NIST P-256") → "secp256r1" + * KJUR.crypto.ECDSA.getName("P-521") → undefined // not supported + */ +KJUR.crypto.ECDSA.getName = function(s) { + if (s === "2a8648ce3d030107") return "secp256r1"; // 1.2.840.10045.3.1.7 + if (s === "2b8104000a") return "secp256k1"; // 1.3.132.0.10 + if (s === "2b81040022") return "secp384r1"; // 1.3.132.0.34 + if ("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(s) !== -1) return "secp256r1"; + if ("|secp256k1|".indexOf(s) !== -1) return "secp256k1"; + if ("|secp384r1|NIST P-384|P-384|".indexOf(s) !== -1) return "secp384r1"; + return null; +}; + diff --git a/ext/rsa-min.js b/ext/rsa-min.js index cc69fe50..a88ed480 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}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 +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{throw"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 ad98c0aa..6a36ae09 100644 --- a/ext/rsa.js +++ b/ext/rsa.js @@ -153,19 +153,18 @@ function RSAKey() { } // Set the public key fields N and e from hex strings -function RSASetPublic(N,E) { - this.isPublic = true; - if (typeof N !== "string") - { - this.n = N; - this.e = E; - } - else if(N != null && E != null && N.length > 0 && E.length > 0) { - this.n = parseBigInt(N,16); - this.e = parseInt(E,16); - } - else - alert("Invalid RSA public key"); +function RSASetPublic(N, E) { + this.isPublic = true; + this.isPrivate = false; + if (typeof N !== "string") { + this.n = N; + this.e = E; + } else if(N != null && E != null && N.length > 0 && E.length > 0) { + this.n = parseBigInt(N,16); + this.e = parseInt(E,16); + } else { + throw "Invalid RSA public key"; + } } // Perform raw public operation on "x": return x^e (mod n) diff --git a/ext/rsa2-min.js b/ext/rsa2-min.js index fa835aaf..40720c1e 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}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 +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;this.isPublic=false;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 b7adeba3..d88babf6 100644 --- a/ext/rsa2.js +++ b/ext/rsa2.js @@ -155,6 +155,7 @@ function RSASetPrivate(N,E,D) { // Set the private key fields N, e, d and CRT params from hex strings function RSASetPrivateEx(N,E,D,P,Q,DP,DQ,C) { this.isPrivate = true; + this.isPublic = false; if (N == null) throw "RSASetPrivateEx N == null"; if (E == null) throw "RSASetPrivateEx E == null"; if (N.length == 0) throw "RSASetPrivateEx N.length == 0"; diff --git a/jsrsasign-latest-all-min.js b/jsrsasign-latest-all-min.js index a4a472c1..e9a6e040 100644 --- a/jsrsasign-latest-all-min.js +++ b/jsrsasign-latest-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign 7.0.0 (2016-12-25) (c) 2010-2016 Kenji Urushima | kjur.github.com/jsrsasign/license + * jsrsasign 7.1.0 (2017-01-22) (c) 2010-2017 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}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"; +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{throw"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}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; +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;this.isPublic=false;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; @@ -230,24 +230,24 @@ var jsonParse=(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][ /*! asn1-1.0.12.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+i.toString(16)}var f=128+g;return f.toString(16)+h}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(this.s)};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};YAHOO.lang.extend(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(f){utc=f.getTime()+(f.getTimezoneOffset()*60000);var e=new Date(utc);return e};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};YAHOO.lang.extend(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};YAHOO.lang.extend(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";this.hTLV="0101ff"};YAHOO.lang.extend(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};YAHOO.lang.extend(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=(b*2))){break}if(d>=200){break}c.push(e);g=e;d++}return c};ASN1HEX.getNthChildIndex_AtObj=function(d,b,e){var c=ASN1HEX.getPosArrayOfChildren_AtObj(d,b);return c[e]};ASN1HEX.getDecendantIndexByNthList=function(e,d,c){if(c.length==0){return d}var f=c.shift();var b=ASN1HEX.getPosArrayOfChildren_AtObj(e,d);return ASN1HEX.getDecendantIndexByNthList(e,b[f],c)};ASN1HEX.getDecendantHexTLVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfTLV_AtObj(d,a)};ASN1HEX.getDecendantHexVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.getVbyList=function(d,c,b,e){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);if(a===undefined){throw"can't find nthList object"}if(e!==undefined){if(d.substr(a,2)!=e){throw"checking tag doesn't match: "+d.substr(a,2)+"!="+e}}return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(q,c,k,g){var e=q;if(q instanceof KJUR.asn1.ASN1Object){e=q.getEncodedHex()}var o=function(x,i){if(x.length<=i*2){return x}else{var v=x.substr(0,i)+"..(total "+x.length/2+"bytes).."+x.substr(x.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(k===undefined){k=0}if(g===undefined){g=""}var t=c.ommit_long_octet;if(e.substr(k,2)=="01"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(e.substr(k,2)=="02"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"INTEGER "+o(h,t)+"\n"}if(e.substr(k,2)=="03"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"BITSTRING "+o(h,t)+"\n"}if(e.substr(k,2)=="04"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(ASN1HEX.isASN1HEX(h)){var j=g+"OCTETSTRING, encapsulates\n";j=j+ASN1HEX.dump(h,c,0,g+" ");return j}else{return g+"OCTETSTRING "+o(h,t)+"\n"}}if(e.substr(k,2)=="05"){return g+"NULL\n"}if(e.substr(k,2)=="06"){var l=ASN1HEX.getHexOfV_AtObj(e,k);var a=KJUR.asn1.ASN1Util.oidHexToInt(l);var n=KJUR.asn1.x509.OID.oid2name(a);var b=a.replace(/\./g," ");if(n!=""){return g+"ObjectIdentifier "+n+" ("+b+")\n"}else{return g+"ObjectIdentifier ("+b+")\n"}}if(e.substr(k,2)=="0c"){return g+"UTF8String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="13"){return g+"PrintableString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="14"){return g+"TeletexString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="16"){return g+"IA5String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="17"){return g+"UTCTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="18"){return g+"GeneralizedTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="30"){if(e.substr(k,4)=="3000"){return g+"SEQUENCE {}\n"}var j=g+"SEQUENCE\n";var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,k);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var u=ASN1HEX.getHexOfV_AtObj(e,d[0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(u);var n=KJUR.asn1.x509.OID.oid2name(a);var p=JSON.parse(JSON.stringify(c));p.x509ExtName=n;f=p}for(var r=0;r=(b*2))){break}if(d>=200){break}c.push(e);g=e;d++}return c};ASN1HEX.getNthChildIndex_AtObj=function(d,b,e){var c=ASN1HEX.getPosArrayOfChildren_AtObj(d,b);return c[e]};ASN1HEX.getDecendantIndexByNthList=function(e,d,c){if(c.length==0){return d}var f=c.shift();var b=ASN1HEX.getPosArrayOfChildren_AtObj(e,d);return ASN1HEX.getDecendantIndexByNthList(e,b[f],c)};ASN1HEX.getDecendantHexTLVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfTLV_AtObj(d,a)};ASN1HEX.getDecendantHexVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.getVbyList=function(d,c,b,e){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);if(a===undefined){throw"can't find nthList object"}if(e!==undefined){if(d.substr(a,2)!=e){throw"checking tag doesn't match: "+d.substr(a,2)+"!="+e}}return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(q,c,k,g){var e=q;if(q instanceof KJUR.asn1.ASN1Object){e=q.getEncodedHex()}var o=function(x,i){if(x.length<=i*2){return x}else{var v=x.substr(0,i)+"..(total "+x.length/2+"bytes).."+x.substr(x.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(k===undefined){k=0}if(g===undefined){g=""}var t=c.ommit_long_octet;if(e.substr(k,2)=="01"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(e.substr(k,2)=="02"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"INTEGER "+o(h,t)+"\n"}if(e.substr(k,2)=="03"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"BITSTRING "+o(h,t)+"\n"}if(e.substr(k,2)=="04"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(ASN1HEX.isASN1HEX(h)){var j=g+"OCTETSTRING, encapsulates\n";j=j+ASN1HEX.dump(h,c,0,g+" ");return j}else{return g+"OCTETSTRING "+o(h,t)+"\n"}}if(e.substr(k,2)=="05"){return g+"NULL\n"}if(e.substr(k,2)=="06"){var l=ASN1HEX.getHexOfV_AtObj(e,k);var a=KJUR.asn1.ASN1Util.oidHexToInt(l);var n=KJUR.asn1.x509.OID.oid2name(a);var b=a.replace(/\./g," ");if(n!=""){return g+"ObjectIdentifier "+n+" ("+b+")\n"}else{return g+"ObjectIdentifier ("+b+")\n"}}if(e.substr(k,2)=="0c"){return g+"UTF8String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="13"){return g+"PrintableString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="14"){return g+"TeletexString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="16"){return g+"IA5String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="17"){return g+"UTCTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="18"){return g+"GeneralizedTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="30"){if(e.substr(k,4)=="3000"){return g+"SEQUENCE {}\n"}var j=g+"SEQUENCE\n";var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,k);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var u=ASN1HEX.getHexOfV_AtObj(e,d[0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(u);var n=KJUR.asn1.x509.OID.oid2name(a);var p=JSON.parse(JSON.stringify(c));p.x509ExtName=n;f=p}for(var r=0;r0){var d=new KJUR.asn1.DERSequence({array:this.extensionsArray});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a3",obj:d});this.asn1Array.push(b)}var e=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=e.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension=function(b){KJUR.asn1.x509.Extension.superclass.constructor.call(this);var a=null;this.getEncodedHex=function(){var f=new KJUR.asn1.DERObjectIdentifier({oid:this.oid});var e=new KJUR.asn1.DEROctetString({hex:this.getExtnValueHex()});var d=new Array();d.push(f);if(this.critical){d.push(new KJUR.asn1.DERBoolean())}d.push(e);var c=new KJUR.asn1.DERSequence({array:d});return c.getEncodedHex()};this.critical=false;if(typeof b!="undefined"){if(typeof b.critical!="undefined"){this.critical=b.critical}}};YAHOO.lang.extend(KJUR.asn1.x509.Extension,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension.appendByNameToArray=function(e,c,b){if(e.toLowerCase()=="basicconstraints"){var d=new KJUR.asn1.x509.BasicConstraints(c);b.push(d)}else{if(e.toLowerCase()=="keyusage"){var d=new KJUR.asn1.x509.KeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="crldistributionpoints"){var d=new KJUR.asn1.x509.CRLDistributionPoints(c);b.push(d)}else{if(e.toLowerCase()=="extkeyusage"){var d=new KJUR.asn1.x509.ExtKeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="authoritykeyidentifier"){var d=new KJUR.asn1.x509.AuthorityKeyIdentifier(c);b.push(d)}else{if(e.toLowerCase()=="authorityinfoaccess"){var d=new KJUR.asn1.x509.AuthorityInfoAccess(c);b.push(d)}else{if(e.toLowerCase()=="subjectaltname"){var d=new KJUR.asn1.x509.SubjectAltName(c);b.push(d)}else{if(e.toLowerCase()=="issueraltname"){var d=new KJUR.asn1.x509.IssuerAltName(c);b.push(d)}else{throw"unsupported extension name: "+e}}}}}}}}};KJUR.asn1.x509.KeyUsage=function(a){KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.15";if(typeof a!="undefined"){if(typeof a.bin!="undefined"){this.asn1ExtnValue=new KJUR.asn1.DERBitString(a)}}};YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage,KJUR.asn1.x509.Extension);KJUR.asn1.x509.BasicConstraints=function(c){KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this,c);var a=false;var b=-1;this.getExtnValueHex=function(){var e=new Array();if(this.cA){e.push(new KJUR.asn1.DERBoolean())}if(this.pathLen>-1){e.push(new KJUR.asn1.DERInteger({"int":this.pathLen}))}var d=new KJUR.asn1.DERSequence({array:e});this.asn1ExtnValue=d;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(typeof c!="undefined"){if(typeof c.cA!="undefined"){this.cA=c.cA}if(typeof c.pathLen!="undefined"){this.pathLen=c.pathLen}}};YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(a){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence({array:b})};this.setByOneURI=function(e){var b=new KJUR.asn1.x509.GeneralNames([{uri:e}]);var d=new KJUR.asn1.x509.DistributionPointName(b);var c=new KJUR.asn1.x509.DistributionPoint({dpobj:d});this.setByDPArray([c])};this.oid="2.5.29.31";if(typeof a!="undefined"){if(typeof a.array!="undefined"){this.setByDPArray(a.array)}else{if(typeof a.uri!="undefined"){this.setByOneURI(a.uri)}}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.ExtKeyUsage=function(a){KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,a);this.setPurposeArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence();for(var c=0;c0){var c=new KJUR.asn1.DERSequence({array:this.aRevokedCert});this.asn1Array.push(c)}var d=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=d.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize=function(){this.asn1Version=null;this.asn1SignatureAlg=null;this.asn1Issuer=null;this.asn1ThisUpdate=null;this.asn1NextUpdate=null;this.aRevokedCert=new Array()};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList,KJUR.asn1.ASN1Object);KJUR.asn1.x509.CRLEntry=function(c){KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this);var b=null;var a=null;this.setCertSerial=function(d){this.sn=new KJUR.asn1.DERInteger(d)};this.setRevocationDate=function(d){this.time=new KJUR.asn1.x509.Time(d)};this.getEncodedHex=function(){var d=new KJUR.asn1.DERSequence({array:[this.sn,this.time]});this.TLV=d.getEncodedHex();return this.TLV};if(typeof c!="undefined"){if(typeof c.time!="undefined"){this.setRevocationDate(c.time)}if(typeof c.sn!="undefined"){this.setCertSerial(c.sn)}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry,KJUR.asn1.ASN1Object);KJUR.asn1.x509.X500Name=function(b){KJUR.asn1.x509.X500Name.superclass.constructor.call(this);this.asn1Array=new Array();this.setByString=function(c){var d=c.split("/");d.shift();for(var e=0;e0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.RDN=function(a){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=new Array();this.addByString=function(b){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:b}))};this.addByMultiValuedString=function(d){var b=KJUR.asn1.x509.RDN.parseString(d);for(var c=0;c0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(b){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var d=null;var c=null;var a="utf8";this.setByString=function(f){var e=f.match(/^([^=]+)=(.+)$/);if(e){this.setByAttrTypeAndValueStr(e[1],e[2])}else{throw"malformed attrTypeAndValueStr: "+f}};this.setByAttrTypeAndValueStr=function(g,f){this.typeObj=KJUR.asn1.x509.OID.atype2obj(g);var e=a;if(g=="C"){e="prn"}this.valueObj=this.getValueObj(e,f)};this.getValueObj=function(f,e){if(f=="utf8"){return new KJUR.asn1.DERUTF8String({str:e})}if(f=="prn"){return new KJUR.asn1.DERPrintableString({str:e})}if(f=="tel"){return new KJUR.asn1.DERTeletexString({str:e})}if(f=="ia5"){return new KJUR.asn1.DERIA5String({str:e})}throw"unsupported directory string type: type="+f+" value="+e};this.getEncodedHex=function(){var e=new KJUR.asn1.DERSequence({array:[this.typeObj,this.valueObj]});this.TLV=e.getEncodedHex();return this.TLV};if(typeof b!="undefined"){if(typeof b.str!="undefined"){this.setByString(b.str)}}};YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(d){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var b=null;var c=null;var a=null;this.setRSAKey=function(e){if(!RSAKey.prototype.isPrototypeOf(e)){throw"argument is not RSAKey instance"}this.rsaKey=e;var g=new KJUR.asn1.DERInteger({bigint:e.n});var f=new KJUR.asn1.DERInteger({"int":e.e});var i=new KJUR.asn1.DERSequence({array:[g,f]});var h=i.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+h})};this.setRSAPEM=function(g){if(g.match(/-----BEGIN PUBLIC KEY-----/)){var n=g;n=n.replace(/^-----[^-]+-----/,"");n=n.replace(/-----[^-]+-----\s*$/,"");var m=n.replace(/\s+/g,"");var f=CryptoJS.enc.Base64.parse(m);var i=CryptoJS.enc.Hex.stringify(f);var k=_rsapem_getHexValueArrayOfChildrenFromHex(i);var h=k[1];var l=h.substr(2);var e=_rsapem_getHexValueArrayOfChildrenFromHex(l);var j=new RSAKey();j.setPublic(e[0],e[1]);this.setRSAKey(j)}else{throw"key not supported"}};this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var e=new KJUR.asn1.DERSequence({array:[this.asn1AlgId,this.asn1SubjPKey]});return e};this.getEncodedHex=function(){var e=this.getASN1Object();this.hTLV=e.getEncodedHex();return this.hTLV};this._setRSAKey=function(e){var g=KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.n}},{"int":{"int":e.e}}]});var f=g.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+f})};this._setEC=function(e){var f=new KJUR.asn1.DERObjectIdentifier({name:e.curveName});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"ecPublicKey",asn1params:f});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+e.pubKeyHex})};this._setDSA=function(e){var f=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.p}},{"int":{bigint:e.q}},{"int":{bigint:e.g}}]});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"dsa",asn1params:f});var g=new KJUR.asn1.DERInteger({bigint:e.y});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+g.getEncodedHex()})};if(typeof d!="undefined"){if(typeof RSAKey!="undefined"&&d instanceof RSAKey){this._setRSAKey(d)}else{if(typeof KJUR.crypto.ECDSA!="undefined"&&d instanceof KJUR.crypto.ECDSA){this._setEC(d)}else{if(typeof KJUR.crypto.DSA!="undefined"&&d instanceof KJUR.crypto.DSA){this._setDSA(d)}else{if(typeof d.rsakey!="undefined"){this.setRSAKey(d.rsakey)}else{if(typeof d.rsapem!="undefined"){this.setRSAPEM(d.rsapem)}}}}}}};YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(c){KJUR.asn1.x509.Time.superclass.constructor.call(this);var b=null;var a=null;this.setTimeParams=function(d){this.timeParams=d};this.getEncodedHex=function(){var d=null;if(this.timeParams!=null){if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime(this.timeParams)}else{d=new KJUR.asn1.DERGeneralizedTime(this.timeParams)}}else{if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime()}else{d=new KJUR.asn1.DERGeneralizedTime()}}this.TLV=d.getEncodedHex();return this.TLV};this.type="utc";if(typeof c!="undefined"){if(typeof c.type!="undefined"){this.type=c.type}else{if(typeof c.str!="undefined"){if(c.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(c.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=c}};YAHOO.lang.extend(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);var a=null;var d=null;var b=null;var c=false;this.getEncodedHex=function(){if(this.nameAlg==null&&this.asn1Alg==null){throw"algorithm not specified"}if(this.nameAlg!=null&&this.asn1Alg==null){this.asn1Alg=KJUR.asn1.x509.OID.name2obj(this.nameAlg)}var f=[this.asn1Alg];if(!this.paramEmpty){f.push(this.asn1Params)}var g=new KJUR.asn1.DERSequence({array:f});this.hTLV=g.getEncodedHex();return this.hTLV};if(typeof e!="undefined"){if(typeof e.name!="undefined"){this.nameAlg=e.name}if(typeof e.asn1params!="undefined"){this.asn1Params=e.asn1params}if(typeof e.paramempty!="undefined"){this.paramEmpty=e.paramempty}}if(this.asn1Params==null){this.asn1Params=new KJUR.asn1.DERNull()}};YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralName=function(d){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var c=null;var b=null;var a={rfc822:"81",dns:"82",dn:"a4",uri:"86"};this.explicit=false;this.setByParam=function(k){var j=null;var g=null;if(k===undefined){return}if(k.rfc822!==undefined){this.type="rfc822";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dns!==undefined){this.type="dns";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.uri!==undefined){this.type="uri";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({str:k.dn})}if(k.ldapdn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({ldapstr:k.ldapdn})}if(k.certissuer!==undefined){this.type="dn";this.explicit=true;var h=k.certissuer;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=X509.pemToHex(h)}if(f==null){throw"certissuer param not cert"}var e=new X509();e.hex=f;var i=e.getIssuerHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(k.certsubj!==undefined){this.type="dn";this.explicit=true;var h=k.certsubj;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=X509.pemToHex(h)}if(f==null){throw"certsubj param not cert"}var e=new X509();e.hex=f;var i=e.getSubjectHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(this.type==null){throw"unsupported type in params="+k}this.asn1Obj=new KJUR.asn1.DERTaggedObject({explicit:this.explicit,tag:a[this.type],obj:g})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(d!==undefined){this.setByParam(d)}};YAHOO.lang.extend(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(b){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null;this.setByParamArray=function(e){for(var c=0;c0){var d=new KJUR.asn1.DERSequence({array:this.extensionsArray});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a3",obj:d});this.asn1Array.push(b)}var e=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=e.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension=function(b){KJUR.asn1.x509.Extension.superclass.constructor.call(this);var a=null;this.getEncodedHex=function(){var f=new KJUR.asn1.DERObjectIdentifier({oid:this.oid});var e=new KJUR.asn1.DEROctetString({hex:this.getExtnValueHex()});var d=new Array();d.push(f);if(this.critical){d.push(new KJUR.asn1.DERBoolean())}d.push(e);var c=new KJUR.asn1.DERSequence({array:d});return c.getEncodedHex()};this.critical=false;if(typeof b!="undefined"){if(typeof b.critical!="undefined"){this.critical=b.critical}}};YAHOO.lang.extend(KJUR.asn1.x509.Extension,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension.appendByNameToArray=function(e,c,b){if(e.toLowerCase()=="basicconstraints"){var d=new KJUR.asn1.x509.BasicConstraints(c);b.push(d)}else{if(e.toLowerCase()=="keyusage"){var d=new KJUR.asn1.x509.KeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="crldistributionpoints"){var d=new KJUR.asn1.x509.CRLDistributionPoints(c);b.push(d)}else{if(e.toLowerCase()=="extkeyusage"){var d=new KJUR.asn1.x509.ExtKeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="authoritykeyidentifier"){var d=new KJUR.asn1.x509.AuthorityKeyIdentifier(c);b.push(d)}else{if(e.toLowerCase()=="authorityinfoaccess"){var d=new KJUR.asn1.x509.AuthorityInfoAccess(c);b.push(d)}else{if(e.toLowerCase()=="subjectaltname"){var d=new KJUR.asn1.x509.SubjectAltName(c);b.push(d)}else{if(e.toLowerCase()=="issueraltname"){var d=new KJUR.asn1.x509.IssuerAltName(c);b.push(d)}else{throw"unsupported extension name: "+e}}}}}}}}};KJUR.asn1.x509.KeyUsage=function(a){KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.15";if(typeof a!="undefined"){if(typeof a.bin!="undefined"){this.asn1ExtnValue=new KJUR.asn1.DERBitString(a)}}};YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage,KJUR.asn1.x509.Extension);KJUR.asn1.x509.BasicConstraints=function(c){KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this,c);var a=false;var b=-1;this.getExtnValueHex=function(){var e=new Array();if(this.cA){e.push(new KJUR.asn1.DERBoolean())}if(this.pathLen>-1){e.push(new KJUR.asn1.DERInteger({"int":this.pathLen}))}var d=new KJUR.asn1.DERSequence({array:e});this.asn1ExtnValue=d;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(typeof c!="undefined"){if(typeof c.cA!="undefined"){this.cA=c.cA}if(typeof c.pathLen!="undefined"){this.pathLen=c.pathLen}}};YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(a){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence({array:b})};this.setByOneURI=function(e){var b=new KJUR.asn1.x509.GeneralNames([{uri:e}]);var d=new KJUR.asn1.x509.DistributionPointName(b);var c=new KJUR.asn1.x509.DistributionPoint({dpobj:d});this.setByDPArray([c])};this.oid="2.5.29.31";if(typeof a!="undefined"){if(typeof a.array!="undefined"){this.setByDPArray(a.array)}else{if(typeof a.uri!="undefined"){this.setByOneURI(a.uri)}}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.ExtKeyUsage=function(a){KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,a);this.setPurposeArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence();for(var c=0;c0){var c=new KJUR.asn1.DERSequence({array:this.aRevokedCert});this.asn1Array.push(c)}var d=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=d.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize=function(){this.asn1Version=null;this.asn1SignatureAlg=null;this.asn1Issuer=null;this.asn1ThisUpdate=null;this.asn1NextUpdate=null;this.aRevokedCert=new Array()};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList,KJUR.asn1.ASN1Object);KJUR.asn1.x509.CRLEntry=function(c){KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this);var b=null;var a=null;this.setCertSerial=function(d){this.sn=new KJUR.asn1.DERInteger(d)};this.setRevocationDate=function(d){this.time=new KJUR.asn1.x509.Time(d)};this.getEncodedHex=function(){var d=new KJUR.asn1.DERSequence({array:[this.sn,this.time]});this.TLV=d.getEncodedHex();return this.TLV};if(typeof c!="undefined"){if(typeof c.time!="undefined"){this.setRevocationDate(c.time)}if(typeof c.sn!="undefined"){this.setCertSerial(c.sn)}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry,KJUR.asn1.ASN1Object);KJUR.asn1.x509.X500Name=function(b){KJUR.asn1.x509.X500Name.superclass.constructor.call(this);this.asn1Array=new Array();this.setByString=function(c){var d=c.split("/");d.shift();for(var e=0;e0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.RDN=function(a){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=new Array();this.addByString=function(b){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:b}))};this.addByMultiValuedString=function(d){var b=KJUR.asn1.x509.RDN.parseString(d);for(var c=0;c0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(b){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var d=null;var c=null;var a="utf8";this.setByString=function(f){var e=f.match(/^([^=]+)=(.+)$/);if(e){this.setByAttrTypeAndValueStr(e[1],e[2])}else{throw"malformed attrTypeAndValueStr: "+f}};this.setByAttrTypeAndValueStr=function(g,f){this.typeObj=KJUR.asn1.x509.OID.atype2obj(g);var e=a;if(g=="C"){e="prn"}this.valueObj=this.getValueObj(e,f)};this.getValueObj=function(f,e){if(f=="utf8"){return new KJUR.asn1.DERUTF8String({str:e})}if(f=="prn"){return new KJUR.asn1.DERPrintableString({str:e})}if(f=="tel"){return new KJUR.asn1.DERTeletexString({str:e})}if(f=="ia5"){return new KJUR.asn1.DERIA5String({str:e})}throw"unsupported directory string type: type="+f+" value="+e};this.getEncodedHex=function(){var e=new KJUR.asn1.DERSequence({array:[this.typeObj,this.valueObj]});this.TLV=e.getEncodedHex();return this.TLV};if(typeof b!="undefined"){if(typeof b.str!="undefined"){this.setByString(b.str)}}};YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(d){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var b=null;var c=null;var a=null;this.setRSAKey=function(e){if(!RSAKey.prototype.isPrototypeOf(e)){throw"argument is not RSAKey instance"}this.rsaKey=e;var g=new KJUR.asn1.DERInteger({bigint:e.n});var f=new KJUR.asn1.DERInteger({"int":e.e});var i=new KJUR.asn1.DERSequence({array:[g,f]});var h=i.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+h})};this.setRSAPEM=function(g){if(g.match(/-----BEGIN PUBLIC KEY-----/)){var n=g;n=n.replace(/^-----[^-]+-----/,"");n=n.replace(/-----[^-]+-----\s*$/,"");var m=n.replace(/\s+/g,"");var f=CryptoJS.enc.Base64.parse(m);var i=CryptoJS.enc.Hex.stringify(f);var k=RSAKey.getHexValueArrayOfChildrenFromHex(i);var h=k[1];var l=h.substr(2);var e=RSAKey.getHexValueArrayOfChildrenFromHex(l);var j=new RSAKey();j.setPublic(e[0],e[1]);this.setRSAKey(j)}else{throw"key not supported"}};this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var e=new KJUR.asn1.DERSequence({array:[this.asn1AlgId,this.asn1SubjPKey]});return e};this.getEncodedHex=function(){var e=this.getASN1Object();this.hTLV=e.getEncodedHex();return this.hTLV};this._setRSAKey=function(e){var g=KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.n}},{"int":{"int":e.e}}]});var f=g.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+f})};this._setEC=function(e){var f=new KJUR.asn1.DERObjectIdentifier({name:e.curveName});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"ecPublicKey",asn1params:f});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+e.pubKeyHex})};this._setDSA=function(e){var f=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.p}},{"int":{bigint:e.q}},{"int":{bigint:e.g}}]});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"dsa",asn1params:f});var g=new KJUR.asn1.DERInteger({bigint:e.y});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+g.getEncodedHex()})};if(typeof d!="undefined"){if(typeof RSAKey!="undefined"&&d instanceof RSAKey){this._setRSAKey(d)}else{if(typeof KJUR.crypto.ECDSA!="undefined"&&d instanceof KJUR.crypto.ECDSA){this._setEC(d)}else{if(typeof KJUR.crypto.DSA!="undefined"&&d instanceof KJUR.crypto.DSA){this._setDSA(d)}else{if(typeof d.rsakey!="undefined"){this.setRSAKey(d.rsakey)}else{if(typeof d.rsapem!="undefined"){this.setRSAPEM(d.rsapem)}}}}}}};YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(c){KJUR.asn1.x509.Time.superclass.constructor.call(this);var b=null;var a=null;this.setTimeParams=function(d){this.timeParams=d};this.getEncodedHex=function(){var d=null;if(this.timeParams!=null){if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime(this.timeParams)}else{d=new KJUR.asn1.DERGeneralizedTime(this.timeParams)}}else{if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime()}else{d=new KJUR.asn1.DERGeneralizedTime()}}this.TLV=d.getEncodedHex();return this.TLV};this.type="utc";if(typeof c!="undefined"){if(typeof c.type!="undefined"){this.type=c.type}else{if(typeof c.str!="undefined"){if(c.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(c.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=c}};YAHOO.lang.extend(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);var a=null;var d=null;var b=null;var c=false;this.getEncodedHex=function(){if(this.nameAlg==null&&this.asn1Alg==null){throw"algorithm not specified"}if(this.nameAlg!=null&&this.asn1Alg==null){this.asn1Alg=KJUR.asn1.x509.OID.name2obj(this.nameAlg)}var f=[this.asn1Alg];if(!this.paramEmpty){f.push(this.asn1Params)}var g=new KJUR.asn1.DERSequence({array:f});this.hTLV=g.getEncodedHex();return this.hTLV};if(typeof e!="undefined"){if(typeof e.name!="undefined"){this.nameAlg=e.name}if(typeof e.asn1params!="undefined"){this.asn1Params=e.asn1params}if(typeof e.paramempty!="undefined"){this.paramEmpty=e.paramempty}}if(this.asn1Params==null){this.asn1Params=new KJUR.asn1.DERNull()}};YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralName=function(d){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var c=null;var b=null;var a={rfc822:"81",dns:"82",dn:"a4",uri:"86"};this.explicit=false;this.setByParam=function(k){var j=null;var g=null;if(k===undefined){return}if(k.rfc822!==undefined){this.type="rfc822";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dns!==undefined){this.type="dns";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.uri!==undefined){this.type="uri";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({str:k.dn})}if(k.ldapdn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({ldapstr:k.ldapdn})}if(k.certissuer!==undefined){this.type="dn";this.explicit=true;var h=k.certissuer;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=ASN1HEX.pemToHex(h)}if(f==null){throw"certissuer param not cert"}var e=new X509();e.hex=f;var i=e.getIssuerHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(k.certsubj!==undefined){this.type="dn";this.explicit=true;var h=k.certsubj;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=ASN1HEX.pemToHex(h)}if(f==null){throw"certsubj param not cert"}var e=new X509();e.hex=f;var i=e.getSubjectHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(this.type==null){throw"unsupported type in params="+k}this.asn1Obj=new KJUR.asn1.DERTaggedObject({explicit:this.explicit,tag:a[this.type],obj:g})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(d!==undefined){this.setByParam(d)}};YAHOO.lang.extend(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(b){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null;this.setByParamArray=function(e){for(var c=0;c0){h=new a.DERTaggedObject({obj:this.dUnsignedAttrs,tag:"a1",explicit:false})}var g=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,e,this.dSigAlg,this.dSig,];if(h!=null){g.push(h)}var f=new a.DERSequence({array:g});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.SignerInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.EncapsulatedContentInfo=function(c){KJUR.asn1.cms.EncapsulatedContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dEContentType=new a.DERObjectIdentifier({name:"data"});this.dEContent=null;this.isDetached=false;this.eContentValueHex=null;this.setContentType=function(e){if(e.match(/^[0-2][.][0-9.]+$/)){this.dEContentType=new a.DERObjectIdentifier({oid:e})}else{this.dEContentType=new a.DERObjectIdentifier({name:e})}};this.setContentValue=function(e){if(typeof e!="undefined"){if(typeof e.hex=="string"){this.eContentValueHex=e.hex}else{if(typeof e.str=="string"){this.eContentValueHex=utf8tohex(e.str)}}}};this.setContentValueHex=function(e){this.eContentValueHex=e};this.setContentValueStr=function(e){this.eContentValueHex=utf8tohex(e)};this.getEncodedHex=function(){if(typeof this.eContentValueHex!="string"){throw"eContentValue not yet set"}var g=new a.DEROctetString({hex:this.eContentValueHex});this.dEContent=new a.DERTaggedObject({obj:g,tag:"a0",explicit:true});var e=[this.dEContentType];if(!this.isDetached){e.push(this.dEContent)}var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.EncapsulatedContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentInfo=function(c){KJUR.asn1.cms.ContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dContentType=null;this.dContent=null;this.setContentType=function(e){if(typeof e=="string"){this.dContentType=d.OID.name2obj(e)}};this.getEncodedHex=function(){var f=new a.DERTaggedObject({obj:this.dContent,tag:"a0",explicit:true});var e=new a.DERSequence({array:[this.dContentType,f]});this.hTLV=e.getEncodedHex();return this.hTLV};if(typeof c!="undefined"){if(c.type){this.setContentType(c.type)}if(c.obj&&c.obj instanceof a.ASN1Object){this.dContent=c.obj}}};YAHOO.lang.extend(KJUR.asn1.cms.ContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.SignedData=function(c){KJUR.asn1.cms.SignedData.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dCMSVersion=new a.DERInteger({"int":1});this.dDigestAlgs=null;this.digestAlgNameList=[];this.dEncapContentInfo=new b.EncapsulatedContentInfo();this.dCerts=null;this.certificateList=[];this.crlList=[];this.signerInfoList=[new b.SignerInfo()];this.addCertificatesByPEM=function(e){var f=KEYUTIL.getHexFromPEM(e);var g=new a.ASN1Object();g.hTLV=f;this.certificateList.push(g)};this.getEncodedHex=function(){if(typeof this.hTLV=="string"){return this.hTLV}if(this.dDigestAlgs==null){var k=[];for(var j=0;j0){var l=new a.DERSet({array:this.certificateList});this.dCerts=new a.DERTaggedObject({obj:l,tag:"a0",explicit:false})}}if(this.dCerts!=null){e.push(this.dCerts)}var g=new a.DERSet({array:this.signerInfoList});e.push(g);var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV};this.getContentInfo=function(){this.getEncodedHex();var e=new b.ContentInfo({type:"signed-data",obj:this});return e};this.getContentInfoEncodedHex=function(){var e=this.getContentInfo();var f=e.getEncodedHex();return f};this.getPEM=function(){var e=this.getContentInfoEncodedHex();var f=a.ASN1Util.getPEMStringFromHex(e,"CMS");return f}};YAHOO.lang.extend(KJUR.asn1.cms.SignedData,KJUR.asn1.ASN1Object);KJUR.asn1.cms.CMSUtil=new function(){};KJUR.asn1.cms.CMSUtil.newSignedData=function(a){var h=KJUR.asn1.cms;var g=KJUR.asn1.cades;var f=new h.SignedData();f.dEncapContentInfo.setContentValue(a.content);if(typeof a.certs=="object"){for(var b=0;b0){h=new a.DERTaggedObject({obj:this.dUnsignedAttrs,tag:"a1",explicit:false})}var g=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,e,this.dSigAlg,this.dSig,];if(h!=null){g.push(h)}var f=new a.DERSequence({array:g});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.SignerInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.EncapsulatedContentInfo=function(c){KJUR.asn1.cms.EncapsulatedContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dEContentType=new a.DERObjectIdentifier({name:"data"});this.dEContent=null;this.isDetached=false;this.eContentValueHex=null;this.setContentType=function(e){if(e.match(/^[0-2][.][0-9.]+$/)){this.dEContentType=new a.DERObjectIdentifier({oid:e})}else{this.dEContentType=new a.DERObjectIdentifier({name:e})}};this.setContentValue=function(e){if(typeof e!="undefined"){if(typeof e.hex=="string"){this.eContentValueHex=e.hex}else{if(typeof e.str=="string"){this.eContentValueHex=utf8tohex(e.str)}}}};this.setContentValueHex=function(e){this.eContentValueHex=e};this.setContentValueStr=function(e){this.eContentValueHex=utf8tohex(e)};this.getEncodedHex=function(){if(typeof this.eContentValueHex!="string"){throw"eContentValue not yet set"}var g=new a.DEROctetString({hex:this.eContentValueHex});this.dEContent=new a.DERTaggedObject({obj:g,tag:"a0",explicit:true});var e=[this.dEContentType];if(!this.isDetached){e.push(this.dEContent)}var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.EncapsulatedContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentInfo=function(c){KJUR.asn1.cms.ContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dContentType=null;this.dContent=null;this.setContentType=function(e){if(typeof e=="string"){this.dContentType=d.OID.name2obj(e)}};this.getEncodedHex=function(){var f=new a.DERTaggedObject({obj:this.dContent,tag:"a0",explicit:true});var e=new a.DERSequence({array:[this.dContentType,f]});this.hTLV=e.getEncodedHex();return this.hTLV};if(typeof c!="undefined"){if(c.type){this.setContentType(c.type)}if(c.obj&&c.obj instanceof a.ASN1Object){this.dContent=c.obj}}};YAHOO.lang.extend(KJUR.asn1.cms.ContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.SignedData=function(c){KJUR.asn1.cms.SignedData.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dCMSVersion=new a.DERInteger({"int":1});this.dDigestAlgs=null;this.digestAlgNameList=[];this.dEncapContentInfo=new b.EncapsulatedContentInfo();this.dCerts=null;this.certificateList=[];this.crlList=[];this.signerInfoList=[new b.SignerInfo()];this.addCertificatesByPEM=function(e){var f=ASN1HEX.pemToHex(e);var g=new a.ASN1Object();g.hTLV=f;this.certificateList.push(g)};this.getEncodedHex=function(){if(typeof this.hTLV=="string"){return this.hTLV}if(this.dDigestAlgs==null){var k=[];for(var j=0;j0){var l=new a.DERSet({array:this.certificateList});this.dCerts=new a.DERTaggedObject({obj:l,tag:"a0",explicit:false})}}if(this.dCerts!=null){e.push(this.dCerts)}var g=new a.DERSet({array:this.signerInfoList});e.push(g);var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV};this.getContentInfo=function(){this.getEncodedHex();var e=new b.ContentInfo({type:"signed-data",obj:this});return e};this.getContentInfoEncodedHex=function(){var e=this.getContentInfo();var f=e.getEncodedHex();return f};this.getPEM=function(){var e=this.getContentInfoEncodedHex();var f=a.ASN1Util.getPEMStringFromHex(e,"CMS");return f}};YAHOO.lang.extend(KJUR.asn1.cms.SignedData,KJUR.asn1.ASN1Object);KJUR.asn1.cms.CMSUtil=new function(){};KJUR.asn1.cms.CMSUtil.newSignedData=function(a){var h=KJUR.asn1.cms;var g=KJUR.asn1.cades;var f=new h.SignedData();f.dEncapContentInfo.setContentValue(a.content);if(typeof a.certs=="object"){for(var b=0;b0){var e=new KJUR.asn1.DERSequence({array:this.extensionsArray});var d=new KJUR.asn1.DERSet({array:[e]});var c=new KJUR.asn1.DERSequence({array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.9.14"}),d]});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a0",obj:c});this.asn1Array.push(b)}else{var b=new KJUR.asn1.DERTaggedObject({explicit:false,tag:"a0",obj:new KJUR.asn1.DERNull()});this.asn1Array.push(b)}var f=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=f.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.csr.CertificationRequestInfo,KJUR.asn1.ASN1Object);KJUR.asn1.csr.CSRUtil=new function(){};KJUR.asn1.csr.CSRUtil.newCSRPEM=function(g){var d=KJUR.asn1.csr;if(g.subject===undefined){throw"parameter subject undefined"}if(g.sbjpubkey===undefined){throw"parameter sbjpubkey undefined"}if(g.sigalg===undefined){throw"parameter sigalg undefined"}if(g.sbjprvkey===undefined){throw"parameter sbjpubkey undefined"}var b=new d.CertificationRequestInfo();b.setSubjectByParam(g.subject);b.setSubjectPublicKeyByGetKey(g.sbjpubkey);if(g.ext!==undefined&&g.ext.length!==undefined){for(var c=0;c0){var e=new KJUR.asn1.DERSequence({array:this.extensionsArray});var d=new KJUR.asn1.DERSet({array:[e]});var c=new KJUR.asn1.DERSequence({array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.9.14"}),d]});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a0",obj:c});this.asn1Array.push(b)}else{var b=new KJUR.asn1.DERTaggedObject({explicit:false,tag:"a0",obj:new KJUR.asn1.DERNull()});this.asn1Array.push(b)}var f=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=f.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.csr.CertificationRequestInfo,KJUR.asn1.ASN1Object);KJUR.asn1.csr.CSRUtil=new function(){};KJUR.asn1.csr.CSRUtil.newCSRPEM=function(g){var d=KJUR.asn1.csr;if(g.subject===undefined){throw"parameter subject undefined"}if(g.sbjpubkey===undefined){throw"parameter sbjpubkey undefined"}if(g.sigalg===undefined){throw"parameter sigalg undefined"}if(g.sbjprvkey===undefined){throw"parameter sbjpubkey undefined"}var b=new d.CertificationRequestInfo();b.setSubjectByParam(g.subject);b.setSubjectPublicKeyByGetKey(g.sbjpubkey);if(g.ext!==undefined&&g.ext.length!==undefined){for(var c=0;cd){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()}; +if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECDSA=function(h){var e="secp256r1";var g=null;var b=null;var f=null;var a=new SecureRandom();var d=null;this.type="EC";this.isPrivate=false;this.isPublic=false;function c(s,o,r,n){var j=Math.max(o.bitLength(),n.bitLength());var t=s.add2D(r);var q=s.curve.getInfinity();for(var p=j-1;p>=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}};this.readPKCS5PrvKeyHex=function(l){var n=ASN1HEX;var m=KJUR.crypto.ECDSA.getName;var p=n.getVbyList;if(n.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var i,k,o;try{i=p(l,0,[2,0],"06");k=p(l,0,[1],"04");try{o=p(l,0,[3,0],"03").substr(2)}catch(j){}}catch(j){throw"malformed PKCS#1/5 plain ECC private key"}this.curveName=m(i);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(o);this.setPrivateKeyHex(k);this.isPublic=false};this.readPKCS8PrvKeyHex=function(l){var q=ASN1HEX;var i=KJUR.crypto.ECDSA.getName;var n=q.getVbyList;if(q.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var j,p,m,k;try{j=n(l,0,[1,0],"06");p=n(l,0,[1,1],"06");m=n(l,0,[2,0,1],"04");try{k=n(l,0,[2,0,2,0],"03").substr(2)}catch(o){}}catch(o){throw"malformed PKCS#8 plain ECC private key"}this.curveName=i(p);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(k);this.setPrivateKeyHex(m);this.isPublic=false};this.readPKCS8PubKeyHex=function(l){var n=ASN1HEX;var m=KJUR.crypto.ECDSA.getName;var p=n.getVbyList;if(n.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var k,i,o;try{k=p(l,0,[0,0],"06");i=p(l,0,[0,1],"06");o=p(l,0,[1],"03").substr(2)}catch(j){throw"malformed PKCS#8 ECC public key"}this.curveName=m(i);if(this.curveName===null){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(o)};this.readCertPubKeyHex=function(k,p){if(p!==5){p=6}var m=ASN1HEX;var l=KJUR.crypto.ECDSA.getName;var o=m.getVbyList;if(m.isASN1HEX(k)===false){throw"not ASN.1 hex string"}var i,n;try{i=o(k,0,[0,p,0,1],"06");n=o(k,0,[0,p,1],"03").substr(2)}catch(j){throw"malformed X.509 certificate ECC public key"}this.curveName=l(i);if(this.curveName===null){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(n)};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()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040022"){return"secp384r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}return null}; /*! ecparam-1.0.0.js (c) 2013 Kenji Urushima | kjur.github.com/jsrsasign/license */ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v0||a.compareTo(b)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(t)>0||t.compareTo(b)>0){throw"invalid DSA signature"}var m=t.modInverse(b);var e=k.multiply(m).mod(b);var c=a.multiply(m).mod(b);var n=j.modPow(e,d).multiply(l.modPow(c,d)).mod(d).mod(b);return n.compareTo(a)==0};this.parseASN1Signature=function(a){try{var d=new BigInteger(ASN1HEX.getVbyList(a,0,[0],"02"),16);var c=new BigInteger(ASN1HEX.getVbyList(a,0,[1],"02"),16);return[d,c]}catch(b){throw"malformed ASN.1 DSA signature"}}}; -/*! pkcs5pkey-1.0.7.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.DSA=function(){this.p=null;this.q=null;this.g=null;this.y=null;this.x=null;this.type="DSA";this.isPrivate=false;this.isPublic=false;this.setPrivate=function(d,c,b,e,a){this.isPrivate=true;this.p=d;this.q=c;this.g=b;this.y=e;this.x=a};this.setPrivateHex=function(d,b,f,i,j){var c,a,e,g,h;c=new BigInteger(d,16);a=new BigInteger(b,16);e=new BigInteger(f,16);if(typeof i==="string"&&i.length>1){g=new BigInteger(i,16)}else{g=null}h=new BigInteger(j,16);this.setPrivate(c,a,e,g,h)};this.setPublic=function(c,b,a,d){this.isPublic=true;this.p=c;this.q=b;this.g=a;this.y=d;this.x=null};this.setPublicHex=function(f,e,d,g){var b,a,h,c;b=new BigInteger(f,16);a=new BigInteger(e,16);h=new BigInteger(d,16);c=new BigInteger(g,16);this.setPublic(b,a,h,c)};this.signWithMessageHash=function(d){var c=this.p;var b=this.q;var f=this.g;var i=this.y;var j=this.x;var e=KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE),b.subtract(BigInteger.ONE));var l=d.substr(0,b.bitLength()/4);var h=new BigInteger(l,16);var a=(f.modPow(e,c)).mod(b);var n=(e.modInverse(b).multiply(h.add(j.multiply(a)))).mod(b);var m=KJUR.asn1.ASN1Util.jsonToASN1HEX({seq:[{"int":{bigint:a}},{"int":{bigint:n}}]});return m};this.verifyWithMessageHash=function(h,f){var d=this.p;var b=this.q;var j=this.g;var l=this.y;var i=this.parseASN1Signature(f);var a=i[0];var t=i[1];var o=h.substr(0,b.bitLength()/4);var k=new BigInteger(o,16);if(BigInteger.ZERO.compareTo(a)>0||a.compareTo(b)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(t)>0||t.compareTo(b)>0){throw"invalid DSA signature"}var m=t.modInverse(b);var e=k.multiply(m).mod(b);var c=a.multiply(m).mod(b);var n=j.modPow(e,d).multiply(l.modPow(c,d)).mod(d).mod(b);return n.compareTo(a)==0};this.parseASN1Signature=function(a){try{var d=new BigInteger(ASN1HEX.getVbyList(a,0,[0],"02"),16);var c=new BigInteger(ASN1HEX.getVbyList(a,0,[1],"02"),16);return[d,c]}catch(b){throw"malformed ASN.1 DSA signature"}};this.readPKCS5PrvKeyHex=function(c){var b,a,f,g,i;var j=ASN1HEX;var d=j.getVbyList;if(j.isASN1HEX(c)===false){throw"not ASN.1 hex string"}try{b=d(c,0,[1],"02");a=d(c,0,[2],"02");f=d(c,0,[3],"02");g=d(c,0,[4],"02");i=d(c,0,[5],"02")}catch(e){console.log("EXCEPTION:"+e);throw"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(b,a,f,g,i)};this.readPKCS8PrvKeyHex=function(d){var f,c,b,g;var e=ASN1HEX;var i=e.getVbyList;if(e.isASN1HEX(d)===false){throw"not ASN.1 hex string"}try{f=i(d,0,[1,1,0],"02");c=i(d,0,[1,1,1],"02");b=i(d,0,[1,1,2],"02");g=i(d,0,[2,0],"02")}catch(a){console.log("EXCEPTION:"+a);throw"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(f,c,b,null,g)};this.readPKCS8PubKeyHex=function(d){var f,c,b,g;var e=ASN1HEX;var i=e.getVbyList;if(e.isASN1HEX(d)===false){throw"not ASN.1 hex string"}try{f=i(d,0,[0,1,0],"02");c=i(d,0,[0,1,1],"02");b=i(d,0,[0,1,2],"02");g=i(d,0,[1,0],"02")}catch(a){console.log("EXCEPTION:"+a);throw"malformed PKCS#8 DSA public key"}this.setPublicHex(f,c,b,g)};this.readCertPubKeyHex=function(c,f){if(f!==5){f=6}var b,a,g,i;var j=ASN1HEX;var d=j.getVbyList;if(j.isASN1HEX(c)===false){throw"not ASN.1 hex string"}try{b=d(c,0,[0,f,0,1,0],"02");a=d(c,0,[0,f,0,1,1],"02");g=d(c,0,[0,f,0,1,2],"02");i=d(c,0,[0,f,1,0],"02")}catch(e){console.log("EXCEPTION:"+e);throw"malformed X.509 certificate DSA public key"}this.setPublicHex(b,a,g,i)}}; +/*! pkcs5pkey-1.1.0.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -var PKCS5PKEY=function(){var c=function(n,p,o){return i(CryptoJS.AES,n,p,o)};var d=function(n,p,o){return i(CryptoJS.TripleDES,n,p,o)};var i=function(q,v,s,o){var p=CryptoJS.enc.Hex.parse(v);var u=CryptoJS.enc.Hex.parse(s);var n=CryptoJS.enc.Hex.parse(o);var r={};r.key=u;r.iv=n;r.ciphertext=p;var t=q.decrypt(r,u,{iv:n});return CryptoJS.enc.Hex.stringify(t)};var j=function(n,p,o){return e(CryptoJS.AES,n,p,o)};var m=function(n,p,o){return e(CryptoJS.TripleDES,n,p,o)};var e=function(s,x,v,p){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(v);var o=CryptoJS.enc.Hex.parse(p);var n={};var u=s.encrypt(r,w,{iv:o});var q=CryptoJS.enc.Hex.parse(u.toString());var t=CryptoJS.enc.Base64.stringify(q);return t};var g={"AES-256-CBC":{proc:c,eproc:j,keylen:32,ivlen:16},"AES-192-CBC":{proc:c,eproc:j,keylen:24,ivlen:16},"AES-128-CBC":{proc:c,eproc:j,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:d,eproc:m,keylen:24,ivlen:8}};var b=function(n){return g[n]["proc"]};var k=function(n){var p=CryptoJS.lib.WordArray.random(n);var o=CryptoJS.enc.Hex.stringify(p);return o};var l=function(t){var u={};var o=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(o){u.cipher=o[1];u.ivsalt=o[2]}var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(n){u.type=n[1]}var r=-1;var v=0;if(t.indexOf("\r\n\r\n")!=-1){r=t.indexOf("\r\n\r\n");v=2}if(t.indexOf("\n\n")!=-1){r=t.indexOf("\n\n");v=1}var q=t.indexOf("-----END");if(r!=-1&&q!=-1){var p=t.substring(r+v*2,q-v);p=p.replace(/\s+/g,"");u.data=p}return u};var h=function(o,w,n){var t=n.substring(0,16);var r=CryptoJS.enc.Hex.parse(t);var p=CryptoJS.enc.Utf8.parse(w);var s=g[o]["keylen"]+g[o]["ivlen"];var v="";var u=null;for(;;){var q=CryptoJS.algo.MD5.create();if(u!=null){q.update(u)}q.update(p);q.update(r);u=q.finalize();v=v+CryptoJS.enc.Hex.stringify(u);if(v.length>=s*2){break}}var x={};x.keyhex=v.substr(0,g[o]["keylen"]*2);x.ivhex=v.substr(g[o]["keylen"]*2,g[o]["ivlen"]*2);return x};var a=function(n,t,p,u){var q=CryptoJS.enc.Base64.parse(n);var o=CryptoJS.enc.Hex.stringify(q);var s=g[t]["proc"];var r=s(o,p,u);return r};var f=function(n,q,o,s){var p=g[q]["eproc"];var r=p(n,o,s);return r};return{version:"1.0.5",getHexFromPEM:function(o,r){var p=o;if(p.indexOf("BEGIN "+r)==-1){throw"can't find PEM header: "+r}p=p.replace("-----BEGIN "+r+"-----","");p=p.replace("-----END "+r+"-----","");var q=p.replace(/\s+/g,"");var n=b64tohex(q);return n},getDecryptedKeyHexByKeyIV:function(o,r,q,p){var n=b(r);return n(o,q,p)},parsePKCS5PEM:function(n){return l(n)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(o,n,p){return h(o,n,p)},decryptKeyB64:function(n,p,o,q){return a(n,p,o,q)},getDecryptedKeyHex:function(w,v){var o=l(w);var r=o.type;var p=o.cipher;var n=o.ivsalt;var q=o.data;var u=h(p,v,n);var t=u.keyhex;var s=a(q,p,t,n);return s},getRSAKeyFromEncryptedPKCS5PEM:function(p,o){var q=this.getDecryptedKeyHex(p,o);var n=new RSAKey();n.readPrivateKeyFromASN1HexString(q);return n},getEncryptedPKCS5PEMFromPrvKeyHex:function(q,x,r,p){if(typeof r=="undefined"||r==null){r="AES-256-CBC"}if(typeof g[r]=="undefined"){throw"PKCS5PKEY unsupported algorithm: "+r}if(typeof p=="undefined"||p==null){var t=g[r]["ivlen"];var s=k(t);p=s.toUpperCase()}var w=h(r,x,p);var v=w.keyhex;var u=f(q,r,v,p);var o=u.replace(/(.{64})/g,"$1\r\n");var n="-----BEGIN RSA PRIVATE KEY-----\r\n";n+="Proc-Type: 4,ENCRYPTED\r\n";n+="DEK-Info: "+r+","+p+"\r\n";n+="\r\n";n+=o;n+="\r\n-----END RSA PRIVATE KEY-----\r\n";return n},getEncryptedPKCS5PEMFromRSAKey:function(C,D,o,s){var A=new KJUR.asn1.DERInteger({"int":0});var v=new KJUR.asn1.DERInteger({bigint:C.n});var z=new KJUR.asn1.DERInteger({"int":C.e});var B=new KJUR.asn1.DERInteger({bigint:C.d});var t=new KJUR.asn1.DERInteger({bigint:C.p});var r=new KJUR.asn1.DERInteger({bigint:C.q});var y=new KJUR.asn1.DERInteger({bigint:C.dmp1});var u=new KJUR.asn1.DERInteger({bigint:C.dmq1});var x=new KJUR.asn1.DERInteger({bigint:C.coeff});var E=new KJUR.asn1.DERSequence({array:[A,v,z,B,t,r,y,u,x]});var w=E.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex(w,D,o,s)},newEncryptedPKCS5PEM:function(n,o,r,s){if(typeof o=="undefined"||o==null){o=1024}if(typeof r=="undefined"||r==null){r="10001"}var p=new RSAKey();p.generate(o,r);var q=null;if(typeof s=="undefined"||s==null){q=this.getEncryptedPKCS5PEMFromRSAKey(pkey,n)}else{q=this.getEncryptedPKCS5PEMFromRSAKey(pkey,n,s)}return q},getRSAKeyFromPlainPKCS8PEM:function(p){if(p.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var o=this.getHexFromPEM(p,"PRIVATE KEY");var n=this.getRSAKeyFromPlainPKCS8Hex(o);return n},getRSAKeyFromPlainPKCS8Hex:function(q){var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=3){throw"outer DERSequence shall have 3 elements: "+p.length}var o=ASN1HEX.getHexOfTLV_AtObj(q,p[1]);if(o!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmIdentifier is not rsaEnc: "+o}var r=ASN1HEX.getHexOfTLV_AtObj(q,p[2]);var s=ASN1HEX.getHexOfV_AtObj(r,0);var n=new RSAKey();n.readPrivateKeyFromASN1HexString(s);return n},parseHexOfEncryptedPKCS8:function(u){var q={};var p=ASN1HEX.getPosArrayOfChildren_AtObj(u,0);if(p.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+p.length}q.ciphertext=ASN1HEX.getHexOfV_AtObj(u,p[1]);var w=ASN1HEX.getPosArrayOfChildren_AtObj(u,p[0]);if(w.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+w.length}if(ASN1HEX.getHexOfV_AtObj(u,w[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(u,w[1]);if(w.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+n.length}var o=ASN1HEX.getPosArrayOfChildren_AtObj(u,n[1]);if(o.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+o.length}if(ASN1HEX.getHexOfV_AtObj(u,o[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}q.encryptionSchemeAlg="TripleDES";q.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(u,o[1]);var r=ASN1HEX.getPosArrayOfChildren_AtObj(u,n[0]);if(r.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+r.length}if(ASN1HEX.getHexOfV_AtObj(u,r[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var v=ASN1HEX.getPosArrayOfChildren_AtObj(u,r[1]);if(v.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+v.length}q.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(u,v[0]);var s=ASN1HEX.getHexOfV_AtObj(u,v[1]);try{q.pbkdf2Iter=parseInt(s,16)}catch(t){throw"malformed format pbkdf2Iter: "+s}return q},getPBKDF2KeyHexFromParam:function(s,n){var r=CryptoJS.enc.Hex.parse(s.pbkdf2Salt);var o=s.pbkdf2Iter;var q=CryptoJS.PBKDF2(n,r,{keySize:192/32,iterations:o});var p=CryptoJS.enc.Hex.stringify(q);return p},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(v,w){var p=this.getHexFromPEM(v,"ENCRYPTED PRIVATE KEY");var n=this.parseHexOfEncryptedPKCS8(p);var s=PKCS5PKEY.getPBKDF2KeyHexFromParam(n,w);var t={};t.ciphertext=CryptoJS.enc.Hex.parse(n.ciphertext);var r=CryptoJS.enc.Hex.parse(s);var q=CryptoJS.enc.Hex.parse(n.encryptionSchemeIV);var u=CryptoJS.TripleDES.decrypt(t,r,{iv:q});var o=CryptoJS.enc.Hex.stringify(u);return o},getRSAKeyFromEncryptedPKCS8PEM:function(q,p){var o=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(q,p);var n=this.getRSAKeyFromPlainPKCS8Hex(o);return n},getKeyFromEncryptedPKCS8PEM:function(q,o){var n=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(q,o);var p=this.getKeyFromPlainPrivatePKCS8Hex(n);return p},parsePlainPrivatePKCS8Hex:function(q){var o={};o.algparam=null;if(q.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(q.substr(p[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(q,p[1]);if(n.length!=2){throw"malformed PKCS8 private key(code:004)"}if(q.substr(n[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}o.algoid=ASN1HEX.getHexOfV_AtObj(q,n[0]);if(q.substr(n[1],2)=="06"){o.algparam=ASN1HEX.getHexOfV_AtObj(q,n[1])}if(q.substr(p[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}o.keyidx=ASN1HEX.getStartPosOfV_AtObj(q,p[2]);return o},getKeyFromPlainPrivatePKCS8PEM:function(o){var n=this.getHexFromPEM(o,"PRIVATE KEY");var p=this.getKeyFromPlainPrivatePKCS8Hex(n);return p},getKeyFromPlainPrivatePKCS8Hex:function(n){var p=this.parsePlainPrivatePKCS8Hex(n);if(p.algoid=="2a864886f70d010101"){this.parsePrivateRawRSAKeyHexAtObj(n,p);var o=p.key;var q=new RSAKey();q.setPrivateEx(o.n,o.e,o.d,o.p,o.q,o.dp,o.dq,o.co);return q}else{if(p.algoid=="2a8648ce3d0201"){this.parsePrivateRawECKeyHexAtObj(n,p);if(KJUR.crypto.OID.oidhex2name[p.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+p.algparam}var r=KJUR.crypto.OID.oidhex2name[p.algparam];var q=new KJUR.crypto.ECDSA({curve:r,prv:p.key});return q}else{throw"unsupported private key algorithm"}}},getRSAKeyFromPublicPKCS8PEM:function(o){var p=this.getHexFromPEM(o,"PUBLIC KEY");var n=this.getRSAKeyFromPublicPKCS8Hex(p);return n},getKeyFromPublicPKCS8PEM:function(o){var p=this.getHexFromPEM(o,"PUBLIC KEY");var n=this.getKeyFromPublicPKCS8Hex(p);return n},getKeyFromPublicPKCS8Hex:function(o){var n=this.parsePublicPKCS8Hex(o);if(n.algoid=="2a864886f70d010101"){var r=this.parsePublicRawRSAKeyHex(n.key);var p=new RSAKey();p.setPublic(r.n,r.e);return p}else{if(n.algoid=="2a8648ce3d0201"){if(KJUR.crypto.OID.oidhex2name[n.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+n.algparam}var q=KJUR.crypto.OID.oidhex2name[n.algparam];var p=new KJUR.crypto.ECDSA({curve:q,pub:n.key});return p}else{throw"unsupported public key algorithm"}}},parsePublicRawRSAKeyHex:function(p){var n={};if(p.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,0);if(o.length!=2){throw"malformed RSA key(code:002)"}if(p.substr(o[0],2)!="02"){throw"malformed RSA key(code:003)"}n.n=ASN1HEX.getHexOfV_AtObj(p,o[0]);if(p.substr(o[1],2)!="02"){throw"malformed RSA key(code:004)"}n.e=ASN1HEX.getHexOfV_AtObj(p,o[1]);return n},parsePrivateRawRSAKeyHexAtObj:function(o,q){var p=q.keyidx;if(o.substr(p,2)!="30"){throw"malformed RSA private key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(o,p);if(n.length!=9){throw"malformed RSA private key(code:002)"}q.key={};q.key.n=ASN1HEX.getHexOfV_AtObj(o,n[1]);q.key.e=ASN1HEX.getHexOfV_AtObj(o,n[2]);q.key.d=ASN1HEX.getHexOfV_AtObj(o,n[3]);q.key.p=ASN1HEX.getHexOfV_AtObj(o,n[4]);q.key.q=ASN1HEX.getHexOfV_AtObj(o,n[5]);q.key.dp=ASN1HEX.getHexOfV_AtObj(o,n[6]);q.key.dq=ASN1HEX.getHexOfV_AtObj(o,n[7]);q.key.co=ASN1HEX.getHexOfV_AtObj(o,n[8])},parsePrivateRawECKeyHexAtObj:function(o,q){var p=q.keyidx;if(o.substr(p,2)!="30"){throw"malformed ECC private key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(o,p);if(n.length!=3){throw"malformed ECC private key(code:002)"}if(o.substr(n[1],2)!="04"){throw"malformed ECC private key(code:003)"}q.key=ASN1HEX.getHexOfV_AtObj(o,n[1])},parsePublicPKCS8Hex:function(q){var o={};o.algparam=null;var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=2){throw"outer DERSequence shall have 2 elements: "+p.length}var r=p[0];if(q.substr(r,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(q,r);if(n.length!=2){throw"malformed PKCS8 public key(code:002)"}if(q.substr(n[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}o.algoid=ASN1HEX.getHexOfV_AtObj(q,n[0]);if(q.substr(n[1],2)=="06"){o.algparam=ASN1HEX.getHexOfV_AtObj(q,n[1])}if(q.substr(p[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}o.key=ASN1HEX.getHexOfV_AtObj(q,p[1]).substr(2);return o},getRSAKeyFromPublicPKCS8Hex:function(r){var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"outer DERSequence shall have 2 elements: "+q.length}var p=ASN1HEX.getHexOfTLV_AtObj(r,q[0]);if(p!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmId is not rsaEncryption"}if(r.substr(q[1],2)!="03"){throw"PKCS8 Public Key is not BITSTRING encapslated."}var t=ASN1HEX.getStartPosOfV_AtObj(r,q[1])+2;if(r.substr(t,2)!="30"){throw"PKCS8 Public Key is not SEQUENCE."}var n=ASN1HEX.getPosArrayOfChildren_AtObj(r,t);if(n.length!=2){throw"inner DERSequence shall have 2 elements: "+n.length}if(r.substr(n[0],2)!="02"){throw"N is not ASN.1 INTEGER"}if(r.substr(n[1],2)!="02"){throw"E is not ASN.1 INTEGER"}var u=ASN1HEX.getHexOfV_AtObj(r,n[0]);var s=ASN1HEX.getHexOfV_AtObj(r,n[1]);var o=new RSAKey();o.setPublic(u,s);return o},}}(); -/*! keyutil-1.0.14.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +var PKCS5PKEY=function(){var c=function(o,q,p){return j(CryptoJS.AES,o,q,p)};var d=function(o,q,p){return j(CryptoJS.TripleDES,o,q,p)};var j=function(r,w,t,p){var q=CryptoJS.enc.Hex.parse(w);var v=CryptoJS.enc.Hex.parse(t);var o=CryptoJS.enc.Hex.parse(p);var s={};s.key=v;s.iv=o;s.ciphertext=q;var u=r.decrypt(s,v,{iv:o});return CryptoJS.enc.Hex.stringify(u)};var k=function(o,q,p){return e(CryptoJS.AES,o,q,p)};var n=function(o,q,p){return e(CryptoJS.TripleDES,o,q,p)};var e=function(t,y,w,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(w);var p=CryptoJS.enc.Hex.parse(q);var o={};var v=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(v.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var g={"AES-256-CBC":{proc:c,eproc:k,keylen:32,ivlen:16},"AES-192-CBC":{proc:c,eproc:k,keylen:24,ivlen:16},"AES-128-CBC":{proc:c,eproc:k,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:d,eproc:n,keylen:24,ivlen:8}};var b=function(o){return g[o]["proc"]};var l=function(o){var q=CryptoJS.lib.WordArray.random(o);var p=CryptoJS.enc.Hex.stringify(q);return p};var m=function(u){var v={};var p=u.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(p){v.cipher=p[1];v.ivsalt=p[2]}var o=u.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(o){v.type=o[1]}var t=-1;var w=0;if(u.indexOf("\r\n\r\n")!=-1){t=u.indexOf("\r\n\r\n");w=2}if(u.indexOf("\n\n")!=-1){t=u.indexOf("\n\n");w=1}var r=u.indexOf("-----END");if(t!=-1&&r!=-1){var q=u.substring(t+w*2,r-w);q=q.replace(/\s+/g,"");v.data=q}return v};var i=function(p,x,o){var u=o.substring(0,16);var s=CryptoJS.enc.Hex.parse(u);var q=CryptoJS.enc.Utf8.parse(x);var t=g[p]["keylen"]+g[p]["ivlen"];var w="";var v=null;for(;;){var r=CryptoJS.algo.MD5.create();if(v!=null){r.update(v)}r.update(q);r.update(s);v=r.finalize();w=w+CryptoJS.enc.Hex.stringify(v);if(w.length>=t*2){break}}var y={};y.keyhex=w.substr(0,g[p]["keylen"]*2);y.ivhex=w.substr(g[p]["keylen"]*2,g[p]["ivlen"]*2);return y};var a=function(o,u,q,v){var r=CryptoJS.enc.Base64.parse(o);var p=CryptoJS.enc.Hex.stringify(r);var t=g[u]["proc"];var s=t(p,q,v);return s};var f=function(o,r,p,t){var q=g[r]["eproc"];var s=q(o,p,t);return s};return{version:"1.0.5",getHexFromPEM:function(o,p){return ASN1HEX.pemToHex(o,p)},getDecryptedKeyHexByKeyIV:function(p,s,r,q){var o=b(s);return o(p,r,q)},parsePKCS5PEM:function(o){return m(o)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(p,o,q){return i(p,o,q)},decryptKeyB64:function(o,q,p,r){return a(o,q,p,r)},getDecryptedKeyHex:function(x,w){var p=m(x);var s=p.type;var q=p.cipher;var o=p.ivsalt;var r=p.data;var v=i(q,w,o);var u=v.keyhex;var t=a(r,q,u,o);return t},getRSAKeyFromEncryptedPKCS5PEM:function(q,p){var r=this.getDecryptedKeyHex(q,p);var o=new RSAKey();o.readPrivateKeyFromASN1HexString(r);return o},getEncryptedPKCS5PEMFromPrvKeyHex:function(r,y,s,q){if(typeof s=="undefined"||s==null){s="AES-256-CBC"}if(typeof g[s]=="undefined"){throw"PKCS5PKEY unsupported algorithm: "+s}if(typeof q=="undefined"||q==null){var u=g[s]["ivlen"];var t=l(u);q=t.toUpperCase()}var x=i(s,y,q);var w=x.keyhex;var v=f(r,s,w,q);var p=v.replace(/(.{64})/g,"$1\r\n");var o="-----BEGIN RSA PRIVATE KEY-----\r\n";o+="Proc-Type: 4,ENCRYPTED\r\n";o+="DEK-Info: "+s+","+q+"\r\n";o+="\r\n";o+=p;o+="\r\n-----END RSA PRIVATE KEY-----\r\n";return o},getEncryptedPKCS5PEMFromRSAKey:function(C,D,o,s){var A=new KJUR.asn1.DERInteger({"int":0});var v=new KJUR.asn1.DERInteger({bigint:C.n});var z=new KJUR.asn1.DERInteger({"int":C.e});var B=new KJUR.asn1.DERInteger({bigint:C.d});var t=new KJUR.asn1.DERInteger({bigint:C.p});var r=new KJUR.asn1.DERInteger({bigint:C.q});var y=new KJUR.asn1.DERInteger({bigint:C.dmp1});var u=new KJUR.asn1.DERInteger({bigint:C.dmq1});var x=new KJUR.asn1.DERInteger({bigint:C.coeff});var E=new KJUR.asn1.DERSequence({array:[A,v,z,B,t,r,y,u,x]});var w=E.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex(w,D,o,s)},newEncryptedPKCS5PEM:function(o,p,s,t){if(typeof p=="undefined"||p==null){p=1024}if(typeof s=="undefined"||s==null){s="10001"}var q=new RSAKey();q.generate(p,s);var r=null;if(typeof t=="undefined"||t==null){r=this.getEncryptedPKCS5PEMFromRSAKey(pkey,o)}else{r=this.getEncryptedPKCS5PEMFromRSAKey(pkey,o,t)}return r},getRSAKeyFromPlainPKCS8PEM:function(q){if(q.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var p=ASN1HEX.pemToHex(q,"PRIVATE KEY");var o=this.getRSAKeyFromPlainPKCS8Hex(p);return o},getRSAKeyFromPlainPKCS8Hex:function(p){var o=new RSAKey();o.readPKCS8PrvKeyHex(p);return o},parseHexOfEncryptedPKCS8:function(v){var r={};var q=ASN1HEX.getPosArrayOfChildren_AtObj(v,0);if(q.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+q.length}r.ciphertext=ASN1HEX.getHexOfV_AtObj(v,q[1]);var x=ASN1HEX.getPosArrayOfChildren_AtObj(v,q[0]);if(x.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+x.length}if(ASN1HEX.getHexOfV_AtObj(v,x[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(v,x[1]);if(x.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length}var p=ASN1HEX.getPosArrayOfChildren_AtObj(v,o[1]);if(p.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+p.length}if(ASN1HEX.getHexOfV_AtObj(v,p[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}r.encryptionSchemeAlg="TripleDES";r.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(v,p[1]);var s=ASN1HEX.getPosArrayOfChildren_AtObj(v,o[0]);if(s.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+s.length}if(ASN1HEX.getHexOfV_AtObj(v,s[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var w=ASN1HEX.getPosArrayOfChildren_AtObj(v,s[1]);if(w.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+w.length}r.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(v,w[0]);var t=ASN1HEX.getHexOfV_AtObj(v,w[1]);try{r.pbkdf2Iter=parseInt(t,16)}catch(u){throw"malformed format pbkdf2Iter: "+t}return r},getPBKDF2KeyHexFromParam:function(t,o){var s=CryptoJS.enc.Hex.parse(t.pbkdf2Salt);var p=t.pbkdf2Iter;var r=CryptoJS.PBKDF2(o,s,{keySize:192/32,iterations:p});var q=CryptoJS.enc.Hex.stringify(r);return q},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(w,x){var q=ASN1HEX.pemToHex(w,"ENCRYPTED PRIVATE KEY");var o=this.parseHexOfEncryptedPKCS8(q);var t=PKCS5PKEY.getPBKDF2KeyHexFromParam(o,x);var u={};u.ciphertext=CryptoJS.enc.Hex.parse(o.ciphertext);var s=CryptoJS.enc.Hex.parse(t);var r=CryptoJS.enc.Hex.parse(o.encryptionSchemeIV);var v=CryptoJS.TripleDES.decrypt(u,s,{iv:r});var p=CryptoJS.enc.Hex.stringify(v);return p},getRSAKeyFromEncryptedPKCS8PEM:function(r,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(r,q);var o=this.getRSAKeyFromPlainPKCS8Hex(p);return o},getKeyFromEncryptedPKCS8PEM:function(r,p){var o=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(r,p);var q=this.getKeyFromPlainPrivatePKCS8Hex(o);return q},parsePlainPrivatePKCS8Hex:function(r){var p={};p.algparam=null;if(r.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(r.substr(q[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(r,q[1]);if(o.length!=2){throw"malformed PKCS8 private key(code:004)"}if(r.substr(o[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}p.algoid=ASN1HEX.getHexOfV_AtObj(r,o[0]);if(r.substr(o[1],2)=="06"){p.algparam=ASN1HEX.getHexOfV_AtObj(r,o[1])}if(r.substr(q[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}p.keyidx=ASN1HEX.getStartPosOfV_AtObj(r,q[2]);return p},getKeyFromPlainPrivatePKCS8PEM:function(p){var o=ASN1HEX.pemToHex(p,"PRIVATE KEY");var q=this.getKeyFromPlainPrivatePKCS8Hex(o);return q},getKeyFromPlainPrivatePKCS8Hex:function(o){var p=this.parsePlainPrivatePKCS8Hex(o);var q;if(p.algoid=="2a864886f70d010101"){q=new RSAKey()}else{if(p.algoid=="2a8648ce380401"){q=new KJUR.crypto.DSA()}else{if(p.algoid=="2a8648ce3d0201"){q=new KJUR.crypto.ECDSA()}else{throw"unsupported private key algorithm"}}}q.readPKCS8PrvKeyHex(o);return q},getRSAKeyFromPublicPKCS8PEM:function(p){var q=ASN1HEX.pemToHex(p,"PUBLIC KEY");var o=this.getRSAKeyFromPublicPKCS8Hex(q);return o},getKeyFromPublicPKCS8PEM:function(p){var q=ASN1HEX.pemToHex(p,"PUBLIC KEY");var o=this.getKeyFromPublicPKCS8Hex(q);return o},getKeyFromPublicPKCS8Hex:function(o){var p;var q=ASN1HEX.getVbyList(h,0,[0,0],"06");if(q==="2a864886f70d010101"){p=new RSAKey()}else{if(q==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(q==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw"unsupported PKCS#8 public key hex"}}}p.readPKCS8PubKeyHex(h);return p},parsePublicRawRSAKeyHex:function(q){var o={};if(q.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=2){throw"malformed RSA key(code:002)"}if(q.substr(p[0],2)!="02"){throw"malformed RSA key(code:003)"}o.n=ASN1HEX.getHexOfV_AtObj(q,p[0]);if(q.substr(p[1],2)!="02"){throw"malformed RSA key(code:004)"}o.e=ASN1HEX.getHexOfV_AtObj(q,p[1]);return o},parsePrivateRawRSAKeyHexAtObj:function(p,r){var q=r.keyidx;if(p.substr(q,2)!="30"){throw"malformed RSA private key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,q);if(o.length!=9){throw"malformed RSA private key(code:002)"}r.key={};r.key.n=ASN1HEX.getHexOfV_AtObj(p,o[1]);r.key.e=ASN1HEX.getHexOfV_AtObj(p,o[2]);r.key.d=ASN1HEX.getHexOfV_AtObj(p,o[3]);r.key.p=ASN1HEX.getHexOfV_AtObj(p,o[4]);r.key.q=ASN1HEX.getHexOfV_AtObj(p,o[5]);r.key.dp=ASN1HEX.getHexOfV_AtObj(p,o[6]);r.key.dq=ASN1HEX.getHexOfV_AtObj(p,o[7]);r.key.co=ASN1HEX.getHexOfV_AtObj(p,o[8])},parsePrivateRawECKeyHexAtObj:function(p,r){var q=r.keyidx;if(p.substr(q,2)!="30"){throw"malformed ECC private key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,q);if(o.length!=3){throw"malformed ECC private key(code:002)"}if(p.substr(o[1],2)!="04"){throw"malformed ECC private key(code:003)"}r.key=ASN1HEX.getHexOfV_AtObj(p,o[1])},parsePublicPKCS8Hex:function(r){var p={};p.algparam=null;var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"outer DERSequence shall have 2 elements: "+q.length}var s=q[0];if(r.substr(s,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(r,s);if(o.length!=2){throw"malformed PKCS8 public key(code:002)"}if(r.substr(o[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}p.algoid=ASN1HEX.getHexOfV_AtObj(r,o[0]);if(r.substr(o[1],2)=="06"){p.algparam=ASN1HEX.getHexOfV_AtObj(r,o[1])}if(r.substr(q[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}p.key=ASN1HEX.getHexOfV_AtObj(r,q[1]).substr(2);return p},getRSAKeyFromPublicPKCS8Hex:function(o){var p=new RSAKey();p.readPKCS8PubKeyHex(o);return p},}}(); +/*! keyutil-1.0.15.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",getHexFromPEM:function(q,u){var r=q;if(r.indexOf("-----BEGIN ")==-1){throw"can't find PEM header: "+u}if(typeof u=="string"&&u!=""){r=r.replace("-----BEGIN "+u+"-----","");r=r.replace("-----END "+u+"-----","")}else{r=r.replace(/-----BEGIN [^-]+-----/,"");r=r.replace(/-----END [^-]+-----/,"")}var t=r.replace(/\s+/g,"");var p=b64tohex(t);return p},getDecryptedKeyHexByKeyIV:function(q,t,s,r){var p=c(t);return p(q,s,r)},parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getRSAKeyFromEncryptedPKCS5PEM:function(r,q){var s=this.getDecryptedKeyHex(r,q);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(s);return p},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw"KEYUTIL unsupported algorithm: "+t}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},getEncryptedPKCS5PEMFromRSAKey:function(D,E,r,t){var B=new KJUR.asn1.DERInteger({"int":0});var w=new KJUR.asn1.DERInteger({bigint:D.n});var A=new KJUR.asn1.DERInteger({"int":D.e});var C=new KJUR.asn1.DERInteger({bigint:D.d});var u=new KJUR.asn1.DERInteger({bigint:D.p});var s=new KJUR.asn1.DERInteger({bigint:D.q});var z=new KJUR.asn1.DERInteger({bigint:D.dmp1});var v=new KJUR.asn1.DERInteger({bigint:D.dmq1});var y=new KJUR.asn1.DERInteger({bigint:D.coeff});var F=new KJUR.asn1.DERSequence({array:[B,w,A,C,u,s,z,v,y]});var x=F.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,E,r,t)},newEncryptedPKCS5PEM:function(p,q,t,u){if(typeof q=="undefined"||q==null){q=1024}if(typeof t=="undefined"||t==null){t="10001"}var r=new RSAKey();r.generate(q,t);var s=null;if(typeof u=="undefined"||u==null){s=this.getEncryptedPKCS5PEMFromRSAKey(r,p)}else{s=this.getEncryptedPKCS5PEMFromRSAKey(r,p,u)}return s},getRSAKeyFromPlainPKCS8PEM:function(r){if(r.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var q=this.getHexFromPEM(r,"PRIVATE KEY");var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getRSAKeyFromPlainPKCS8Hex:function(s){var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"outer DERSequence shall have 3 elements: "+r.length}var q=ASN1HEX.getHexOfTLV_AtObj(s,r[1]);if(q!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmIdentifier is not rsaEnc: "+q}var q=ASN1HEX.getHexOfTLV_AtObj(s,r[1]);var t=ASN1HEX.getHexOfTLV_AtObj(s,r[2]);var u=ASN1HEX.getHexOfV_AtObj(t,0);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(u);return p},parseHexOfEncryptedPKCS8:function(w){var s={};var r=ASN1HEX.getPosArrayOfChildren_AtObj(w,0);if(r.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+r.length}s.ciphertext=ASN1HEX.getHexOfV_AtObj(w,r[1]);var y=ASN1HEX.getPosArrayOfChildren_AtObj(w,r[0]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+y.length}if(ASN1HEX.getHexOfV_AtObj(w,y[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(w,y[1]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+p.length}var q=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[1]);if(q.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length}if(ASN1HEX.getHexOfV_AtObj(w,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}s.encryptionSchemeAlg="TripleDES";s.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(w,q[1]);var t=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[0]);if(t.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+t.length}if(ASN1HEX.getHexOfV_AtObj(w,t[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var x=ASN1HEX.getPosArrayOfChildren_AtObj(w,t[1]);if(x.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length}s.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(w,x[0]);var u=ASN1HEX.getHexOfV_AtObj(w,x[1]);try{s.pbkdf2Iter=parseInt(u,16)}catch(v){throw"malformed format pbkdf2Iter: "+u}return s},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=this.getHexFromPEM(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getRSAKeyFromEncryptedPKCS8PEM:function(s,r){var q=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,r);var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(s.substr(r[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,r[1]);if(p.length!=2){throw"malformed PKCS8 private key(code:004)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}if(s.substr(r[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}q.keyidx=ASN1HEX.getStartPosOfV_AtObj(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=this.getHexFromPEM(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var w=this.parsePlainPrivatePKCS8Hex(p);if(w.algoid=="2a864886f70d010101"){this.parsePrivateRawRSAKeyHexAtObj(p,w);var u=w.key;var z=new RSAKey();z.setPrivateEx(u.n,u.e,u.d,u.p,u.q,u.dp,u.dq,u.co);return z}else{if(w.algoid=="2a8648ce3d0201"){this.parsePrivateRawECKeyHexAtObj(p,w);if(KJUR.crypto.OID.oidhex2name[w.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+w.algparam}var v=KJUR.crypto.OID.oidhex2name[w.algparam];var z=new KJUR.crypto.ECDSA({curve:v});z.setPublicKeyHex(w.pubkey);z.setPrivateKeyHex(w.key);z.isPublic=false;return z}else{if(w.algoid=="2a8648ce380401"){var t=ASN1HEX.getVbyList(p,0,[1,1,0],"02");var s=ASN1HEX.getVbyList(p,0,[1,1,1],"02");var y=ASN1HEX.getVbyList(p,0,[1,1,2],"02");var B=ASN1HEX.getVbyList(p,0,[2,0],"02");var r=new BigInteger(t,16);var q=new BigInteger(s,16);var x=new BigInteger(y,16);var A=new BigInteger(B,16);var z=new KJUR.crypto.DSA();z.setPrivate(r,q,x,null,A);return z}else{throw"unsupported private key algorithm"}}}},getRSAKeyFromPublicPKCS8PEM:function(q){var r=this.getHexFromPEM(q,"PUBLIC KEY");var p=this.getRSAKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8PEM:function(q){var r=this.getHexFromPEM(q,"PUBLIC KEY");var p=this.getKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8Hex:function(q){var p=this.parsePublicPKCS8Hex(q);if(p.algoid=="2a864886f70d010101"){var u=this.parsePublicRawRSAKeyHex(p.key);var r=new RSAKey();r.setPublic(u.n,u.e);return r}else{if(p.algoid=="2a8648ce3d0201"){if(KJUR.crypto.OID.oidhex2name[p.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+p.algparam}var s=KJUR.crypto.OID.oidhex2name[p.algparam];var r=new KJUR.crypto.ECDSA({curve:s,pub:p.key});return r}else{if(p.algoid=="2a8648ce380401"){var t=p.algparam;var v=ASN1HEX.getHexOfV_AtObj(p.key,0);var r=new KJUR.crypto.DSA();r.setPublic(new BigInteger(t.p,16),new BigInteger(t.q,16),new BigInteger(t.g,16),new BigInteger(v,16));return r}else{throw"unsupported public key algorithm"}}}},parsePublicRawRSAKeyHex:function(r){var p={};if(r.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"malformed RSA key(code:002)"}if(r.substr(q[0],2)!="02"){throw"malformed RSA key(code:003)"}p.n=ASN1HEX.getHexOfV_AtObj(r,q[0]);if(r.substr(q[1],2)!="02"){throw"malformed RSA key(code:004)"}p.e=ASN1HEX.getHexOfV_AtObj(r,q[1]);return p},parsePrivateRawRSAKeyHexAtObj:function(q,s){var r=s.keyidx;if(q.substr(r,2)!="30"){throw"malformed RSA private key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,r);if(p.length!=9){throw"malformed RSA private key(code:002)"}s.key={};s.key.n=ASN1HEX.getHexOfV_AtObj(q,p[1]);s.key.e=ASN1HEX.getHexOfV_AtObj(q,p[2]);s.key.d=ASN1HEX.getHexOfV_AtObj(q,p[3]);s.key.p=ASN1HEX.getHexOfV_AtObj(q,p[4]);s.key.q=ASN1HEX.getHexOfV_AtObj(q,p[5]);s.key.dp=ASN1HEX.getHexOfV_AtObj(q,p[6]);s.key.dq=ASN1HEX.getHexOfV_AtObj(q,p[7]);s.key.co=ASN1HEX.getHexOfV_AtObj(q,p[8])},parsePrivateRawECKeyHexAtObj:function(p,t){var q=t.keyidx;var r=ASN1HEX.getVbyList(p,q,[1],"04");var s=ASN1HEX.getVbyList(p,q,[2,0],"03").substr(2);t.key=r;t.pubkey=s},parsePublicPKCS8Hex:function(s){var q={};q.algparam=null;var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=2){throw"outer DERSequence shall have 2 elements: "+r.length}var t=r[0];if(s.substr(t,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,t);if(p.length!=2){throw"malformed PKCS8 public key(code:002)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}else{if(s.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=ASN1HEX.getVbyList(s,p[1],[0],"02");q.algparam.q=ASN1HEX.getVbyList(s,p[1],[1],"02");q.algparam.g=ASN1HEX.getVbyList(s,p[1],[2],"02")}}if(s.substr(r[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}q.key=ASN1HEX.getHexOfV_AtObj(s,r[1]).substr(2);return q},getRSAKeyFromPublicPKCS8Hex:function(t){var s=ASN1HEX.getPosArrayOfChildren_AtObj(t,0);if(s.length!=2){throw"outer DERSequence shall have 2 elements: "+s.length}var r=ASN1HEX.getHexOfTLV_AtObj(t,s[0]);if(r!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmId is not rsaEncryption"}if(t.substr(s[1],2)!="03"){throw"PKCS8 Public Key is not BITSTRING encapslated."}var v=ASN1HEX.getStartPosOfV_AtObj(t,s[1])+2;if(t.substr(v,2)!="30"){throw"PKCS8 Public Key is not SEQUENCE."}var p=ASN1HEX.getPosArrayOfChildren_AtObj(t,v);if(p.length!=2){throw"inner DERSequence shall have 2 elements: "+p.length}if(t.substr(p[0],2)!="02"){throw"N is not ASN.1 INTEGER"}if(t.substr(p[1],2)!="02"){throw"E is not ASN.1 INTEGER"}var w=ASN1HEX.getHexOfV_AtObj(t,p[0]);var u=ASN1HEX.getHexOfV_AtObj(t,p[1]);var q=new RSAKey();q.setPublic(w,u);return q},}}();KEYUTIL.getKey=function(f,e,h){if(typeof RSAKey!="undefined"&&f instanceof RSAKey){return f}if(typeof KJUR.crypto.ECDSA!="undefined"&&f instanceof KJUR.crypto.ECDSA){return f}if(typeof KJUR.crypto.DSA!="undefined"&&f instanceof KJUR.crypto.DSA){return f}if(f.curve!==undefined&&f.xy!==undefined&&f.d===undefined){return new KJUR.crypto.ECDSA({pub:f.xy,curve:f.curve})}if(f.curve!==undefined&&f.d!==undefined){return new KJUR.crypto.ECDSA({prv:f.d,curve:f.curve})}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d===undefined){var w=new RSAKey();w.setPublic(f.n,f.e);return w}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p!==undefined&&f.q!==undefined&&f.dp!==undefined&&f.dq!==undefined&&f.co!==undefined&&f.qi===undefined){var w=new RSAKey();w.setPrivateEx(f.n,f.e,f.d,f.p,f.q,f.dp,f.dq,f.co);return w}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p===undefined){var w=new RSAKey();w.setPrivate(f.n,f.e,f.d);return w}if(f.p!==undefined&&f.q!==undefined&&f.g!==undefined&&f.y!==undefined&&f.x===undefined){var w=new KJUR.crypto.DSA();w.setPublic(f.p,f.q,f.g,f.y);return w}if(f.p!==undefined&&f.q!==undefined&&f.g!==undefined&&f.y!==undefined&&f.x!==undefined){var w=new KJUR.crypto.DSA();w.setPrivate(f.p,f.q,f.g,f.y,f.x);return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d===undefined){var w=new RSAKey();w.setPublic(b64utohex(f.n),b64utohex(f.e));return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p!==undefined&&f.q!==undefined&&f.dp!==undefined&&f.dq!==undefined&&f.qi!==undefined){var w=new RSAKey();w.setPrivateEx(b64utohex(f.n),b64utohex(f.e),b64utohex(f.d),b64utohex(f.p),b64utohex(f.q),b64utohex(f.dp),b64utohex(f.dq),b64utohex(f.qi));return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined){var w=new RSAKey();w.setPrivate(b64utohex(f.n),b64utohex(f.e),b64utohex(f.d));return w}if(f.kty==="EC"&&f.crv!==undefined&&f.x!==undefined&&f.y!==undefined&&f.d===undefined){var d=new KJUR.crypto.ECDSA({curve:f.crv});var l=d.ecparams.keylen/4;var r=("0000000000"+b64utohex(f.x)).slice(-l);var n=("0000000000"+b64utohex(f.y)).slice(-l);var m="04"+r+n;d.setPublicKeyHex(m);return d}if(f.kty==="EC"&&f.crv!==undefined&&f.x!==undefined&&f.y!==undefined&&f.d!==undefined){var d=new KJUR.crypto.ECDSA({curve:f.crv});var l=d.ecparams.keylen/4;var r=("0000000000"+b64utohex(f.x)).slice(-l);var n=("0000000000"+b64utohex(f.y)).slice(-l);var m="04"+r+n;var a=("0000000000"+b64utohex(f.d)).slice(-l);d.setPublicKeyHex(m);d.setPrivateKeyHex(a);return d}if(f.indexOf("-END CERTIFICATE-",0)!=-1||f.indexOf("-END X509 CERTIFICATE-",0)!=-1||f.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(f)}if(h==="pkcs8pub"){return KEYUTIL.getKeyFromPublicPKCS8Hex(f)}if(f.indexOf("-END PUBLIC KEY-")!=-1){return KEYUTIL.getKeyFromPublicPKCS8PEM(f)}if(h==="pkcs5prv"){var w=new RSAKey();w.readPrivateKeyFromASN1HexString(f);return w}if(h==="pkcs5prv"){var w=new RSAKey();w.readPrivateKeyFromASN1HexString(f);return w}if(f.indexOf("-END RSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")==-1){var i=KEYUTIL.getHexFromPEM(f,"RSA PRIVATE KEY");return KEYUTIL.getKey(i,null,"pkcs5prv")}if(f.indexOf("-END DSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")==-1){var u=this.getHexFromPEM(f,"DSA PRIVATE KEY");var t=ASN1HEX.getVbyList(u,0,[1],"02");var s=ASN1HEX.getVbyList(u,0,[2],"02");var v=ASN1HEX.getVbyList(u,0,[3],"02");var j=ASN1HEX.getVbyList(u,0,[4],"02");var k=ASN1HEX.getVbyList(u,0,[5],"02");var w=new KJUR.crypto.DSA();w.setPrivate(new BigInteger(t,16),new BigInteger(s,16),new BigInteger(v,16),new BigInteger(j,16),new BigInteger(k,16));return w}if(f.indexOf("-END PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(f)}if(f.indexOf("-END RSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(f,e)}if(f.indexOf("-END EC PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){var u=KEYUTIL.getDecryptedKeyHex(f,e);var w=ASN1HEX.getVbyList(u,0,[1],"04");var c=ASN1HEX.getVbyList(u,0,[2,0],"06");var o=ASN1HEX.getVbyList(u,0,[3,0],"03").substr(2);var b="";if(KJUR.crypto.OID.oidhex2name[c]!==undefined){b=KJUR.crypto.OID.oidhex2name[c]}else{throw"undefined OID(hex) in KJUR.crypto.OID: "+c}var d=new KJUR.crypto.ECDSA({name:b});d.setPublicKeyHex(o);d.setPrivateKeyHex(w);d.isPublic=false;return d}if(f.indexOf("-END DSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){var u=KEYUTIL.getDecryptedKeyHex(f,e);var t=ASN1HEX.getVbyList(u,0,[1],"02");var s=ASN1HEX.getVbyList(u,0,[2],"02");var v=ASN1HEX.getVbyList(u,0,[3],"02");var j=ASN1HEX.getVbyList(u,0,[4],"02");var k=ASN1HEX.getVbyList(u,0,[5],"02");var w=new KJUR.crypto.DSA();w.setPrivate(new BigInteger(t,16),new BigInteger(s,16),new BigInteger(v,16),new BigInteger(j,16),new BigInteger(k,16));return w}if(f.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromEncryptedPKCS8PEM(f,e)}throw"not supported argument"};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw"unknown algorithm: "+a}}};KEYUTIL.getPEM=function(a,r,o,g,j){var v=KJUR.asn1;var u=KJUR.crypto;function p(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return w}function q(w){var s=KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:w.prvKeyHex}},{tag:["a0",true,{oid:{name:w.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+w.pubKeyHex}}]}]});return s}function n(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return w}if(((typeof RSAKey!="undefined"&&a instanceof RSAKey)||(typeof u.DSA!="undefined"&&a instanceof u.DSA)||(typeof u.ECDSA!="undefined"&&a instanceof u.ECDSA))&&a.isPublic==true&&(r===undefined||r=="PKCS8PUB")){var t=new KJUR.asn1.x509.SubjectPublicKeyInfo(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"PUBLIC KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o===undefined||o==null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"RSA PRIVATE KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o===undefined||o==null)&&a.isPrivate==true){var f=new KJUR.asn1.DERObjectIdentifier({name:a.curveName});var l=f.getEncodedHex();var e=q(a);var k=e.getEncodedHex();var i="";i+=v.ASN1Util.getPEMStringFromHex(l,"EC PARAMETERS");i+=v.ASN1Util.getPEMStringFromHex(k,"EC PRIVATE KEY");return i}if(r=="PKCS1PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o===undefined||o==null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"DSA PRIVATE KEY")}if(r=="PKCS5PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=q(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",m,o,g)}var h=function(w,s){var y=b(w,s);var x=new KJUR.asn1.ASN1Util.newObject({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:y.pbkdf2Salt}},{"int":y.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:y.encryptionSchemeIV}}]}]}]},{octstr:{hex:y.ciphertext}}]});return x.getEncodedHex()};var b=function(D,E){var x=100;var C=CryptoJS.lib.WordArray.random(8);var B="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var y=CryptoJS.PBKDF2(E,C,{keySize:192/32,iterations:x});var z=CryptoJS.enc.Hex.parse(D);var A=CryptoJS.TripleDES.encrypt(z,y,{iv:s})+"";var w={};w.ciphertext=A;w.pbkdf2Salt=CryptoJS.enc.Hex.stringify(C);w.pbkdf2Iter=x;w.encryptionSchemeAlg=B;w.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return w};if(r=="PKCS8PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&a.isPrivate==true){var d=p(a);var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&a.isPrivate==true){var d=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:a.prvKeyHex}},{tag:["a1",true,{bitstr:{hex:"00"+a.pubKeyHex}}]}]});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:a.curveName}}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&a.isPrivate==true){var d=new KJUR.asn1.DERInteger({bigint:a.x});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:a.p}},{"int":{bigint:a.q}},{"int":{bigint:a.g}}]}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}throw"unsupported object nor format"};KEYUTIL.getKeyFromCSRPEM=function(b){var a=KEYUTIL.getHexFromPEM(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(c){var b={};var e=c;if(e.substr(0,2)!="30"){throw"malformed CSR(code:001)"}var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,0);if(d.length<1){throw"malformed CSR(code:002)"}if(e.substr(d[0],2)!="30"){throw"malformed CSR(code:003)"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(e,d[0]);if(a.length<3){throw"malformed CSR(code:004)"}b.p8pubkeyhex=ASN1HEX.getHexOfTLV_AtObj(e,a[2]);return b};KEYUTIL.getJWKFromKey=function(d){var b={};if(d instanceof RSAKey&&d.isPrivate){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));b.d=hextob64u(d.d.toString(16));b.p=hextob64u(d.p.toString(16));b.q=hextob64u(d.q.toString(16));b.dp=hextob64u(d.dmp1.toString(16));b.dq=hextob64u(d.dmq1.toString(16));b.qi=hextob64u(d.coeff.toString(16));return b}else{if(d instanceof RSAKey&&d.isPublic){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPrivate){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);b.d=hextob64u(d.prvKeyHex);return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPublic){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);return b}}}}throw"not supported key object"}; -/*! rsapem-1.1.js (c) 2012 Kenji Urushima | kjur.github.com/jsrsasign/license +var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",getHexFromPEM:function(p,q){return ASN1HEX.pemToHex(p,q)},getDecryptedKeyHexByKeyIV:function(q,t,s,r){var p=c(t);return p(q,s,r)},parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getRSAKeyFromEncryptedPKCS5PEM:function(r,q){var s=this.getDecryptedKeyHex(r,q);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(s);return p},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw"KEYUTIL unsupported algorithm: "+t}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},getEncryptedPKCS5PEMFromRSAKey:function(D,E,r,t){var B=new KJUR.asn1.DERInteger({"int":0});var w=new KJUR.asn1.DERInteger({bigint:D.n});var A=new KJUR.asn1.DERInteger({"int":D.e});var C=new KJUR.asn1.DERInteger({bigint:D.d});var u=new KJUR.asn1.DERInteger({bigint:D.p});var s=new KJUR.asn1.DERInteger({bigint:D.q});var z=new KJUR.asn1.DERInteger({bigint:D.dmp1});var v=new KJUR.asn1.DERInteger({bigint:D.dmq1});var y=new KJUR.asn1.DERInteger({bigint:D.coeff});var F=new KJUR.asn1.DERSequence({array:[B,w,A,C,u,s,z,v,y]});var x=F.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,E,r,t)},newEncryptedPKCS5PEM:function(p,q,t,u){if(typeof q=="undefined"||q==null){q=1024}if(typeof t=="undefined"||t==null){t="10001"}var r=new RSAKey();r.generate(q,t);var s=null;if(typeof u=="undefined"||u==null){s=this.getEncryptedPKCS5PEMFromRSAKey(r,p)}else{s=this.getEncryptedPKCS5PEMFromRSAKey(r,p,u)}return s},getRSAKeyFromPlainPKCS8PEM:function(r){if(r.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var q=ASN1HEX.pemToHex(r,"PRIVATE KEY");var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getRSAKeyFromPlainPKCS8Hex:function(q){var p=new RSAKey();p.readPKCS8PrvKeyHex(q);return p},parseHexOfEncryptedPKCS8:function(w){var s={};var r=ASN1HEX.getPosArrayOfChildren_AtObj(w,0);if(r.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+r.length}s.ciphertext=ASN1HEX.getHexOfV_AtObj(w,r[1]);var y=ASN1HEX.getPosArrayOfChildren_AtObj(w,r[0]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+y.length}if(ASN1HEX.getHexOfV_AtObj(w,y[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(w,y[1]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+p.length}var q=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[1]);if(q.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length}if(ASN1HEX.getHexOfV_AtObj(w,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}s.encryptionSchemeAlg="TripleDES";s.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(w,q[1]);var t=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[0]);if(t.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+t.length}if(ASN1HEX.getHexOfV_AtObj(w,t[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var x=ASN1HEX.getPosArrayOfChildren_AtObj(w,t[1]);if(x.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length}s.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(w,x[0]);var u=ASN1HEX.getHexOfV_AtObj(w,x[1]);try{s.pbkdf2Iter=parseInt(u,16)}catch(v){throw"malformed format pbkdf2Iter: "+u}return s},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=ASN1HEX.pemToHex(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getRSAKeyFromEncryptedPKCS8PEM:function(s,r){var q=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,r);var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(s.substr(r[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,r[1]);if(p.length!=2){throw"malformed PKCS8 private key(code:004)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}if(s.substr(r[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}q.keyidx=ASN1HEX.getStartPosOfV_AtObj(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=ASN1HEX.pemToHex(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var q=this.parsePlainPrivatePKCS8Hex(p);var r;if(q.algoid=="2a864886f70d010101"){r=new RSAKey()}else{if(q.algoid=="2a8648ce380401"){r=new KJUR.crypto.DSA()}else{if(q.algoid=="2a8648ce3d0201"){r=new KJUR.crypto.ECDSA()}else{throw"unsupported private key algorithm"}}}r.readPKCS8PrvKeyHex(p);return r},getRSAKeyFromPublicPKCS8PEM:function(q){var r=ASN1HEX.pemToHex(q,"PUBLIC KEY");var p=this.getRSAKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8PEM:function(q){var r=ASN1HEX.pemToHex(q,"PUBLIC KEY");var p=this.getKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8Hex:function(q){var p;var r=ASN1HEX.getVbyList(q,0,[0,0],"06");if(r==="2a864886f70d010101"){p=new RSAKey()}else{if(r==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(r==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw"unsupported PKCS#8 public key hex"}}}p.readPKCS8PubKeyHex(q);return p},parsePublicRawRSAKeyHex:function(r){var p={};if(r.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"malformed RSA key(code:002)"}if(r.substr(q[0],2)!="02"){throw"malformed RSA key(code:003)"}p.n=ASN1HEX.getHexOfV_AtObj(r,q[0]);if(r.substr(q[1],2)!="02"){throw"malformed RSA key(code:004)"}p.e=ASN1HEX.getHexOfV_AtObj(r,q[1]);return p},parsePrivateRawRSAKeyHexAtObj:function(q,u){var t=ASN1HEX;var r=t.getHexOfV_AtObj;var s=t.getDecendantIndexByNthList(q,0,[2,0]);var p=t.getPosArrayOfChildren_AtObj(q,s);if(p.length!==9){throw"malformed PKCS#8 plain RSA private key"}u.key={};u.key.n=r(q,p[1]);u.key.e=r(q,p[2]);u.key.d=r(q,p[3]);u.key.p=r(q,p[4]);u.key.q=r(q,p[5]);u.key.dp=r(q,p[6]);u.key.dq=r(q,p[7]);u.key.co=r(q,p[8])},parsePrivateRawECKeyHexAtObj:function(p,t){var s=ASN1HEX;var q=t.keyidx;var r=new KJUR.crypto.ECDSA();r.readPKCS8PrvKeyHex(p);t.key=r.prvKeyHex;t.pubkey=r.pubKeyHex},parsePublicPKCS8Hex:function(s){var q={};q.algparam=null;var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=2){throw"outer DERSequence shall have 2 elements: "+r.length}var t=r[0];if(s.substr(t,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,t);if(p.length!=2){throw"malformed PKCS8 public key(code:002)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}else{if(s.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=ASN1HEX.getVbyList(s,p[1],[0],"02");q.algparam.q=ASN1HEX.getVbyList(s,p[1],[1],"02");q.algparam.g=ASN1HEX.getVbyList(s,p[1],[2],"02")}}if(s.substr(r[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}q.key=ASN1HEX.getHexOfV_AtObj(s,r[1]).substr(2);return q},getRSAKeyFromPublicPKCS8Hex:function(p){var q=new RSAKey();q.readPKCS8PubKeyHex(p);return q},}}();KEYUTIL.getKey=function(i,f,j){if(typeof RSAKey!="undefined"&&i instanceof RSAKey){return i}if(typeof KJUR.crypto.ECDSA!="undefined"&&i instanceof KJUR.crypto.ECDSA){return i}if(typeof KJUR.crypto.DSA!="undefined"&&i instanceof KJUR.crypto.DSA){return i}if(i.curve!==undefined&&i.xy!==undefined&&i.d===undefined){return new KJUR.crypto.ECDSA({pub:i.xy,curve:i.curve})}if(i.curve!==undefined&&i.d!==undefined){return new KJUR.crypto.ECDSA({prv:i.d,curve:i.curve})}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d===undefined){var D=new RSAKey();D.setPublic(i.n,i.e);return D}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p!==undefined&&i.q!==undefined&&i.dp!==undefined&&i.dq!==undefined&&i.co!==undefined&&i.qi===undefined){var D=new RSAKey();D.setPrivateEx(i.n,i.e,i.d,i.p,i.q,i.dp,i.dq,i.co);return D}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p===undefined){var D=new RSAKey();D.setPrivate(i.n,i.e,i.d);return D}if(i.p!==undefined&&i.q!==undefined&&i.g!==undefined&&i.y!==undefined&&i.x===undefined){var D=new KJUR.crypto.DSA();D.setPublic(i.p,i.q,i.g,i.y);return D}if(i.p!==undefined&&i.q!==undefined&&i.g!==undefined&&i.y!==undefined&&i.x!==undefined){var D=new KJUR.crypto.DSA();D.setPrivate(i.p,i.q,i.g,i.y,i.x);return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d===undefined){var D=new RSAKey();D.setPublic(b64utohex(i.n),b64utohex(i.e));return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p!==undefined&&i.q!==undefined&&i.dp!==undefined&&i.dq!==undefined&&i.qi!==undefined){var D=new RSAKey();D.setPrivateEx(b64utohex(i.n),b64utohex(i.e),b64utohex(i.d),b64utohex(i.p),b64utohex(i.q),b64utohex(i.dp),b64utohex(i.dq),b64utohex(i.qi));return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined){var D=new RSAKey();D.setPrivate(b64utohex(i.n),b64utohex(i.e),b64utohex(i.d));return D}if(i.kty==="EC"&&i.crv!==undefined&&i.x!==undefined&&i.y!==undefined&&i.d===undefined){var e=new KJUR.crypto.ECDSA({curve:i.crv});var n=e.ecparams.keylen/4;var t=("0000000000"+b64utohex(i.x)).slice(-n);var r=("0000000000"+b64utohex(i.y)).slice(-n);var o="04"+t+r;e.setPublicKeyHex(o);return e}if(i.kty==="EC"&&i.crv!==undefined&&i.x!==undefined&&i.y!==undefined&&i.d!==undefined){var e=new KJUR.crypto.ECDSA({curve:i.crv});var n=e.ecparams.keylen/4;var t=("0000000000"+b64utohex(i.x)).slice(-n);var r=("0000000000"+b64utohex(i.y)).slice(-n);var o="04"+t+r;var b=("0000000000"+b64utohex(i.d)).slice(-n);e.setPublicKeyHex(o);e.setPrivateKeyHex(b);return e}if(j==="pkcs5prv"){var A=i,w=ASN1HEX,C,D;C=w.getPosArrayOfChildren_AtObj(A,0);if(C.length===9){D=new RSAKey();D.readPrivateKeyFromASN1HexString(i)}else{if(C.length===6){D=new KJUR.crypto.DSA();D.readPKCS5PrvKeyHex(A)}else{if(C.length>2&&A.substr(C[1],2)==="04"){D=new KJUR.crypto.ECDSA();D.readPKCS5PrvKeyHex(A)}else{throw"unsupported PKCS#1/5 hexadecimal key"}}}return D}if(j==="pkcs8prv"){var D=KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(i);return D}if(j==="pkcs8pub"){return KEYUTIL.getKeyFromPublicPKCS8Hex(i)}if(j==="x509pub"){return X509.getPublicKeyFromCertHex(i)}if(i.indexOf("-END CERTIFICATE-",0)!=-1||i.indexOf("-END X509 CERTIFICATE-",0)!=-1||i.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(i)}if(i.indexOf("-END PUBLIC KEY-")!=-1){return KEYUTIL.getKeyFromPublicPKCS8PEM(i)}if(i.indexOf("-END RSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")==-1){var k=ASN1HEX.pemToHex(i,"RSA PRIVATE KEY");return KEYUTIL.getKey(k,null,"pkcs5prv")}if(i.indexOf("-END DSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")==-1){var z=ASN1HEX.pemToHex(i,"DSA PRIVATE KEY");var v=ASN1HEX.getVbyList(z,0,[1],"02");var u=ASN1HEX.getVbyList(z,0,[2],"02");var B=ASN1HEX.getVbyList(z,0,[3],"02");var l=ASN1HEX.getVbyList(z,0,[4],"02");var m=ASN1HEX.getVbyList(z,0,[5],"02");var D=new KJUR.crypto.DSA();D.setPrivate(new BigInteger(v,16),new BigInteger(u,16),new BigInteger(B,16),new BigInteger(l,16),new BigInteger(m,16));return D}if(i.indexOf("-END PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(i)}if(i.indexOf("-END RSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(i,f)}if(i.indexOf("-END EC PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){var z=KEYUTIL.getDecryptedKeyHex(i,f);var D=ASN1HEX.getVbyList(z,0,[1],"04");var d=ASN1HEX.getVbyList(z,0,[2,0],"06");var s=ASN1HEX.getVbyList(z,0,[3,0],"03").substr(2);var c="";if(KJUR.crypto.OID.oidhex2name[d]!==undefined){c=KJUR.crypto.OID.oidhex2name[d]}else{throw"undefined OID(hex) in KJUR.crypto.OID: "+d}var e=new KJUR.crypto.ECDSA({curve:c});e.setPublicKeyHex(s);e.setPrivateKeyHex(D);e.isPublic=false;return e}if(i.indexOf("-END DSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){var z=KEYUTIL.getDecryptedKeyHex(i,f);var v=ASN1HEX.getVbyList(z,0,[1],"02");var u=ASN1HEX.getVbyList(z,0,[2],"02");var B=ASN1HEX.getVbyList(z,0,[3],"02");var l=ASN1HEX.getVbyList(z,0,[4],"02");var m=ASN1HEX.getVbyList(z,0,[5],"02");var D=new KJUR.crypto.DSA();D.setPrivate(new BigInteger(v,16),new BigInteger(u,16),new BigInteger(B,16),new BigInteger(l,16),new BigInteger(m,16));return D}if(i.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromEncryptedPKCS8PEM(i,f)}throw"not supported argument"};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw"unknown algorithm: "+a}}};KEYUTIL.getPEM=function(a,r,o,g,j){var v=KJUR.asn1;var u=KJUR.crypto;function p(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return w}function q(w){var s=KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:w.prvKeyHex}},{tag:["a0",true,{oid:{name:w.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+w.pubKeyHex}}]}]});return s}function n(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return w}if(((typeof RSAKey!="undefined"&&a instanceof RSAKey)||(typeof u.DSA!="undefined"&&a instanceof u.DSA)||(typeof u.ECDSA!="undefined"&&a instanceof u.ECDSA))&&a.isPublic==true&&(r===undefined||r=="PKCS8PUB")){var t=new KJUR.asn1.x509.SubjectPublicKeyInfo(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"PUBLIC KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o===undefined||o==null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"RSA PRIVATE KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o===undefined||o==null)&&a.isPrivate==true){var f=new KJUR.asn1.DERObjectIdentifier({name:a.curveName});var l=f.getEncodedHex();var e=q(a);var k=e.getEncodedHex();var i="";i+=v.ASN1Util.getPEMStringFromHex(l,"EC PARAMETERS");i+=v.ASN1Util.getPEMStringFromHex(k,"EC PRIVATE KEY");return i}if(r=="PKCS1PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o===undefined||o==null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"DSA PRIVATE KEY")}if(r=="PKCS5PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=q(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",m,o,g)}var h=function(w,s){var y=b(w,s);var x=new KJUR.asn1.ASN1Util.newObject({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:y.pbkdf2Salt}},{"int":y.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:y.encryptionSchemeIV}}]}]}]},{octstr:{hex:y.ciphertext}}]});return x.getEncodedHex()};var b=function(D,E){var x=100;var C=CryptoJS.lib.WordArray.random(8);var B="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var y=CryptoJS.PBKDF2(E,C,{keySize:192/32,iterations:x});var z=CryptoJS.enc.Hex.parse(D);var A=CryptoJS.TripleDES.encrypt(z,y,{iv:s})+"";var w={};w.ciphertext=A;w.pbkdf2Salt=CryptoJS.enc.Hex.stringify(C);w.pbkdf2Iter=x;w.encryptionSchemeAlg=B;w.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return w};if(r=="PKCS8PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&a.isPrivate==true){var d=p(a);var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&a.isPrivate==true){var d=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:a.prvKeyHex}},{tag:["a1",true,{bitstr:{hex:"00"+a.pubKeyHex}}]}]});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:a.curveName}}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&a.isPrivate==true){var d=new KJUR.asn1.DERInteger({bigint:a.x});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:a.p}},{"int":{bigint:a.q}},{"int":{bigint:a.g}}]}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}throw"unsupported object nor format"};KEYUTIL.getKeyFromCSRPEM=function(b){var a=ASN1HEX.pemToHex(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(c){var b={};var e=c;if(e.substr(0,2)!="30"){throw"malformed CSR(code:001)"}var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,0);if(d.length<1){throw"malformed CSR(code:002)"}if(e.substr(d[0],2)!="30"){throw"malformed CSR(code:003)"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(e,d[0]);if(a.length<3){throw"malformed CSR(code:004)"}b.p8pubkeyhex=ASN1HEX.getHexOfTLV_AtObj(e,a[2]);return b};KEYUTIL.getJWKFromKey=function(d){var b={};if(d instanceof RSAKey&&d.isPrivate){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));b.d=hextob64u(d.d.toString(16));b.p=hextob64u(d.p.toString(16));b.q=hextob64u(d.q.toString(16));b.dp=hextob64u(d.dmp1.toString(16));b.dq=hextob64u(d.dmq1.toString(16));b.qi=hextob64u(d.coeff.toString(16));return b}else{if(d instanceof RSAKey&&d.isPublic){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPrivate){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);b.d=hextob64u(d.prvKeyHex);return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPublic){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);return b}}}}throw"not supported key object"}; +/*! rsapem-1.2.0.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -function _rsapem_pemToBase64(b){var a=b;a=a.replace("-----BEGIN RSA PRIVATE KEY-----","");a=a.replace("-----END RSA PRIVATE KEY-----","");a=a.replace(/[ \n]+/g,"");return a}function _rsapem_getPosArrayOfChildrenFromHex(d){var j=new Array();var k=ASN1HEX.getStartPosOfV_AtObj(d,0);var f=ASN1HEX.getPosOfNextSibling_AtObj(d,k);var h=ASN1HEX.getPosOfNextSibling_AtObj(d,f);var b=ASN1HEX.getPosOfNextSibling_AtObj(d,h);var l=ASN1HEX.getPosOfNextSibling_AtObj(d,b);var e=ASN1HEX.getPosOfNextSibling_AtObj(d,l);var g=ASN1HEX.getPosOfNextSibling_AtObj(d,e);var c=ASN1HEX.getPosOfNextSibling_AtObj(d,g);var i=ASN1HEX.getPosOfNextSibling_AtObj(d,c);j.push(k,f,h,b,l,e,g,c,i);return j}function _rsapem_getHexValueArrayOfChildrenFromHex(i){var o=_rsapem_getPosArrayOfChildrenFromHex(i);var r=ASN1HEX.getHexOfV_AtObj(i,o[0]);var f=ASN1HEX.getHexOfV_AtObj(i,o[1]);var j=ASN1HEX.getHexOfV_AtObj(i,o[2]);var k=ASN1HEX.getHexOfV_AtObj(i,o[3]);var c=ASN1HEX.getHexOfV_AtObj(i,o[4]);var b=ASN1HEX.getHexOfV_AtObj(i,o[5]);var h=ASN1HEX.getHexOfV_AtObj(i,o[6]);var g=ASN1HEX.getHexOfV_AtObj(i,o[7]);var l=ASN1HEX.getHexOfV_AtObj(i,o[8]);var m=new Array();m.push(r,f,j,k,c,b,h,g,l);return m}function _rsapem_readPrivateKeyFromASN1HexString(c){var b=_rsapem_getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])}function _rsapem_readPrivateKeyFromPEMString(e){var c=_rsapem_pemToBase64(e);var d=b64tohex(c);var b=_rsapem_getHexValueArrayOfChildrenFromHex(d);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])}RSAKey.prototype.readPrivateKeyFromPEMString=_rsapem_readPrivateKeyFromPEMString;RSAKey.prototype.readPrivateKeyFromASN1HexString=_rsapem_readPrivateKeyFromASN1HexString; +RSAKey.pemToBase64=function(b){var a=b;a=a.replace("-----BEGIN RSA PRIVATE KEY-----","");a=a.replace("-----END RSA PRIVATE KEY-----","");a=a.replace(/[ \n]+/g,"");return a};RSAKey.getPosArrayOfChildrenFromHex=function(g){var j=new Array();var i=ASN1HEX.getStartPosOfV_AtObj(g,0);var b=ASN1HEX.getPosOfNextSibling_AtObj(g,i);var e=ASN1HEX.getPosOfNextSibling_AtObj(g,b);var f=ASN1HEX.getPosOfNextSibling_AtObj(g,e);var l=ASN1HEX.getPosOfNextSibling_AtObj(g,f);var k=ASN1HEX.getPosOfNextSibling_AtObj(g,l);var d=ASN1HEX.getPosOfNextSibling_AtObj(g,k);var c=ASN1HEX.getPosOfNextSibling_AtObj(g,d);var h=ASN1HEX.getPosOfNextSibling_AtObj(g,c);j.push(i,b,e,f,l,k,d,c,h);return j};RSAKey.getHexValueArrayOfChildrenFromHex=function(f){var l=RSAKey.getPosArrayOfChildrenFromHex(f);var e=ASN1HEX.getHexOfV_AtObj(f,l[0]);var j=ASN1HEX.getHexOfV_AtObj(f,l[1]);var b=ASN1HEX.getHexOfV_AtObj(f,l[2]);var c=ASN1HEX.getHexOfV_AtObj(f,l[3]);var h=ASN1HEX.getHexOfV_AtObj(f,l[4]);var g=ASN1HEX.getHexOfV_AtObj(f,l[5]);var m=ASN1HEX.getHexOfV_AtObj(f,l[6]);var k=ASN1HEX.getHexOfV_AtObj(f,l[7]);var d=ASN1HEX.getHexOfV_AtObj(f,l[8]);var i=new Array();i.push(e,j,b,c,h,g,m,k,d);return i};RSAKey.prototype.readPrivateKeyFromPEMString=function(e){var c=RSAKey.pemToBase64(e);var d=b64tohex(c);var b=RSAKey.getHexValueArrayOfChildrenFromHex(d);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPrivateKeyFromASN1HexString=function(a){this.readPKCS5PrvKeyHex(a)};RSAKey.prototype.readPKCS5PrvKeyHex=function(c){var b=RSAKey.getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPKCS8PrvKeyHex=function(e){var c,j,l,b,a,f,d,k;var m=ASN1HEX;var g=m.getVbyList;if(m.isASN1HEX(e)===false){throw"not ASN.1 hex string"}try{c=g(e,0,[2,0,1],"02");j=g(e,0,[2,0,2],"02");l=g(e,0,[2,0,3],"02");b=g(e,0,[2,0,4],"02");a=g(e,0,[2,0,5],"02");f=g(e,0,[2,0,6],"02");d=g(e,0,[2,0,7],"02");k=g(e,0,[2,0,8],"02")}catch(i){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(c,j,l,b,a,f,d,k)};RSAKey.prototype.readPKCS5PubKeyHex=function(b){if(ASN1HEX.isASN1HEX(b)===false){throw"keyHex is not ASN.1 hex string"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(b,0);if(a.length!==2||b.substr(a[0],2)!=="02"||b.substr(a[1],2)!=="02"){throw"wrong hex for PKCS#5 public key"}var d=ASN1HEX.getHexOfV_AtObj(b,a[0]);var c=ASN1HEX.getHexOfV_AtObj(b,a[1]);this.setPublic(d,c)};RSAKey.prototype.readPKCS8PubKeyHex=function(b){if(ASN1HEX.isASN1HEX(b)===false){throw"not ASN.1 hex string"}if(ASN1HEX.getDecendantHexTLVByNthList(b,0,[0,0])!=="06092a864886f70d010101"){throw"not PKCS8 RSA public key"}var a=ASN1HEX.getDecendantHexTLVByNthList(b,0,[1,0]);this.readPKCS5PubKeyHex(a)};RSAKey.prototype.readCertPubKeyHex=function(b,c){if(c!==5){c=6}if(ASN1HEX.isASN1HEX(b)===false){throw"not ASN.1 hex string"}var a=ASN1HEX.getDecendantHexTLVByNthList(b,0,[0,c]);this.readPKCS8PubKeyHex(a)}; /*! rsasign-1.2.7.js (c) 2012 Kenji Urushima | kjur.github.com/jsrsasign/license */ var _RE_HEXDECONLY=new RegExp("");_RE_HEXDECONLY.compile("[^0-9a-f]","gi");function _rsasign_getHexPaddedDigestInfoForString(d,e,a){var b=function(f){return KJUR.crypto.Util.hashString(f,a)};var c=b(d);return KJUR.crypto.Util.getPaddedDigestInfoHex(c,a,e)}function _zeroPaddingOfSignature(e,d){var c="";var a=d/4-e.length;for(var b=0;b>24,(d&16711680)>>16,(d&65280)>>8,d&255]))));d+=1}return b}function _rsasign_signStringPSS(e,a,d){var c=function(f){return KJUR.crypto.Util.hashHex(f,a)};var b=c(rstrtohex(e));if(d===undefined){d=-1}return this.signWithMessageHashPSS(b,a,d)}function _rsasign_signWithMessageHashPSS(l,a,k){var b=hextorstr(l);var g=b.length;var m=this.n.bitLength()-1;var c=Math.ceil(m/8);var d;var o=function(i){return KJUR.crypto.Util.hashHex(i,a)};if(k===-1||k===undefined){k=g}else{if(k===-2){k=c-g-2}else{if(k<-2){throw"invalid salt length"}}}if(c<(g+k+2)){throw"data too long"}var f="";if(k>0){f=new Array(k);new SecureRandom().nextBytes(f);f=String.fromCharCode.apply(String,f)}var n=hextorstr(o(rstrtohex("\x00\x00\x00\x00\x00\x00\x00\x00"+b+f)));var j=[];for(d=0;d>(8*c-m))&255;q[0]&=~p;for(d=0;dthis.n.bitLength()){return 0}var i=this.doPublic(b);var e=i.toString(16).replace(/^1f+00/,"");var g=_rsasign_getAlgNameAndHashFromHexDisgestInfo(e);if(g.length==0){return false}var d=g[0];var h=g[1];var a=function(k){return KJUR.crypto.Util.hashString(k,d)};var c=a(f);return(h==c)}function _rsasign_verifyWithMessageHash(e,a){a=a.replace(_RE_HEXDECONLY,"");a=a.replace(/[ \n]+/g,"");var b=parseBigInt(a,16);if(b.bitLength()>this.n.bitLength()){return 0}var h=this.doPublic(b);var g=h.toString(16).replace(/^1f+00/,"");var c=_rsasign_getAlgNameAndHashFromHexDisgestInfo(g);if(c.length==0){return false}var d=c[0];var f=c[1];return(f==e)}function _rsasign_verifyStringPSS(c,b,a,f){var e=function(g){return KJUR.crypto.Util.hashHex(g,a)};var d=e(rstrtohex(c));if(f===undefined){f=-1}return this.verifyWithMessageHashPSS(d,b,a,f)}function _rsasign_verifyWithMessageHashPSS(f,s,l,c){var k=new BigInteger(s,16);if(k.bitLength()>this.n.bitLength()){return false}var r=function(i){return KJUR.crypto.Util.hashHex(i,l)};var j=hextorstr(f);var h=j.length;var g=this.n.bitLength()-1;var m=Math.ceil(g/8);var q;if(c===-1||c===undefined){c=h}else{if(c===-2){c=m-h-2}else{if(c<-2){throw"invalid salt length"}}}if(m<(h+c+2)){throw"data too long"}var a=this.doPublic(k).toByteArray();for(q=0;q>(8*m-g))&255;if((d.charCodeAt(0)&p)!==0){throw"bits beyond keysize not zero"}var n=pss_mgf1_str(e,d.length,r);var o=[];for(q=0;q0){var c=":"+j.join(":")+":";if(c.indexOf(":"+h+":")==-1){throw"algorithm '"+h+"' not accepted in the list"}}if(h!="none"&&t===null){throw"key shall be specified to verify."}if(typeof t=="string"&&t.indexOf("-----BEGIN ")!=-1){t=KEYUTIL.getKey(t)}if(s=="RS"||s=="PS"){if(!(t instanceof RSAKey)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(s=="ES"){if(!(t instanceof KJUR.crypto.ECDSA)){throw"key shall be a ECDSA obj for ES* algs"}}if(h=="none"){}var n=null;if(m.jwsalg2sigalg[i.alg]===undefined){throw"unsupported alg name: "+h}else{n=m.jwsalg2sigalg[h]}if(n=="none"){throw"not supported"}else{if(n.substr(0,4)=="Hmac"){var k=null;if(t===undefined){throw"hexadecimal key shall be specified for HMAC"}var g=new KJUR.crypto.Mac({alg:n,pass:t});g.updateString(b);k=g.doFinal();return r==k}else{if(n.indexOf("withECDSA")!=-1){var f=null;try{f=KJUR.crypto.ECDSA.concatSigToASN1Sig(r)}catch(o){return false}var e=new KJUR.crypto.Signature({alg:n});e.init(t);e.updateString(b);return e.verify(f)}else{var e=new KJUR.crypto.Signature({alg:n});e.init(t);e.updateString(b);return e.verify(r)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(d,j,l){var h=KJUR.jws.JWS;var i=d.split(".");var c=i[0];var g=i[1];var m=c+"."+g;var k=b64utohex(i[2]);var f=h.readSafeJSONString(b64utoutf8(c));var e=h.readSafeJSONString(b64utoutf8(g));if(f.alg===undefined){return false}if(l.alg===undefined){throw"acceptField.alg shall be specified"}if(!h.inArray(f.alg,l.alg)){return false}if(e.iss!==undefined&&typeof l.iss==="object"){if(!h.inArray(e.iss,l.iss)){return false}}if(e.sub!==undefined&&typeof l.sub==="object"){if(!h.inArray(e.sub,l.sub)){return false}}if(e.aud!==undefined&&typeof l.aud==="object"){if(typeof e.aud=="string"){if(!h.inArray(e.aud,l.aud)){return false}}else{if(typeof e.aud=="object"){if(!h.includedArray(e.aud,l.aud)){return false}}}}var b=KJUR.jws.IntDate.getNow();if(l.verifyAt!==undefined&&typeof l.verifyAt==="number"){b=l.verifyAt}if(l.gracePeriod===undefined||typeof l.gracePeriod!=="number"){l.gracePeriod=0}if(e.exp!==undefined&&typeof e.exp=="number"){if(e.exp+l.gracePeriodMIT License */ @@ -278,7 +278,7 @@ var KEYUTIL = function() { version: "1.0.0", /** - * get hexacedimal string of PEM format + * (DEPRECATED) get hexacedimal string of PEM format * @name getHexFromPEM * @memberOf KEYUTIL * @function @@ -286,22 +286,10 @@ var KEYUTIL = function() { * @param {String} sHead PEM header string without BEGIN/END * @return {String} hexadecimal string data of PEM contents * @since pkcs5pkey 1.0.5 + * @deprecated from keyutil 1.1.0 jsrsasign 7.0.1. please move to {@link ASN1HEX.pemToHex} */ getHexFromPEM: function(sPEM, sHead) { - var s = sPEM; - if (s.indexOf("-----BEGIN ") == -1) { - throw "can't find PEM header: " + sHead; - } - if (typeof sHead == "string" && sHead != "") { - s = s.replace("-----BEGIN " + sHead + "-----", ""); - s = s.replace("-----END " + sHead + "-----", ""); - } else { - s = s.replace(/-----BEGIN [^-]+-----/, ''); - s = s.replace(/-----END [^-]+-----/, ''); - } - var sB64 = s.replace(/\s+/g, ''); - var dataHex = b64tohex(sB64); - return dataHex; + return ASN1HEX.pemToHex(sPEM, sHead); }, /** @@ -562,7 +550,7 @@ var KEYUTIL = function() { getRSAKeyFromPlainPKCS8PEM: function(pkcs8PEM) { if (pkcs8PEM.match(/ENCRYPTED/)) throw "pem shall be not ENCRYPTED"; - var prvKeyHex = this.getHexFromPEM(pkcs8PEM, "PRIVATE KEY"); + var prvKeyHex = ASN1HEX.pemToHex(pkcs8PEM, "PRIVATE KEY"); var rsaKey = this.getRSAKeyFromPlainPKCS8Hex(prvKeyHex); return rsaKey; }, @@ -578,20 +566,10 @@ var KEYUTIL = function() { * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}. */ getRSAKeyFromPlainPKCS8Hex: function(prvKeyHex) { - var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(prvKeyHex, 0); - if (a1.length != 3) - throw "outer DERSequence shall have 3 elements: " + a1.length; - var algIdTLV =ASN1HEX.getHexOfTLV_AtObj(prvKeyHex, a1[1]); - if (algIdTLV != "300d06092a864886f70d0101010500") // AlgId rsaEncryption - throw "PKCS8 AlgorithmIdentifier is not rsaEnc: " + algIdTLV; - var algIdTLV = ASN1HEX.getHexOfTLV_AtObj(prvKeyHex, a1[1]); - var octetStr = ASN1HEX.getHexOfTLV_AtObj(prvKeyHex, a1[2]); - var p5KeyHex = ASN1HEX.getHexOfV_AtObj(octetStr, 0); - //alert(p5KeyHex); var rsaKey = new RSAKey(); - rsaKey.readPrivateKeyFromASN1HexString(p5KeyHex); + rsaKey.readPKCS8PrvKeyHex(prvKeyHex); return rsaKey; - }, + }, /** * generate PBKDF2 key hexstring with specified passcode and information @@ -738,7 +716,7 @@ var KEYUTIL = function() { */ getPlainPKCS8HexFromEncryptedPKCS8PEM: function(pkcs8PEM, passcode) { // 1. derHex - PKCS#8 private key encrypted by PBKDF2 - var derHex = this.getHexFromPEM(pkcs8PEM, "ENCRYPTED PRIVATE KEY"); + var derHex = ASN1HEX.pemToHex(pkcs8PEM, "ENCRYPTED PRIVATE KEY"); // 2. info - PKCS#5 PBES info var info = this.parseHexOfEncryptedPKCS8(derHex); // 3. hKey - PBKDF2 key @@ -862,54 +840,36 @@ var KEYUTIL = function() { * @since pkcs5pkey 1.0.5 */ getKeyFromPlainPrivatePKCS8PEM: function(prvKeyPEM) { - var prvKeyHex = this.getHexFromPEM(prvKeyPEM, "PRIVATE KEY"); + var prvKeyHex = ASN1HEX.pemToHex(prvKeyPEM, "PRIVATE KEY"); var key = this.getKeyFromPlainPrivatePKCS8Hex(prvKeyHex); return key; }, /** - * get RSAKey/ECDSA private key object from HEX plain PEM PKCS#8 private key + * get RSAKey/DSA/ECDSA private key object from HEX plain PEM PKCS#8 private key * @name getKeyFromPlainPrivatePKCS8Hex * @memberOf KEYUTIL * @function * @param {String} prvKeyHex hexadecimal string of plain PKCS#8 private key - * @return {Object} RSAKey or KJUR.crypto.ECDSA private key object + * @return {Object} RSAKey or KJUR.crypto.{DSA,ECDSA} private key object * @since pkcs5pkey 1.0.5 */ getKeyFromPlainPrivatePKCS8Hex: function(prvKeyHex) { var p8 = this.parsePlainPrivatePKCS8Hex(prvKeyHex); + var key; if (p8.algoid == "2a864886f70d010101") { // RSA - this.parsePrivateRawRSAKeyHexAtObj(prvKeyHex, p8); - var k = p8.key; - var key = new RSAKey(); - key.setPrivateEx(k.n, k.e, k.d, k.p, k.q, k.dp, k.dq, k.co); - return key; + key = new RSAKey(); + } else if (p8.algoid == "2a8648ce380401") { // DSA + key = new KJUR.crypto.DSA(); } else if (p8.algoid == "2a8648ce3d0201") { // ECC - this.parsePrivateRawECKeyHexAtObj(prvKeyHex, p8); - if (KJUR.crypto.OID.oidhex2name[p8.algparam] === undefined) - throw "KJUR.crypto.OID.oidhex2name undefined: " + p8.algparam; - var curveName = KJUR.crypto.OID.oidhex2name[p8.algparam]; - var key = new KJUR.crypto.ECDSA({'curve': curveName}); - key.setPublicKeyHex(p8.pubkey); - key.setPrivateKeyHex(p8.key); - key.isPublic = false; - return key; - } else if (p8.algoid == "2a8648ce380401") { // DSA - var hP = ASN1HEX.getVbyList(prvKeyHex, 0, [1,1,0], "02"); - var hQ = ASN1HEX.getVbyList(prvKeyHex, 0, [1,1,1], "02"); - var hG = ASN1HEX.getVbyList(prvKeyHex, 0, [1,1,2], "02"); - var hX = ASN1HEX.getVbyList(prvKeyHex, 0, [2,0], "02"); - var biP = new BigInteger(hP, 16); - var biQ = new BigInteger(hQ, 16); - var biG = new BigInteger(hG, 16); - var biX = new BigInteger(hX, 16); - var key = new KJUR.crypto.DSA(); - key.setPrivate(biP, biQ, biG, null, biX); - return key; + key = new KJUR.crypto.ECDSA(); } else { throw "unsupported private key algorithm"; } + + key.readPKCS8PrvKeyHex(prvKeyHex); + return key; }, // === PKCS8 RSA Public Key ================================================ @@ -924,7 +884,7 @@ var KEYUTIL = function() { * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}. */ getRSAKeyFromPublicPKCS8PEM: function(pkcs8PubPEM) { - var pubKeyHex = this.getHexFromPEM(pkcs8PubPEM, "PUBLIC KEY"); + var pubKeyHex = ASN1HEX.pemToHex(pkcs8PubPEM, "PUBLIC KEY"); var rsaKey = this.getRSAKeyFromPublicPKCS8Hex(pubKeyHex); return rsaKey; }, @@ -940,7 +900,7 @@ var KEYUTIL = function() { * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}. */ getKeyFromPublicPKCS8PEM: function(pkcs8PubPEM) { - var pubKeyHex = this.getHexFromPEM(pkcs8PubPEM, "PUBLIC KEY"); + var pubKeyHex = ASN1HEX.pemToHex(pkcs8PubPEM, "PUBLIC KEY"); var key = this.getKeyFromPublicPKCS8Hex(pubKeyHex); return key; }, @@ -955,33 +915,22 @@ var KEYUTIL = function() { * @since pkcs5pkey 1.0.5 * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}. */ - getKeyFromPublicPKCS8Hex: function(pkcs8PubHex) { - var p8 = this.parsePublicPKCS8Hex(pkcs8PubHex); - - if (p8.algoid == "2a864886f70d010101") { // RSA - var aRSA = this.parsePublicRawRSAKeyHex(p8.key); - var key = new RSAKey(); - key.setPublic(aRSA.n, aRSA.e); - return key; - } else if (p8.algoid == "2a8648ce3d0201") { // ECC - if (KJUR.crypto.OID.oidhex2name[p8.algparam] === undefined) - throw "KJUR.crypto.OID.oidhex2name undefined: " + p8.algparam; - var curveName = KJUR.crypto.OID.oidhex2name[p8.algparam]; - var key = new KJUR.crypto.ECDSA({'curve': curveName, 'pub': p8.key}); - return key; - } else if (p8.algoid == "2a8648ce380401") { // DSA 1.2.840.10040.4.1 - var param = p8.algparam; - var y = ASN1HEX.getHexOfV_AtObj(p8.key, 0); - var key = new KJUR.crypto.DSA(); - key.setPublic(new BigInteger(param.p, 16), - new BigInteger(param.q, 16), - new BigInteger(param.g, 16), - new BigInteger(y, 16)); - return key; - } else { - throw "unsupported public key algorithm"; - } - }, + getKeyFromPublicPKCS8Hex: function(h) { + var key; + var hOID = ASN1HEX.getVbyList(h, 0, [0, 0], "06"); + + if (hOID === "2a864886f70d010101") { // oid=RSA + key = new RSAKey(); + } else if (hOID === "2a8648ce380401") { // oid=DSA + key = new KJUR.crypto.DSA(); + } else if (hOID === "2a8648ce3d0201") { // oid=ECPUB + key = new KJUR.crypto.ECDSA(); + } else { + throw "unsupported PKCS#8 public key hex"; + } + key.readPKCS8PubKeyHex(h); + return key; + }, /** * parse hexadecimal string of plain PKCS#8 private key @@ -1032,6 +981,7 @@ var KEYUTIL = function() { * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 private key concluding RSA private key * @return {Array} info associative array to add parsed RSA private key information * @since pkcs5pkey 1.0.5 + * @deprecated since jsrsasign 7.1.0 keyutil 1.1.0 * @description * Following properties are added to associative array 'info' *
      @@ -1046,26 +996,24 @@ var KEYUTIL = function() { *
    */ parsePrivateRawRSAKeyHexAtObj: function(pkcs8PrvHex, info) { - var keyIdx = info.keyidx; - - // 1. sequence - if (pkcs8PrvHex.substr(keyIdx, 2) != "30") - throw "malformed RSA private key(code:001)"; // not sequence + var _ASN1HEX = ASN1HEX; + var _getV = _ASN1HEX.getHexOfV_AtObj; - var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, keyIdx); - if (a1.length != 9) - throw "malformed RSA private key(code:002)"; // not sequence + var idxSeq = _ASN1HEX.getDecendantIndexByNthList(pkcs8PrvHex, 0, [2, 0]); + var a = _ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PrvHex, idxSeq); + + if (a.length !== 9) throw "malformed PKCS#8 plain RSA private key"; // 2. RSA key info.key = {}; - info.key.n = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[1]); - info.key.e = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[2]); - info.key.d = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[3]); - info.key.p = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[4]); - info.key.q = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[5]); - info.key.dp = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[6]); - info.key.dq = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[7]); - info.key.co = ASN1HEX.getHexOfV_AtObj(pkcs8PrvHex, a1[8]); + info.key.n = _getV(pkcs8PrvHex, a[1]); + info.key.e = _getV(pkcs8PrvHex, a[2]); + info.key.d = _getV(pkcs8PrvHex, a[3]); + info.key.p = _getV(pkcs8PrvHex, a[4]); + info.key.q = _getV(pkcs8PrvHex, a[5]); + info.key.dp = _getV(pkcs8PrvHex, a[6]); + info.key.dq = _getV(pkcs8PrvHex, a[7]); + info.key.co = _getV(pkcs8PrvHex, a[8]); }, /** @@ -1076,6 +1024,7 @@ var KEYUTIL = function() { * @param {String} pkcs8PrvHex hexadecimal string of PKCS#8 private key concluding EC private key * @return {Array} info associative array to add parsed ECC private key information * @since pkcs5pkey 1.0.5 + * @deprecated since jsrsasign 7.1.0 keyutil 1.1.0 * @description * Following properties are added to associative array 'info' *
      @@ -1083,13 +1032,15 @@ var KEYUTIL = function() { *
    */ parsePrivateRawECKeyHexAtObj: function(pkcs8PrvHex, info) { + var _ASN1HEX = ASN1HEX; + var keyIdx = info.keyidx; - - var key = ASN1HEX.getVbyList(pkcs8PrvHex, keyIdx, [1], "04"); - var pubkey = ASN1HEX.getVbyList(pkcs8PrvHex, keyIdx, [2,0], "03").substr(2); - info.key = key; - info.pubkey = pubkey; + var ec = new KJUR.crypto.ECDSA(); + ec.readPKCS8PrvKeyHex(pkcs8PrvHex); + + info.key = ec.prvKeyHex; + info.pubkey = ec.pubKeyHex; }, /** @@ -1162,42 +1113,10 @@ var KEYUTIL = function() { * @deprecated From jsrsasign 4.2.1 please use {@link KEYUTIL.getKey#}. */ getRSAKeyFromPublicPKCS8Hex: function(pkcs8PubHex) { - var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, 0); - if (a1.length != 2) - throw "outer DERSequence shall have 2 elements: " + a1.length; - - var algIdTLV =ASN1HEX.getHexOfTLV_AtObj(pkcs8PubHex, a1[0]); - if (algIdTLV != "300d06092a864886f70d0101010500") // AlgId rsaEncryption - throw "PKCS8 AlgorithmId is not rsaEncryption"; - - if (pkcs8PubHex.substr(a1[1], 2) != "03") - throw "PKCS8 Public Key is not BITSTRING encapslated."; - - var idxPub = ASN1HEX.getStartPosOfV_AtObj(pkcs8PubHex, a1[1]) + 2; // 2 for unused bit - - if (pkcs8PubHex.substr(idxPub, 2) != "30") - throw "PKCS8 Public Key is not SEQUENCE."; - - var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(pkcs8PubHex, idxPub); - if (a2.length != 2) - throw "inner DERSequence shall have 2 elements: " + a2.length; - - if (pkcs8PubHex.substr(a2[0], 2) != "02") - throw "N is not ASN.1 INTEGER"; - if (pkcs8PubHex.substr(a2[1], 2) != "02") - throw "E is not ASN.1 INTEGER"; - - var hN = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[0]); - var hE = ASN1HEX.getHexOfV_AtObj(pkcs8PubHex, a2[1]); - - var pubKey = new RSAKey(); - pubKey.setPublic(hN, hE); - - return pubKey; - }, - - //addAlgorithm: function(functionObject, algName, keyLen, ivLen) { - //} + var key = new RSAKey(); + key.readPKCS8PubKeyHex(pkcs8PubHex); + return key; + }, }; }(); @@ -1433,42 +1352,61 @@ KEYUTIL.getKey = function(param, passcode, hextype) { return ec; } - // 4. by PEM certificate (-----BEGIN ... CERTIFITE----) - if (param.indexOf("-END CERTIFICATE-", 0) != -1 || - param.indexOf("-END X509 CERTIFICATE-", 0) != -1 || - param.indexOf("-END TRUSTED CERTIFICATE-", 0) != -1) { - return X509.getPublicKeyFromCertPEM(param); + // 4. (plain) hexadecimal data + // 4.1. get private key by PKCS#5 plain RSA/DSA/ECDSA hexadecimal string + if (hextype === "pkcs5prv") { + var h = param, _ASN1HEX = ASN1HEX, a, key; + a = _ASN1HEX.getPosArrayOfChildren_AtObj(h, 0); + if (a.length === 9) { // RSA (INT x 9) + key = new RSAKey(); + key.readPrivateKeyFromASN1HexString(param); + } else if (a.length === 6) { // DSA (INT x 6) + key = new KJUR.crypto.DSA(); + key.readPKCS5PrvKeyHex(h); + } else if (a.length > 2 && // ECDSA (INT, OCT prv, [0] curve, [1] pub) + h.substr(a[1], 2) === "04") { + key = new KJUR.crypto.ECDSA(); + key.readPKCS5PrvKeyHex(h); + } else { + throw "unsupported PKCS#1/5 hexadecimal key"; + } + + return key; + } + + // 4.2. get private key by PKCS#8 plain RSA/DSA/ECDSA hexadecimal string + if (hextype === "pkcs8prv") { + var key = KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(param); + return key; } - // 4. public key by PKCS#8 hexadecimal string + // 4.3. get public key by PKCS#8 RSA/DSA/ECDSA hexadecimal string if (hextype === "pkcs8pub") { return KEYUTIL.getKeyFromPublicPKCS8Hex(param); } - // 5. public key by PKCS#8 PEM string - if (param.indexOf("-END PUBLIC KEY-") != -1) { - return KEYUTIL.getKeyFromPublicPKCS8PEM(param); - } - - // 6. private key by PKCS#5 plain hexadecimal RSA string - if (hextype === "pkcs5prv") { - var key = new RSAKey(); - key.readPrivateKeyFromASN1HexString(param); - return key; + // 4.4. get public key by X.509 hexadecimal string for RSA/DSA/ECDSA + if (hextype === "x509pub") { + return X509.getPublicKeyFromCertHex(param); } - // 7. private key by plain PKCS#5 hexadecimal RSA string - if (hextype === "pkcs5prv") { - var key = new RSAKey(); - key.readPrivateKeyFromASN1HexString(param); - return key; + // 5. by PEM certificate (-----BEGIN ... CERTIFICATE----) + if (param.indexOf("-END CERTIFICATE-", 0) != -1 || + param.indexOf("-END X509 CERTIFICATE-", 0) != -1 || + param.indexOf("-END TRUSTED CERTIFICATE-", 0) != -1) { + return X509.getPublicKeyFromCertPEM(param); } - // 8. private key by plain PKCS#5 PEM RSA string + // 6. public key by PKCS#8 PEM string + if (param.indexOf("-END PUBLIC KEY-") != -1) { + return KEYUTIL.getKeyFromPublicPKCS8PEM(param); + } + + // 8.1 private key by plain PKCS#5 PEM RSA string // getKey("-----BEGIN RSA PRIVATE KEY-...") if (param.indexOf("-END RSA PRIVATE KEY-") != -1 && param.indexOf("4,ENCRYPTED") == -1) { - var hex = KEYUTIL.getHexFromPEM(param, "RSA PRIVATE KEY"); + var hex = ASN1HEX.pemToHex(param, "RSA PRIVATE KEY"); return KEYUTIL.getKey(hex, null, "pkcs5prv"); } @@ -1476,7 +1414,7 @@ KEYUTIL.getKey = function(param, passcode, hextype) { if (param.indexOf("-END DSA PRIVATE KEY-") != -1 && param.indexOf("4,ENCRYPTED") == -1) { - var hKey = this.getHexFromPEM(param, "DSA PRIVATE KEY"); + var hKey = ASN1HEX.pemToHex(param, "DSA PRIVATE KEY"); var p = ASN1HEX.getVbyList(hKey, 0, [1], "02"); var q = ASN1HEX.getVbyList(hKey, 0, [2], "02"); var g = ASN1HEX.getVbyList(hKey, 0, [3], "02"); @@ -1491,18 +1429,18 @@ KEYUTIL.getKey = function(param, passcode, hextype) { return key; } - // 9. private key by plain PKCS#8 PEM ECC/RSA string + // 10. private key by plain PKCS#8 PEM ECC/RSA string if (param.indexOf("-END PRIVATE KEY-") != -1) { return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(param); } - // 10. private key by encrypted PKCS#5 PEM RSA string + // 11.1 private key by encrypted PKCS#5 PEM RSA string if (param.indexOf("-END RSA PRIVATE KEY-") != -1 && param.indexOf("4,ENCRYPTED") != -1) { return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(param, passcode); } - // 10.2. private key by encrypted PKCS#5 PEM ECDSA string + // 11.2. private key by encrypted PKCS#5 PEM ECDSA string if (param.indexOf("-END EC PRIVATE KEY-") != -1 && param.indexOf("4,ENCRYPTED") != -1) { var hKey = KEYUTIL.getDecryptedKeyHex(param, passcode); @@ -1518,14 +1456,14 @@ KEYUTIL.getKey = function(param, passcode, hextype) { throw "undefined OID(hex) in KJUR.crypto.OID: " + curveNameOidHex; } - var ec = new KJUR.crypto.ECDSA({'name': curveName}); + var ec = new KJUR.crypto.ECDSA({'curve': curveName}); ec.setPublicKeyHex(pubkey); ec.setPrivateKeyHex(key); ec.isPublic = false; return ec; } - // 10.3. private key by encrypted PKCS#5 PEM DSA string + // 11.3. private key by encrypted PKCS#5 PEM DSA string if (param.indexOf("-END DSA PRIVATE KEY-") != -1 && param.indexOf("4,ENCRYPTED") != -1) { var hKey = KEYUTIL.getDecryptedKeyHex(param, passcode); @@ -1967,7 +1905,7 @@ KEYUTIL.getPEM = function(keyObjOrHex, formatType, passwd, encAlg, hexType) { * @since keyutil 1.0.5 */ KEYUTIL.getKeyFromCSRPEM = function(csrPEM) { - var csrHex = KEYUTIL.getHexFromPEM(csrPEM, "CERTIFICATE REQUEST"); + var csrHex = ASN1HEX.pemToHex(csrPEM, "CERTIFICATE REQUEST"); var key = KEYUTIL.getKeyFromCSRHex(csrHex); return key; }; diff --git a/min/asn1cades-1.0.min.js b/min/asn1cades-1.0.min.js index 38683876..ff352276 100755 --- a/min/asn1cades-1.0.min.js +++ b/min/asn1cades-1.0.min.js @@ -1,3 +1,3 @@ -/*! asn1cades-1.0.0.js (c) 2013-2014 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! asn1cades-1.0.1.js (c) 2014-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}if(typeof KJUR.asn1.cades=="undefined"||!KJUR.asn1.cades){KJUR.asn1.cades={}}KJUR.asn1.cades.SignaturePolicyIdentifier=function(e){KJUR.asn1.cades.SignaturePolicyIdentifier.superclass.constructor.call(this);this.attrTypeOid="1.2.840.113549.1.9.16.2.15";var b=KJUR.asn1;var d=KJUR.asn1.cades;if(typeof e!="undefined"){if(typeof e.oid=="string"&&typeof e.hash=="object"){var f=new b.DERObjectIdentifier({oid:e.oid});var a=new d.OtherHashAlgAndValue(e.hash);var c=new b.DERSequence({array:[f,a]});this.valueList=[c]}}};YAHOO.lang.extend(KJUR.asn1.cades.SignaturePolicyIdentifier,KJUR.asn1.cms.Attribute);KJUR.asn1.cades.OtherHashAlgAndValue=function(b){KJUR.asn1.cades.OtherHashAlgAndValue.superclass.constructor.call(this);var a=KJUR.asn1;var c=KJUR.asn1.x509;this.dAlg=null;this.dHash=null;this.getEncodedHex=function(){var d=new a.DERSequence({array:[this.dAlg,this.dHash]});this.hTLV=d.getEncodedHex();return this.hTLV};if(typeof b!="undefined"){if(typeof b.alg=="string"&&typeof b.hash=="string"){this.dAlg=new c.AlgorithmIdentifier({name:b.alg});this.dHash=new a.DEROctetString({hex:b.hash})}}};YAHOO.lang.extend(KJUR.asn1.cades.OtherHashAlgAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.cades.SignatureTimeStamp=function(c){KJUR.asn1.cades.SignatureTimeStamp.superclass.constructor.call(this);this.attrTypeOid="1.2.840.113549.1.9.16.2.14";this.tstHex=null;var a=KJUR.asn1;if(typeof c!="undefined"){if(typeof c.res!="undefined"){if(typeof c.res=="string"&&c.res.match(/^[0-9A-Fa-f]+$/)){}else{if(c.res instanceof KJUR.asn1.ASN1Object){}else{throw"res param shall be ASN1Object or hex string"}}}if(typeof c.tst!="undefined"){if(typeof c.tst=="string"&&c.tst.match(/^[0-9A-Fa-f]+$/)){var b=new a.ASN1Object();this.tstHex=c.tst;b.hTLV=this.tstHex;b.getEncodedHex();this.valueList=[b]}else{if(c.tst instanceof KJUR.asn1.ASN1Object){}else{throw"tst param shall be ASN1Object or hex string"}}}}};YAHOO.lang.extend(KJUR.asn1.cades.SignatureTimeStamp,KJUR.asn1.cms.Attribute);KJUR.asn1.cades.CompleteCertificateRefs=function(c){KJUR.asn1.cades.CompleteCertificateRefs.superclass.constructor.call(this);this.attrTypeOid="1.2.840.113549.1.9.16.2.21";var a=KJUR.asn1;var b=KJUR.asn1.cades;this.setByArray=function(d){this.valueList=[];for(var e=0;e0){h=new a.DERTaggedObject({obj:this.dUnsignedAttrs,tag:"a1",explicit:false})}var g=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,e,this.dSigAlg,this.dSig,];if(h!=null){g.push(h)}var f=new a.DERSequence({array:g});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.SignerInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.EncapsulatedContentInfo=function(c){KJUR.asn1.cms.EncapsulatedContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dEContentType=new a.DERObjectIdentifier({name:"data"});this.dEContent=null;this.isDetached=false;this.eContentValueHex=null;this.setContentType=function(e){if(e.match(/^[0-2][.][0-9.]+$/)){this.dEContentType=new a.DERObjectIdentifier({oid:e})}else{this.dEContentType=new a.DERObjectIdentifier({name:e})}};this.setContentValue=function(e){if(typeof e!="undefined"){if(typeof e.hex=="string"){this.eContentValueHex=e.hex}else{if(typeof e.str=="string"){this.eContentValueHex=utf8tohex(e.str)}}}};this.setContentValueHex=function(e){this.eContentValueHex=e};this.setContentValueStr=function(e){this.eContentValueHex=utf8tohex(e)};this.getEncodedHex=function(){if(typeof this.eContentValueHex!="string"){throw"eContentValue not yet set"}var g=new a.DEROctetString({hex:this.eContentValueHex});this.dEContent=new a.DERTaggedObject({obj:g,tag:"a0",explicit:true});var e=[this.dEContentType];if(!this.isDetached){e.push(this.dEContent)}var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.EncapsulatedContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentInfo=function(c){KJUR.asn1.cms.ContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dContentType=null;this.dContent=null;this.setContentType=function(e){if(typeof e=="string"){this.dContentType=d.OID.name2obj(e)}};this.getEncodedHex=function(){var f=new a.DERTaggedObject({obj:this.dContent,tag:"a0",explicit:true});var e=new a.DERSequence({array:[this.dContentType,f]});this.hTLV=e.getEncodedHex();return this.hTLV};if(typeof c!="undefined"){if(c.type){this.setContentType(c.type)}if(c.obj&&c.obj instanceof a.ASN1Object){this.dContent=c.obj}}};YAHOO.lang.extend(KJUR.asn1.cms.ContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.SignedData=function(c){KJUR.asn1.cms.SignedData.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dCMSVersion=new a.DERInteger({"int":1});this.dDigestAlgs=null;this.digestAlgNameList=[];this.dEncapContentInfo=new b.EncapsulatedContentInfo();this.dCerts=null;this.certificateList=[];this.crlList=[];this.signerInfoList=[new b.SignerInfo()];this.addCertificatesByPEM=function(e){var f=KEYUTIL.getHexFromPEM(e);var g=new a.ASN1Object();g.hTLV=f;this.certificateList.push(g)};this.getEncodedHex=function(){if(typeof this.hTLV=="string"){return this.hTLV}if(this.dDigestAlgs==null){var k=[];for(var j=0;j0){var l=new a.DERSet({array:this.certificateList});this.dCerts=new a.DERTaggedObject({obj:l,tag:"a0",explicit:false})}}if(this.dCerts!=null){e.push(this.dCerts)}var g=new a.DERSet({array:this.signerInfoList});e.push(g);var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV};this.getContentInfo=function(){this.getEncodedHex();var e=new b.ContentInfo({type:"signed-data",obj:this});return e};this.getContentInfoEncodedHex=function(){var e=this.getContentInfo();var f=e.getEncodedHex();return f};this.getPEM=function(){var e=this.getContentInfoEncodedHex();var f=a.ASN1Util.getPEMStringFromHex(e,"CMS");return f}};YAHOO.lang.extend(KJUR.asn1.cms.SignedData,KJUR.asn1.ASN1Object);KJUR.asn1.cms.CMSUtil=new function(){};KJUR.asn1.cms.CMSUtil.newSignedData=function(a){var h=KJUR.asn1.cms;var g=KJUR.asn1.cades;var f=new h.SignedData();f.dEncapContentInfo.setContentValue(a.content);if(typeof a.certs=="object"){for(var b=0;b0){h=new a.DERTaggedObject({obj:this.dUnsignedAttrs,tag:"a1",explicit:false})}var g=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,e,this.dSigAlg,this.dSig,];if(h!=null){g.push(h)}var f=new a.DERSequence({array:g});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.SignerInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.EncapsulatedContentInfo=function(c){KJUR.asn1.cms.EncapsulatedContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dEContentType=new a.DERObjectIdentifier({name:"data"});this.dEContent=null;this.isDetached=false;this.eContentValueHex=null;this.setContentType=function(e){if(e.match(/^[0-2][.][0-9.]+$/)){this.dEContentType=new a.DERObjectIdentifier({oid:e})}else{this.dEContentType=new a.DERObjectIdentifier({name:e})}};this.setContentValue=function(e){if(typeof e!="undefined"){if(typeof e.hex=="string"){this.eContentValueHex=e.hex}else{if(typeof e.str=="string"){this.eContentValueHex=utf8tohex(e.str)}}}};this.setContentValueHex=function(e){this.eContentValueHex=e};this.setContentValueStr=function(e){this.eContentValueHex=utf8tohex(e)};this.getEncodedHex=function(){if(typeof this.eContentValueHex!="string"){throw"eContentValue not yet set"}var g=new a.DEROctetString({hex:this.eContentValueHex});this.dEContent=new a.DERTaggedObject({obj:g,tag:"a0",explicit:true});var e=[this.dEContentType];if(!this.isDetached){e.push(this.dEContent)}var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.EncapsulatedContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentInfo=function(c){KJUR.asn1.cms.ContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dContentType=null;this.dContent=null;this.setContentType=function(e){if(typeof e=="string"){this.dContentType=d.OID.name2obj(e)}};this.getEncodedHex=function(){var f=new a.DERTaggedObject({obj:this.dContent,tag:"a0",explicit:true});var e=new a.DERSequence({array:[this.dContentType,f]});this.hTLV=e.getEncodedHex();return this.hTLV};if(typeof c!="undefined"){if(c.type){this.setContentType(c.type)}if(c.obj&&c.obj instanceof a.ASN1Object){this.dContent=c.obj}}};YAHOO.lang.extend(KJUR.asn1.cms.ContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.SignedData=function(c){KJUR.asn1.cms.SignedData.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dCMSVersion=new a.DERInteger({"int":1});this.dDigestAlgs=null;this.digestAlgNameList=[];this.dEncapContentInfo=new b.EncapsulatedContentInfo();this.dCerts=null;this.certificateList=[];this.crlList=[];this.signerInfoList=[new b.SignerInfo()];this.addCertificatesByPEM=function(e){var f=ASN1HEX.pemToHex(e);var g=new a.ASN1Object();g.hTLV=f;this.certificateList.push(g)};this.getEncodedHex=function(){if(typeof this.hTLV=="string"){return this.hTLV}if(this.dDigestAlgs==null){var k=[];for(var j=0;j0){var l=new a.DERSet({array:this.certificateList});this.dCerts=new a.DERTaggedObject({obj:l,tag:"a0",explicit:false})}}if(this.dCerts!=null){e.push(this.dCerts)}var g=new a.DERSet({array:this.signerInfoList});e.push(g);var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV};this.getContentInfo=function(){this.getEncodedHex();var e=new b.ContentInfo({type:"signed-data",obj:this});return e};this.getContentInfoEncodedHex=function(){var e=this.getContentInfo();var f=e.getEncodedHex();return f};this.getPEM=function(){var e=this.getContentInfoEncodedHex();var f=a.ASN1Util.getPEMStringFromHex(e,"CMS");return f}};YAHOO.lang.extend(KJUR.asn1.cms.SignedData,KJUR.asn1.ASN1Object);KJUR.asn1.cms.CMSUtil=new function(){};KJUR.asn1.cms.CMSUtil.newSignedData=function(a){var h=KJUR.asn1.cms;var g=KJUR.asn1.cades;var f=new h.SignedData();f.dEncapContentInfo.setContentValue(a.content);if(typeof a.certs=="object"){for(var b=0;b0){var e=new KJUR.asn1.DERSequence({array:this.extensionsArray});var d=new KJUR.asn1.DERSet({array:[e]});var c=new KJUR.asn1.DERSequence({array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.9.14"}),d]});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a0",obj:c});this.asn1Array.push(b)}else{var b=new KJUR.asn1.DERTaggedObject({explicit:false,tag:"a0",obj:new KJUR.asn1.DERNull()});this.asn1Array.push(b)}var f=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=f.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.csr.CertificationRequestInfo,KJUR.asn1.ASN1Object);KJUR.asn1.csr.CSRUtil=new function(){};KJUR.asn1.csr.CSRUtil.newCSRPEM=function(g){var d=KJUR.asn1.csr;if(g.subject===undefined){throw"parameter subject undefined"}if(g.sbjpubkey===undefined){throw"parameter sbjpubkey undefined"}if(g.sigalg===undefined){throw"parameter sigalg undefined"}if(g.sbjprvkey===undefined){throw"parameter sbjpubkey undefined"}var b=new d.CertificationRequestInfo();b.setSubjectByParam(g.subject);b.setSubjectPublicKeyByGetKey(g.sbjpubkey);if(g.ext!==undefined&&g.ext.length!==undefined){for(var c=0;c0){var e=new KJUR.asn1.DERSequence({array:this.extensionsArray});var d=new KJUR.asn1.DERSet({array:[e]});var c=new KJUR.asn1.DERSequence({array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.9.14"}),d]});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a0",obj:c});this.asn1Array.push(b)}else{var b=new KJUR.asn1.DERTaggedObject({explicit:false,tag:"a0",obj:new KJUR.asn1.DERNull()});this.asn1Array.push(b)}var f=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=f.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.csr.CertificationRequestInfo,KJUR.asn1.ASN1Object);KJUR.asn1.csr.CSRUtil=new function(){};KJUR.asn1.csr.CSRUtil.newCSRPEM=function(g){var d=KJUR.asn1.csr;if(g.subject===undefined){throw"parameter subject undefined"}if(g.sbjpubkey===undefined){throw"parameter sbjpubkey undefined"}if(g.sigalg===undefined){throw"parameter sigalg undefined"}if(g.sbjprvkey===undefined){throw"parameter sbjpubkey undefined"}var b=new d.CertificationRequestInfo();b.setSubjectByParam(g.subject);b.setSubjectPublicKeyByGetKey(g.sbjpubkey);if(g.ext!==undefined&&g.ext.length!==undefined){for(var c=0;c=(b*2))){break}if(d>=200){break}c.push(e);g=e;d++}return c};ASN1HEX.getNthChildIndex_AtObj=function(d,b,e){var c=ASN1HEX.getPosArrayOfChildren_AtObj(d,b);return c[e]};ASN1HEX.getDecendantIndexByNthList=function(e,d,c){if(c.length==0){return d}var f=c.shift();var b=ASN1HEX.getPosArrayOfChildren_AtObj(e,d);return ASN1HEX.getDecendantIndexByNthList(e,b[f],c)};ASN1HEX.getDecendantHexTLVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfTLV_AtObj(d,a)};ASN1HEX.getDecendantHexVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.getVbyList=function(d,c,b,e){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);if(a===undefined){throw"can't find nthList object"}if(e!==undefined){if(d.substr(a,2)!=e){throw"checking tag doesn't match: "+d.substr(a,2)+"!="+e}}return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(q,c,k,g){var e=q;if(q instanceof KJUR.asn1.ASN1Object){e=q.getEncodedHex()}var o=function(x,i){if(x.length<=i*2){return x}else{var v=x.substr(0,i)+"..(total "+x.length/2+"bytes).."+x.substr(x.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(k===undefined){k=0}if(g===undefined){g=""}var t=c.ommit_long_octet;if(e.substr(k,2)=="01"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(e.substr(k,2)=="02"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"INTEGER "+o(h,t)+"\n"}if(e.substr(k,2)=="03"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"BITSTRING "+o(h,t)+"\n"}if(e.substr(k,2)=="04"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(ASN1HEX.isASN1HEX(h)){var j=g+"OCTETSTRING, encapsulates\n";j=j+ASN1HEX.dump(h,c,0,g+" ");return j}else{return g+"OCTETSTRING "+o(h,t)+"\n"}}if(e.substr(k,2)=="05"){return g+"NULL\n"}if(e.substr(k,2)=="06"){var l=ASN1HEX.getHexOfV_AtObj(e,k);var a=KJUR.asn1.ASN1Util.oidHexToInt(l);var n=KJUR.asn1.x509.OID.oid2name(a);var b=a.replace(/\./g," ");if(n!=""){return g+"ObjectIdentifier "+n+" ("+b+")\n"}else{return g+"ObjectIdentifier ("+b+")\n"}}if(e.substr(k,2)=="0c"){return g+"UTF8String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="13"){return g+"PrintableString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="14"){return g+"TeletexString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="16"){return g+"IA5String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="17"){return g+"UTCTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="18"){return g+"GeneralizedTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="30"){if(e.substr(k,4)=="3000"){return g+"SEQUENCE {}\n"}var j=g+"SEQUENCE\n";var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,k);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var u=ASN1HEX.getHexOfV_AtObj(e,d[0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(u);var n=KJUR.asn1.x509.OID.oid2name(a);var p=JSON.parse(JSON.stringify(c));p.x509ExtName=n;f=p}for(var r=0;r=(b*2))){break}if(d>=200){break}c.push(e);g=e;d++}return c};ASN1HEX.getNthChildIndex_AtObj=function(d,b,e){var c=ASN1HEX.getPosArrayOfChildren_AtObj(d,b);return c[e]};ASN1HEX.getDecendantIndexByNthList=function(e,d,c){if(c.length==0){return d}var f=c.shift();var b=ASN1HEX.getPosArrayOfChildren_AtObj(e,d);return ASN1HEX.getDecendantIndexByNthList(e,b[f],c)};ASN1HEX.getDecendantHexTLVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfTLV_AtObj(d,a)};ASN1HEX.getDecendantHexVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.getVbyList=function(d,c,b,e){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);if(a===undefined){throw"can't find nthList object"}if(e!==undefined){if(d.substr(a,2)!=e){throw"checking tag doesn't match: "+d.substr(a,2)+"!="+e}}return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(q,c,k,g){var e=q;if(q instanceof KJUR.asn1.ASN1Object){e=q.getEncodedHex()}var o=function(x,i){if(x.length<=i*2){return x}else{var v=x.substr(0,i)+"..(total "+x.length/2+"bytes).."+x.substr(x.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(k===undefined){k=0}if(g===undefined){g=""}var t=c.ommit_long_octet;if(e.substr(k,2)=="01"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(e.substr(k,2)=="02"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"INTEGER "+o(h,t)+"\n"}if(e.substr(k,2)=="03"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"BITSTRING "+o(h,t)+"\n"}if(e.substr(k,2)=="04"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(ASN1HEX.isASN1HEX(h)){var j=g+"OCTETSTRING, encapsulates\n";j=j+ASN1HEX.dump(h,c,0,g+" ");return j}else{return g+"OCTETSTRING "+o(h,t)+"\n"}}if(e.substr(k,2)=="05"){return g+"NULL\n"}if(e.substr(k,2)=="06"){var l=ASN1HEX.getHexOfV_AtObj(e,k);var a=KJUR.asn1.ASN1Util.oidHexToInt(l);var n=KJUR.asn1.x509.OID.oid2name(a);var b=a.replace(/\./g," ");if(n!=""){return g+"ObjectIdentifier "+n+" ("+b+")\n"}else{return g+"ObjectIdentifier ("+b+")\n"}}if(e.substr(k,2)=="0c"){return g+"UTF8String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="13"){return g+"PrintableString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="14"){return g+"TeletexString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="16"){return g+"IA5String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="17"){return g+"UTCTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="18"){return g+"GeneralizedTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="30"){if(e.substr(k,4)=="3000"){return g+"SEQUENCE {}\n"}var j=g+"SEQUENCE\n";var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,k);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var u=ASN1HEX.getHexOfV_AtObj(e,d[0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(u);var n=KJUR.asn1.x509.OID.oid2name(a);var p=JSON.parse(JSON.stringify(c));p.x509ExtName=n;f=p}for(var r=0;r0){var d=new KJUR.asn1.DERSequence({array:this.extensionsArray});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a3",obj:d});this.asn1Array.push(b)}var e=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=e.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension=function(b){KJUR.asn1.x509.Extension.superclass.constructor.call(this);var a=null;this.getEncodedHex=function(){var f=new KJUR.asn1.DERObjectIdentifier({oid:this.oid});var e=new KJUR.asn1.DEROctetString({hex:this.getExtnValueHex()});var d=new Array();d.push(f);if(this.critical){d.push(new KJUR.asn1.DERBoolean())}d.push(e);var c=new KJUR.asn1.DERSequence({array:d});return c.getEncodedHex()};this.critical=false;if(typeof b!="undefined"){if(typeof b.critical!="undefined"){this.critical=b.critical}}};YAHOO.lang.extend(KJUR.asn1.x509.Extension,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension.appendByNameToArray=function(e,c,b){if(e.toLowerCase()=="basicconstraints"){var d=new KJUR.asn1.x509.BasicConstraints(c);b.push(d)}else{if(e.toLowerCase()=="keyusage"){var d=new KJUR.asn1.x509.KeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="crldistributionpoints"){var d=new KJUR.asn1.x509.CRLDistributionPoints(c);b.push(d)}else{if(e.toLowerCase()=="extkeyusage"){var d=new KJUR.asn1.x509.ExtKeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="authoritykeyidentifier"){var d=new KJUR.asn1.x509.AuthorityKeyIdentifier(c);b.push(d)}else{if(e.toLowerCase()=="authorityinfoaccess"){var d=new KJUR.asn1.x509.AuthorityInfoAccess(c);b.push(d)}else{if(e.toLowerCase()=="subjectaltname"){var d=new KJUR.asn1.x509.SubjectAltName(c);b.push(d)}else{if(e.toLowerCase()=="issueraltname"){var d=new KJUR.asn1.x509.IssuerAltName(c);b.push(d)}else{throw"unsupported extension name: "+e}}}}}}}}};KJUR.asn1.x509.KeyUsage=function(a){KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.15";if(typeof a!="undefined"){if(typeof a.bin!="undefined"){this.asn1ExtnValue=new KJUR.asn1.DERBitString(a)}}};YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage,KJUR.asn1.x509.Extension);KJUR.asn1.x509.BasicConstraints=function(c){KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this,c);var a=false;var b=-1;this.getExtnValueHex=function(){var e=new Array();if(this.cA){e.push(new KJUR.asn1.DERBoolean())}if(this.pathLen>-1){e.push(new KJUR.asn1.DERInteger({"int":this.pathLen}))}var d=new KJUR.asn1.DERSequence({array:e});this.asn1ExtnValue=d;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(typeof c!="undefined"){if(typeof c.cA!="undefined"){this.cA=c.cA}if(typeof c.pathLen!="undefined"){this.pathLen=c.pathLen}}};YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(a){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence({array:b})};this.setByOneURI=function(e){var b=new KJUR.asn1.x509.GeneralNames([{uri:e}]);var d=new KJUR.asn1.x509.DistributionPointName(b);var c=new KJUR.asn1.x509.DistributionPoint({dpobj:d});this.setByDPArray([c])};this.oid="2.5.29.31";if(typeof a!="undefined"){if(typeof a.array!="undefined"){this.setByDPArray(a.array)}else{if(typeof a.uri!="undefined"){this.setByOneURI(a.uri)}}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.ExtKeyUsage=function(a){KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,a);this.setPurposeArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence();for(var c=0;c0){var c=new KJUR.asn1.DERSequence({array:this.aRevokedCert});this.asn1Array.push(c)}var d=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=d.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize=function(){this.asn1Version=null;this.asn1SignatureAlg=null;this.asn1Issuer=null;this.asn1ThisUpdate=null;this.asn1NextUpdate=null;this.aRevokedCert=new Array()};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList,KJUR.asn1.ASN1Object);KJUR.asn1.x509.CRLEntry=function(c){KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this);var b=null;var a=null;this.setCertSerial=function(d){this.sn=new KJUR.asn1.DERInteger(d)};this.setRevocationDate=function(d){this.time=new KJUR.asn1.x509.Time(d)};this.getEncodedHex=function(){var d=new KJUR.asn1.DERSequence({array:[this.sn,this.time]});this.TLV=d.getEncodedHex();return this.TLV};if(typeof c!="undefined"){if(typeof c.time!="undefined"){this.setRevocationDate(c.time)}if(typeof c.sn!="undefined"){this.setCertSerial(c.sn)}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry,KJUR.asn1.ASN1Object);KJUR.asn1.x509.X500Name=function(b){KJUR.asn1.x509.X500Name.superclass.constructor.call(this);this.asn1Array=new Array();this.setByString=function(c){var d=c.split("/");d.shift();for(var e=0;e0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.RDN=function(a){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=new Array();this.addByString=function(b){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:b}))};this.addByMultiValuedString=function(d){var b=KJUR.asn1.x509.RDN.parseString(d);for(var c=0;c0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(b){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var d=null;var c=null;var a="utf8";this.setByString=function(f){var e=f.match(/^([^=]+)=(.+)$/);if(e){this.setByAttrTypeAndValueStr(e[1],e[2])}else{throw"malformed attrTypeAndValueStr: "+f}};this.setByAttrTypeAndValueStr=function(g,f){this.typeObj=KJUR.asn1.x509.OID.atype2obj(g);var e=a;if(g=="C"){e="prn"}this.valueObj=this.getValueObj(e,f)};this.getValueObj=function(f,e){if(f=="utf8"){return new KJUR.asn1.DERUTF8String({str:e})}if(f=="prn"){return new KJUR.asn1.DERPrintableString({str:e})}if(f=="tel"){return new KJUR.asn1.DERTeletexString({str:e})}if(f=="ia5"){return new KJUR.asn1.DERIA5String({str:e})}throw"unsupported directory string type: type="+f+" value="+e};this.getEncodedHex=function(){var e=new KJUR.asn1.DERSequence({array:[this.typeObj,this.valueObj]});this.TLV=e.getEncodedHex();return this.TLV};if(typeof b!="undefined"){if(typeof b.str!="undefined"){this.setByString(b.str)}}};YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(d){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var b=null;var c=null;var a=null;this.setRSAKey=function(e){if(!RSAKey.prototype.isPrototypeOf(e)){throw"argument is not RSAKey instance"}this.rsaKey=e;var g=new KJUR.asn1.DERInteger({bigint:e.n});var f=new KJUR.asn1.DERInteger({"int":e.e});var i=new KJUR.asn1.DERSequence({array:[g,f]});var h=i.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+h})};this.setRSAPEM=function(g){if(g.match(/-----BEGIN PUBLIC KEY-----/)){var n=g;n=n.replace(/^-----[^-]+-----/,"");n=n.replace(/-----[^-]+-----\s*$/,"");var m=n.replace(/\s+/g,"");var f=CryptoJS.enc.Base64.parse(m);var i=CryptoJS.enc.Hex.stringify(f);var k=_rsapem_getHexValueArrayOfChildrenFromHex(i);var h=k[1];var l=h.substr(2);var e=_rsapem_getHexValueArrayOfChildrenFromHex(l);var j=new RSAKey();j.setPublic(e[0],e[1]);this.setRSAKey(j)}else{throw"key not supported"}};this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var e=new KJUR.asn1.DERSequence({array:[this.asn1AlgId,this.asn1SubjPKey]});return e};this.getEncodedHex=function(){var e=this.getASN1Object();this.hTLV=e.getEncodedHex();return this.hTLV};this._setRSAKey=function(e){var g=KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.n}},{"int":{"int":e.e}}]});var f=g.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+f})};this._setEC=function(e){var f=new KJUR.asn1.DERObjectIdentifier({name:e.curveName});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"ecPublicKey",asn1params:f});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+e.pubKeyHex})};this._setDSA=function(e){var f=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.p}},{"int":{bigint:e.q}},{"int":{bigint:e.g}}]});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"dsa",asn1params:f});var g=new KJUR.asn1.DERInteger({bigint:e.y});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+g.getEncodedHex()})};if(typeof d!="undefined"){if(typeof RSAKey!="undefined"&&d instanceof RSAKey){this._setRSAKey(d)}else{if(typeof KJUR.crypto.ECDSA!="undefined"&&d instanceof KJUR.crypto.ECDSA){this._setEC(d)}else{if(typeof KJUR.crypto.DSA!="undefined"&&d instanceof KJUR.crypto.DSA){this._setDSA(d)}else{if(typeof d.rsakey!="undefined"){this.setRSAKey(d.rsakey)}else{if(typeof d.rsapem!="undefined"){this.setRSAPEM(d.rsapem)}}}}}}};YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(c){KJUR.asn1.x509.Time.superclass.constructor.call(this);var b=null;var a=null;this.setTimeParams=function(d){this.timeParams=d};this.getEncodedHex=function(){var d=null;if(this.timeParams!=null){if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime(this.timeParams)}else{d=new KJUR.asn1.DERGeneralizedTime(this.timeParams)}}else{if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime()}else{d=new KJUR.asn1.DERGeneralizedTime()}}this.TLV=d.getEncodedHex();return this.TLV};this.type="utc";if(typeof c!="undefined"){if(typeof c.type!="undefined"){this.type=c.type}else{if(typeof c.str!="undefined"){if(c.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(c.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=c}};YAHOO.lang.extend(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);var a=null;var d=null;var b=null;var c=false;this.getEncodedHex=function(){if(this.nameAlg==null&&this.asn1Alg==null){throw"algorithm not specified"}if(this.nameAlg!=null&&this.asn1Alg==null){this.asn1Alg=KJUR.asn1.x509.OID.name2obj(this.nameAlg)}var f=[this.asn1Alg];if(!this.paramEmpty){f.push(this.asn1Params)}var g=new KJUR.asn1.DERSequence({array:f});this.hTLV=g.getEncodedHex();return this.hTLV};if(typeof e!="undefined"){if(typeof e.name!="undefined"){this.nameAlg=e.name}if(typeof e.asn1params!="undefined"){this.asn1Params=e.asn1params}if(typeof e.paramempty!="undefined"){this.paramEmpty=e.paramempty}}if(this.asn1Params==null){this.asn1Params=new KJUR.asn1.DERNull()}};YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralName=function(d){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var c=null;var b=null;var a={rfc822:"81",dns:"82",dn:"a4",uri:"86"};this.explicit=false;this.setByParam=function(k){var j=null;var g=null;if(k===undefined){return}if(k.rfc822!==undefined){this.type="rfc822";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dns!==undefined){this.type="dns";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.uri!==undefined){this.type="uri";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({str:k.dn})}if(k.ldapdn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({ldapstr:k.ldapdn})}if(k.certissuer!==undefined){this.type="dn";this.explicit=true;var h=k.certissuer;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=X509.pemToHex(h)}if(f==null){throw"certissuer param not cert"}var e=new X509();e.hex=f;var i=e.getIssuerHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(k.certsubj!==undefined){this.type="dn";this.explicit=true;var h=k.certsubj;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=X509.pemToHex(h)}if(f==null){throw"certsubj param not cert"}var e=new X509();e.hex=f;var i=e.getSubjectHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(this.type==null){throw"unsupported type in params="+k}this.asn1Obj=new KJUR.asn1.DERTaggedObject({explicit:this.explicit,tag:a[this.type],obj:g})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(d!==undefined){this.setByParam(d)}};YAHOO.lang.extend(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(b){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null;this.setByParamArray=function(e){for(var c=0;c0){var d=new KJUR.asn1.DERSequence({array:this.extensionsArray});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a3",obj:d});this.asn1Array.push(b)}var e=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=e.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension=function(b){KJUR.asn1.x509.Extension.superclass.constructor.call(this);var a=null;this.getEncodedHex=function(){var f=new KJUR.asn1.DERObjectIdentifier({oid:this.oid});var e=new KJUR.asn1.DEROctetString({hex:this.getExtnValueHex()});var d=new Array();d.push(f);if(this.critical){d.push(new KJUR.asn1.DERBoolean())}d.push(e);var c=new KJUR.asn1.DERSequence({array:d});return c.getEncodedHex()};this.critical=false;if(typeof b!="undefined"){if(typeof b.critical!="undefined"){this.critical=b.critical}}};YAHOO.lang.extend(KJUR.asn1.x509.Extension,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension.appendByNameToArray=function(e,c,b){if(e.toLowerCase()=="basicconstraints"){var d=new KJUR.asn1.x509.BasicConstraints(c);b.push(d)}else{if(e.toLowerCase()=="keyusage"){var d=new KJUR.asn1.x509.KeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="crldistributionpoints"){var d=new KJUR.asn1.x509.CRLDistributionPoints(c);b.push(d)}else{if(e.toLowerCase()=="extkeyusage"){var d=new KJUR.asn1.x509.ExtKeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="authoritykeyidentifier"){var d=new KJUR.asn1.x509.AuthorityKeyIdentifier(c);b.push(d)}else{if(e.toLowerCase()=="authorityinfoaccess"){var d=new KJUR.asn1.x509.AuthorityInfoAccess(c);b.push(d)}else{if(e.toLowerCase()=="subjectaltname"){var d=new KJUR.asn1.x509.SubjectAltName(c);b.push(d)}else{if(e.toLowerCase()=="issueraltname"){var d=new KJUR.asn1.x509.IssuerAltName(c);b.push(d)}else{throw"unsupported extension name: "+e}}}}}}}}};KJUR.asn1.x509.KeyUsage=function(a){KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.15";if(typeof a!="undefined"){if(typeof a.bin!="undefined"){this.asn1ExtnValue=new KJUR.asn1.DERBitString(a)}}};YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage,KJUR.asn1.x509.Extension);KJUR.asn1.x509.BasicConstraints=function(c){KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this,c);var a=false;var b=-1;this.getExtnValueHex=function(){var e=new Array();if(this.cA){e.push(new KJUR.asn1.DERBoolean())}if(this.pathLen>-1){e.push(new KJUR.asn1.DERInteger({"int":this.pathLen}))}var d=new KJUR.asn1.DERSequence({array:e});this.asn1ExtnValue=d;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(typeof c!="undefined"){if(typeof c.cA!="undefined"){this.cA=c.cA}if(typeof c.pathLen!="undefined"){this.pathLen=c.pathLen}}};YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(a){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence({array:b})};this.setByOneURI=function(e){var b=new KJUR.asn1.x509.GeneralNames([{uri:e}]);var d=new KJUR.asn1.x509.DistributionPointName(b);var c=new KJUR.asn1.x509.DistributionPoint({dpobj:d});this.setByDPArray([c])};this.oid="2.5.29.31";if(typeof a!="undefined"){if(typeof a.array!="undefined"){this.setByDPArray(a.array)}else{if(typeof a.uri!="undefined"){this.setByOneURI(a.uri)}}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.ExtKeyUsage=function(a){KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,a);this.setPurposeArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence();for(var c=0;c0){var c=new KJUR.asn1.DERSequence({array:this.aRevokedCert});this.asn1Array.push(c)}var d=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=d.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize=function(){this.asn1Version=null;this.asn1SignatureAlg=null;this.asn1Issuer=null;this.asn1ThisUpdate=null;this.asn1NextUpdate=null;this.aRevokedCert=new Array()};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList,KJUR.asn1.ASN1Object);KJUR.asn1.x509.CRLEntry=function(c){KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this);var b=null;var a=null;this.setCertSerial=function(d){this.sn=new KJUR.asn1.DERInteger(d)};this.setRevocationDate=function(d){this.time=new KJUR.asn1.x509.Time(d)};this.getEncodedHex=function(){var d=new KJUR.asn1.DERSequence({array:[this.sn,this.time]});this.TLV=d.getEncodedHex();return this.TLV};if(typeof c!="undefined"){if(typeof c.time!="undefined"){this.setRevocationDate(c.time)}if(typeof c.sn!="undefined"){this.setCertSerial(c.sn)}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry,KJUR.asn1.ASN1Object);KJUR.asn1.x509.X500Name=function(b){KJUR.asn1.x509.X500Name.superclass.constructor.call(this);this.asn1Array=new Array();this.setByString=function(c){var d=c.split("/");d.shift();for(var e=0;e0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.RDN=function(a){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=new Array();this.addByString=function(b){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:b}))};this.addByMultiValuedString=function(d){var b=KJUR.asn1.x509.RDN.parseString(d);for(var c=0;c0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(b){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var d=null;var c=null;var a="utf8";this.setByString=function(f){var e=f.match(/^([^=]+)=(.+)$/);if(e){this.setByAttrTypeAndValueStr(e[1],e[2])}else{throw"malformed attrTypeAndValueStr: "+f}};this.setByAttrTypeAndValueStr=function(g,f){this.typeObj=KJUR.asn1.x509.OID.atype2obj(g);var e=a;if(g=="C"){e="prn"}this.valueObj=this.getValueObj(e,f)};this.getValueObj=function(f,e){if(f=="utf8"){return new KJUR.asn1.DERUTF8String({str:e})}if(f=="prn"){return new KJUR.asn1.DERPrintableString({str:e})}if(f=="tel"){return new KJUR.asn1.DERTeletexString({str:e})}if(f=="ia5"){return new KJUR.asn1.DERIA5String({str:e})}throw"unsupported directory string type: type="+f+" value="+e};this.getEncodedHex=function(){var e=new KJUR.asn1.DERSequence({array:[this.typeObj,this.valueObj]});this.TLV=e.getEncodedHex();return this.TLV};if(typeof b!="undefined"){if(typeof b.str!="undefined"){this.setByString(b.str)}}};YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(d){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var b=null;var c=null;var a=null;this.setRSAKey=function(e){if(!RSAKey.prototype.isPrototypeOf(e)){throw"argument is not RSAKey instance"}this.rsaKey=e;var g=new KJUR.asn1.DERInteger({bigint:e.n});var f=new KJUR.asn1.DERInteger({"int":e.e});var i=new KJUR.asn1.DERSequence({array:[g,f]});var h=i.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+h})};this.setRSAPEM=function(g){if(g.match(/-----BEGIN PUBLIC KEY-----/)){var n=g;n=n.replace(/^-----[^-]+-----/,"");n=n.replace(/-----[^-]+-----\s*$/,"");var m=n.replace(/\s+/g,"");var f=CryptoJS.enc.Base64.parse(m);var i=CryptoJS.enc.Hex.stringify(f);var k=RSAKey.getHexValueArrayOfChildrenFromHex(i);var h=k[1];var l=h.substr(2);var e=RSAKey.getHexValueArrayOfChildrenFromHex(l);var j=new RSAKey();j.setPublic(e[0],e[1]);this.setRSAKey(j)}else{throw"key not supported"}};this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var e=new KJUR.asn1.DERSequence({array:[this.asn1AlgId,this.asn1SubjPKey]});return e};this.getEncodedHex=function(){var e=this.getASN1Object();this.hTLV=e.getEncodedHex();return this.hTLV};this._setRSAKey=function(e){var g=KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.n}},{"int":{"int":e.e}}]});var f=g.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+f})};this._setEC=function(e){var f=new KJUR.asn1.DERObjectIdentifier({name:e.curveName});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"ecPublicKey",asn1params:f});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+e.pubKeyHex})};this._setDSA=function(e){var f=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.p}},{"int":{bigint:e.q}},{"int":{bigint:e.g}}]});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"dsa",asn1params:f});var g=new KJUR.asn1.DERInteger({bigint:e.y});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+g.getEncodedHex()})};if(typeof d!="undefined"){if(typeof RSAKey!="undefined"&&d instanceof RSAKey){this._setRSAKey(d)}else{if(typeof KJUR.crypto.ECDSA!="undefined"&&d instanceof KJUR.crypto.ECDSA){this._setEC(d)}else{if(typeof KJUR.crypto.DSA!="undefined"&&d instanceof KJUR.crypto.DSA){this._setDSA(d)}else{if(typeof d.rsakey!="undefined"){this.setRSAKey(d.rsakey)}else{if(typeof d.rsapem!="undefined"){this.setRSAPEM(d.rsapem)}}}}}}};YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(c){KJUR.asn1.x509.Time.superclass.constructor.call(this);var b=null;var a=null;this.setTimeParams=function(d){this.timeParams=d};this.getEncodedHex=function(){var d=null;if(this.timeParams!=null){if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime(this.timeParams)}else{d=new KJUR.asn1.DERGeneralizedTime(this.timeParams)}}else{if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime()}else{d=new KJUR.asn1.DERGeneralizedTime()}}this.TLV=d.getEncodedHex();return this.TLV};this.type="utc";if(typeof c!="undefined"){if(typeof c.type!="undefined"){this.type=c.type}else{if(typeof c.str!="undefined"){if(c.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(c.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=c}};YAHOO.lang.extend(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);var a=null;var d=null;var b=null;var c=false;this.getEncodedHex=function(){if(this.nameAlg==null&&this.asn1Alg==null){throw"algorithm not specified"}if(this.nameAlg!=null&&this.asn1Alg==null){this.asn1Alg=KJUR.asn1.x509.OID.name2obj(this.nameAlg)}var f=[this.asn1Alg];if(!this.paramEmpty){f.push(this.asn1Params)}var g=new KJUR.asn1.DERSequence({array:f});this.hTLV=g.getEncodedHex();return this.hTLV};if(typeof e!="undefined"){if(typeof e.name!="undefined"){this.nameAlg=e.name}if(typeof e.asn1params!="undefined"){this.asn1Params=e.asn1params}if(typeof e.paramempty!="undefined"){this.paramEmpty=e.paramempty}}if(this.asn1Params==null){this.asn1Params=new KJUR.asn1.DERNull()}};YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralName=function(d){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var c=null;var b=null;var a={rfc822:"81",dns:"82",dn:"a4",uri:"86"};this.explicit=false;this.setByParam=function(k){var j=null;var g=null;if(k===undefined){return}if(k.rfc822!==undefined){this.type="rfc822";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dns!==undefined){this.type="dns";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.uri!==undefined){this.type="uri";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({str:k.dn})}if(k.ldapdn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({ldapstr:k.ldapdn})}if(k.certissuer!==undefined){this.type="dn";this.explicit=true;var h=k.certissuer;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=ASN1HEX.pemToHex(h)}if(f==null){throw"certissuer param not cert"}var e=new X509();e.hex=f;var i=e.getIssuerHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(k.certsubj!==undefined){this.type="dn";this.explicit=true;var h=k.certsubj;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=ASN1HEX.pemToHex(h)}if(f==null){throw"certsubj param not cert"}var e=new X509();e.hex=f;var i=e.getSubjectHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(this.type==null){throw"unsupported type in params="+k}this.asn1Obj=new KJUR.asn1.DERTaggedObject({explicit:this.explicit,tag:a[this.type],obj:g})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(d!==undefined){this.setByParam(d)}};YAHOO.lang.extend(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(b){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null;this.setByParamArray=function(e){for(var c=0;c0||a.compareTo(b)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(t)>0||t.compareTo(b)>0){throw"invalid DSA signature"}var m=t.modInverse(b);var e=k.multiply(m).mod(b);var c=a.multiply(m).mod(b);var n=j.modPow(e,d).multiply(l.modPow(c,d)).mod(d).mod(b);return n.compareTo(a)==0};this.parseASN1Signature=function(a){try{var d=new BigInteger(ASN1HEX.getVbyList(a,0,[0],"02"),16);var c=new BigInteger(ASN1HEX.getVbyList(a,0,[1],"02"),16);return[d,c]}catch(b){throw"malformed ASN.1 DSA signature"}}}; \ No newline at end of file +if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.DSA=function(){this.p=null;this.q=null;this.g=null;this.y=null;this.x=null;this.type="DSA";this.isPrivate=false;this.isPublic=false;this.setPrivate=function(d,c,b,e,a){this.isPrivate=true;this.p=d;this.q=c;this.g=b;this.y=e;this.x=a};this.setPrivateHex=function(d,b,f,i,j){var c,a,e,g,h;c=new BigInteger(d,16);a=new BigInteger(b,16);e=new BigInteger(f,16);if(typeof i==="string"&&i.length>1){g=new BigInteger(i,16)}else{g=null}h=new BigInteger(j,16);this.setPrivate(c,a,e,g,h)};this.setPublic=function(c,b,a,d){this.isPublic=true;this.p=c;this.q=b;this.g=a;this.y=d;this.x=null};this.setPublicHex=function(f,e,d,g){var b,a,h,c;b=new BigInteger(f,16);a=new BigInteger(e,16);h=new BigInteger(d,16);c=new BigInteger(g,16);this.setPublic(b,a,h,c)};this.signWithMessageHash=function(d){var c=this.p;var b=this.q;var f=this.g;var i=this.y;var j=this.x;var e=KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE),b.subtract(BigInteger.ONE));var l=d.substr(0,b.bitLength()/4);var h=new BigInteger(l,16);var a=(f.modPow(e,c)).mod(b);var n=(e.modInverse(b).multiply(h.add(j.multiply(a)))).mod(b);var m=KJUR.asn1.ASN1Util.jsonToASN1HEX({seq:[{"int":{bigint:a}},{"int":{bigint:n}}]});return m};this.verifyWithMessageHash=function(h,f){var d=this.p;var b=this.q;var j=this.g;var l=this.y;var i=this.parseASN1Signature(f);var a=i[0];var t=i[1];var o=h.substr(0,b.bitLength()/4);var k=new BigInteger(o,16);if(BigInteger.ZERO.compareTo(a)>0||a.compareTo(b)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(t)>0||t.compareTo(b)>0){throw"invalid DSA signature"}var m=t.modInverse(b);var e=k.multiply(m).mod(b);var c=a.multiply(m).mod(b);var n=j.modPow(e,d).multiply(l.modPow(c,d)).mod(d).mod(b);return n.compareTo(a)==0};this.parseASN1Signature=function(a){try{var d=new BigInteger(ASN1HEX.getVbyList(a,0,[0],"02"),16);var c=new BigInteger(ASN1HEX.getVbyList(a,0,[1],"02"),16);return[d,c]}catch(b){throw"malformed ASN.1 DSA signature"}};this.readPKCS5PrvKeyHex=function(c){var b,a,f,g,i;var j=ASN1HEX;var d=j.getVbyList;if(j.isASN1HEX(c)===false){throw"not ASN.1 hex string"}try{b=d(c,0,[1],"02");a=d(c,0,[2],"02");f=d(c,0,[3],"02");g=d(c,0,[4],"02");i=d(c,0,[5],"02")}catch(e){console.log("EXCEPTION:"+e);throw"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(b,a,f,g,i)};this.readPKCS8PrvKeyHex=function(d){var f,c,b,g;var e=ASN1HEX;var i=e.getVbyList;if(e.isASN1HEX(d)===false){throw"not ASN.1 hex string"}try{f=i(d,0,[1,1,0],"02");c=i(d,0,[1,1,1],"02");b=i(d,0,[1,1,2],"02");g=i(d,0,[2,0],"02")}catch(a){console.log("EXCEPTION:"+a);throw"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(f,c,b,null,g)};this.readPKCS8PubKeyHex=function(d){var f,c,b,g;var e=ASN1HEX;var i=e.getVbyList;if(e.isASN1HEX(d)===false){throw"not ASN.1 hex string"}try{f=i(d,0,[0,1,0],"02");c=i(d,0,[0,1,1],"02");b=i(d,0,[0,1,2],"02");g=i(d,0,[1,0],"02")}catch(a){console.log("EXCEPTION:"+a);throw"malformed PKCS#8 DSA public key"}this.setPublicHex(f,c,b,g)};this.readCertPubKeyHex=function(c,f){if(f!==5){f=6}var b,a,g,i;var j=ASN1HEX;var d=j.getVbyList;if(j.isASN1HEX(c)===false){throw"not ASN.1 hex string"}try{b=d(c,0,[0,f,0,1,0],"02");a=d(c,0,[0,f,0,1,1],"02");g=d(c,0,[0,f,0,1,2],"02");i=d(c,0,[0,f,1,0],"02")}catch(e){console.log("EXCEPTION:"+e);throw"malformed X.509 certificate DSA public key"}this.setPublicHex(b,a,g,i)}}; \ No newline at end of file diff --git a/min/ecdsa-modified-1.0.min.js b/min/ecdsa-modified-1.0.min.js index 159ca1f3..54d2c8c8 100644 --- a/min/ecdsa-modified-1.0.min.js +++ b/min/ecdsa-modified-1.0.min.js @@ -1,3 +1,3 @@ -/*! ecdsa-modified-1.0.5.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE +/*! ecdsa-modified-1.1.0.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE */ -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECDSA=function(h){var e="secp256r1";var g=null;var b=null;var f=null;var a=new SecureRandom();var d=null;this.type="EC";function c(s,o,r,n){var j=Math.max(o.bitLength(),n.bitLength());var t=s.add2D(r);var q=s.curve.getInfinity();for(var p=j-1;p>=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()}; \ No newline at end of file +if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECDSA=function(h){var e="secp256r1";var g=null;var b=null;var f=null;var a=new SecureRandom();var d=null;this.type="EC";this.isPrivate=false;this.isPublic=false;function c(s,o,r,n){var j=Math.max(o.bitLength(),n.bitLength());var t=s.add2D(r);var q=s.curve.getInfinity();for(var p=j-1;p>=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}};this.readPKCS5PrvKeyHex=function(l){var n=ASN1HEX;var m=KJUR.crypto.ECDSA.getName;var p=n.getVbyList;if(n.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var i,k,o;try{i=p(l,0,[2,0],"06");k=p(l,0,[1],"04");try{o=p(l,0,[3,0],"03").substr(2)}catch(j){}}catch(j){throw"malformed PKCS#1/5 plain ECC private key"}this.curveName=m(i);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(o);this.setPrivateKeyHex(k);this.isPublic=false};this.readPKCS8PrvKeyHex=function(l){var q=ASN1HEX;var i=KJUR.crypto.ECDSA.getName;var n=q.getVbyList;if(q.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var j,p,m,k;try{j=n(l,0,[1,0],"06");p=n(l,0,[1,1],"06");m=n(l,0,[2,0,1],"04");try{k=n(l,0,[2,0,2,0],"03").substr(2)}catch(o){}}catch(o){throw"malformed PKCS#8 plain ECC private key"}this.curveName=i(p);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(k);this.setPrivateKeyHex(m);this.isPublic=false};this.readPKCS8PubKeyHex=function(l){var n=ASN1HEX;var m=KJUR.crypto.ECDSA.getName;var p=n.getVbyList;if(n.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var k,i,o;try{k=p(l,0,[0,0],"06");i=p(l,0,[0,1],"06");o=p(l,0,[1],"03").substr(2)}catch(j){throw"malformed PKCS#8 ECC public key"}this.curveName=m(i);if(this.curveName===null){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(o)};this.readCertPubKeyHex=function(k,p){if(p!==5){p=6}var m=ASN1HEX;var l=KJUR.crypto.ECDSA.getName;var o=m.getVbyList;if(m.isASN1HEX(k)===false){throw"not ASN.1 hex string"}var i,n;try{i=o(k,0,[0,p,0,1],"06");n=o(k,0,[0,p,1],"03").substr(2)}catch(j){throw"malformed X.509 certificate ECC public key"}this.curveName=l(i);if(this.curveName===null){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(n)};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()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040022"){return"secp384r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}return null}; \ No newline at end of file diff --git a/min/keyutil-1.0.min.js b/min/keyutil-1.0.min.js index 85d2e9d6..02a375e4 100644 --- a/min/keyutil-1.0.min.js +++ b/min/keyutil-1.0.min.js @@ -1,3 +1,3 @@ -/*! keyutil-1.0.14.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! keyutil-1.0.15.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",getHexFromPEM:function(q,u){var r=q;if(r.indexOf("-----BEGIN ")==-1){throw"can't find PEM header: "+u}if(typeof u=="string"&&u!=""){r=r.replace("-----BEGIN "+u+"-----","");r=r.replace("-----END "+u+"-----","")}else{r=r.replace(/-----BEGIN [^-]+-----/,"");r=r.replace(/-----END [^-]+-----/,"")}var t=r.replace(/\s+/g,"");var p=b64tohex(t);return p},getDecryptedKeyHexByKeyIV:function(q,t,s,r){var p=c(t);return p(q,s,r)},parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getRSAKeyFromEncryptedPKCS5PEM:function(r,q){var s=this.getDecryptedKeyHex(r,q);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(s);return p},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw"KEYUTIL unsupported algorithm: "+t}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},getEncryptedPKCS5PEMFromRSAKey:function(D,E,r,t){var B=new KJUR.asn1.DERInteger({"int":0});var w=new KJUR.asn1.DERInteger({bigint:D.n});var A=new KJUR.asn1.DERInteger({"int":D.e});var C=new KJUR.asn1.DERInteger({bigint:D.d});var u=new KJUR.asn1.DERInteger({bigint:D.p});var s=new KJUR.asn1.DERInteger({bigint:D.q});var z=new KJUR.asn1.DERInteger({bigint:D.dmp1});var v=new KJUR.asn1.DERInteger({bigint:D.dmq1});var y=new KJUR.asn1.DERInteger({bigint:D.coeff});var F=new KJUR.asn1.DERSequence({array:[B,w,A,C,u,s,z,v,y]});var x=F.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,E,r,t)},newEncryptedPKCS5PEM:function(p,q,t,u){if(typeof q=="undefined"||q==null){q=1024}if(typeof t=="undefined"||t==null){t="10001"}var r=new RSAKey();r.generate(q,t);var s=null;if(typeof u=="undefined"||u==null){s=this.getEncryptedPKCS5PEMFromRSAKey(r,p)}else{s=this.getEncryptedPKCS5PEMFromRSAKey(r,p,u)}return s},getRSAKeyFromPlainPKCS8PEM:function(r){if(r.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var q=this.getHexFromPEM(r,"PRIVATE KEY");var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getRSAKeyFromPlainPKCS8Hex:function(s){var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"outer DERSequence shall have 3 elements: "+r.length}var q=ASN1HEX.getHexOfTLV_AtObj(s,r[1]);if(q!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmIdentifier is not rsaEnc: "+q}var q=ASN1HEX.getHexOfTLV_AtObj(s,r[1]);var t=ASN1HEX.getHexOfTLV_AtObj(s,r[2]);var u=ASN1HEX.getHexOfV_AtObj(t,0);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(u);return p},parseHexOfEncryptedPKCS8:function(w){var s={};var r=ASN1HEX.getPosArrayOfChildren_AtObj(w,0);if(r.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+r.length}s.ciphertext=ASN1HEX.getHexOfV_AtObj(w,r[1]);var y=ASN1HEX.getPosArrayOfChildren_AtObj(w,r[0]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+y.length}if(ASN1HEX.getHexOfV_AtObj(w,y[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(w,y[1]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+p.length}var q=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[1]);if(q.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length}if(ASN1HEX.getHexOfV_AtObj(w,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}s.encryptionSchemeAlg="TripleDES";s.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(w,q[1]);var t=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[0]);if(t.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+t.length}if(ASN1HEX.getHexOfV_AtObj(w,t[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var x=ASN1HEX.getPosArrayOfChildren_AtObj(w,t[1]);if(x.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length}s.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(w,x[0]);var u=ASN1HEX.getHexOfV_AtObj(w,x[1]);try{s.pbkdf2Iter=parseInt(u,16)}catch(v){throw"malformed format pbkdf2Iter: "+u}return s},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=this.getHexFromPEM(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getRSAKeyFromEncryptedPKCS8PEM:function(s,r){var q=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,r);var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(s.substr(r[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,r[1]);if(p.length!=2){throw"malformed PKCS8 private key(code:004)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}if(s.substr(r[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}q.keyidx=ASN1HEX.getStartPosOfV_AtObj(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=this.getHexFromPEM(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var w=this.parsePlainPrivatePKCS8Hex(p);if(w.algoid=="2a864886f70d010101"){this.parsePrivateRawRSAKeyHexAtObj(p,w);var u=w.key;var z=new RSAKey();z.setPrivateEx(u.n,u.e,u.d,u.p,u.q,u.dp,u.dq,u.co);return z}else{if(w.algoid=="2a8648ce3d0201"){this.parsePrivateRawECKeyHexAtObj(p,w);if(KJUR.crypto.OID.oidhex2name[w.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+w.algparam}var v=KJUR.crypto.OID.oidhex2name[w.algparam];var z=new KJUR.crypto.ECDSA({curve:v});z.setPublicKeyHex(w.pubkey);z.setPrivateKeyHex(w.key);z.isPublic=false;return z}else{if(w.algoid=="2a8648ce380401"){var t=ASN1HEX.getVbyList(p,0,[1,1,0],"02");var s=ASN1HEX.getVbyList(p,0,[1,1,1],"02");var y=ASN1HEX.getVbyList(p,0,[1,1,2],"02");var B=ASN1HEX.getVbyList(p,0,[2,0],"02");var r=new BigInteger(t,16);var q=new BigInteger(s,16);var x=new BigInteger(y,16);var A=new BigInteger(B,16);var z=new KJUR.crypto.DSA();z.setPrivate(r,q,x,null,A);return z}else{throw"unsupported private key algorithm"}}}},getRSAKeyFromPublicPKCS8PEM:function(q){var r=this.getHexFromPEM(q,"PUBLIC KEY");var p=this.getRSAKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8PEM:function(q){var r=this.getHexFromPEM(q,"PUBLIC KEY");var p=this.getKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8Hex:function(q){var p=this.parsePublicPKCS8Hex(q);if(p.algoid=="2a864886f70d010101"){var u=this.parsePublicRawRSAKeyHex(p.key);var r=new RSAKey();r.setPublic(u.n,u.e);return r}else{if(p.algoid=="2a8648ce3d0201"){if(KJUR.crypto.OID.oidhex2name[p.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+p.algparam}var s=KJUR.crypto.OID.oidhex2name[p.algparam];var r=new KJUR.crypto.ECDSA({curve:s,pub:p.key});return r}else{if(p.algoid=="2a8648ce380401"){var t=p.algparam;var v=ASN1HEX.getHexOfV_AtObj(p.key,0);var r=new KJUR.crypto.DSA();r.setPublic(new BigInteger(t.p,16),new BigInteger(t.q,16),new BigInteger(t.g,16),new BigInteger(v,16));return r}else{throw"unsupported public key algorithm"}}}},parsePublicRawRSAKeyHex:function(r){var p={};if(r.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"malformed RSA key(code:002)"}if(r.substr(q[0],2)!="02"){throw"malformed RSA key(code:003)"}p.n=ASN1HEX.getHexOfV_AtObj(r,q[0]);if(r.substr(q[1],2)!="02"){throw"malformed RSA key(code:004)"}p.e=ASN1HEX.getHexOfV_AtObj(r,q[1]);return p},parsePrivateRawRSAKeyHexAtObj:function(q,s){var r=s.keyidx;if(q.substr(r,2)!="30"){throw"malformed RSA private key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,r);if(p.length!=9){throw"malformed RSA private key(code:002)"}s.key={};s.key.n=ASN1HEX.getHexOfV_AtObj(q,p[1]);s.key.e=ASN1HEX.getHexOfV_AtObj(q,p[2]);s.key.d=ASN1HEX.getHexOfV_AtObj(q,p[3]);s.key.p=ASN1HEX.getHexOfV_AtObj(q,p[4]);s.key.q=ASN1HEX.getHexOfV_AtObj(q,p[5]);s.key.dp=ASN1HEX.getHexOfV_AtObj(q,p[6]);s.key.dq=ASN1HEX.getHexOfV_AtObj(q,p[7]);s.key.co=ASN1HEX.getHexOfV_AtObj(q,p[8])},parsePrivateRawECKeyHexAtObj:function(p,t){var q=t.keyidx;var r=ASN1HEX.getVbyList(p,q,[1],"04");var s=ASN1HEX.getVbyList(p,q,[2,0],"03").substr(2);t.key=r;t.pubkey=s},parsePublicPKCS8Hex:function(s){var q={};q.algparam=null;var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=2){throw"outer DERSequence shall have 2 elements: "+r.length}var t=r[0];if(s.substr(t,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,t);if(p.length!=2){throw"malformed PKCS8 public key(code:002)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}else{if(s.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=ASN1HEX.getVbyList(s,p[1],[0],"02");q.algparam.q=ASN1HEX.getVbyList(s,p[1],[1],"02");q.algparam.g=ASN1HEX.getVbyList(s,p[1],[2],"02")}}if(s.substr(r[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}q.key=ASN1HEX.getHexOfV_AtObj(s,r[1]).substr(2);return q},getRSAKeyFromPublicPKCS8Hex:function(t){var s=ASN1HEX.getPosArrayOfChildren_AtObj(t,0);if(s.length!=2){throw"outer DERSequence shall have 2 elements: "+s.length}var r=ASN1HEX.getHexOfTLV_AtObj(t,s[0]);if(r!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmId is not rsaEncryption"}if(t.substr(s[1],2)!="03"){throw"PKCS8 Public Key is not BITSTRING encapslated."}var v=ASN1HEX.getStartPosOfV_AtObj(t,s[1])+2;if(t.substr(v,2)!="30"){throw"PKCS8 Public Key is not SEQUENCE."}var p=ASN1HEX.getPosArrayOfChildren_AtObj(t,v);if(p.length!=2){throw"inner DERSequence shall have 2 elements: "+p.length}if(t.substr(p[0],2)!="02"){throw"N is not ASN.1 INTEGER"}if(t.substr(p[1],2)!="02"){throw"E is not ASN.1 INTEGER"}var w=ASN1HEX.getHexOfV_AtObj(t,p[0]);var u=ASN1HEX.getHexOfV_AtObj(t,p[1]);var q=new RSAKey();q.setPublic(w,u);return q},}}();KEYUTIL.getKey=function(f,e,h){if(typeof RSAKey!="undefined"&&f instanceof RSAKey){return f}if(typeof KJUR.crypto.ECDSA!="undefined"&&f instanceof KJUR.crypto.ECDSA){return f}if(typeof KJUR.crypto.DSA!="undefined"&&f instanceof KJUR.crypto.DSA){return f}if(f.curve!==undefined&&f.xy!==undefined&&f.d===undefined){return new KJUR.crypto.ECDSA({pub:f.xy,curve:f.curve})}if(f.curve!==undefined&&f.d!==undefined){return new KJUR.crypto.ECDSA({prv:f.d,curve:f.curve})}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d===undefined){var w=new RSAKey();w.setPublic(f.n,f.e);return w}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p!==undefined&&f.q!==undefined&&f.dp!==undefined&&f.dq!==undefined&&f.co!==undefined&&f.qi===undefined){var w=new RSAKey();w.setPrivateEx(f.n,f.e,f.d,f.p,f.q,f.dp,f.dq,f.co);return w}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p===undefined){var w=new RSAKey();w.setPrivate(f.n,f.e,f.d);return w}if(f.p!==undefined&&f.q!==undefined&&f.g!==undefined&&f.y!==undefined&&f.x===undefined){var w=new KJUR.crypto.DSA();w.setPublic(f.p,f.q,f.g,f.y);return w}if(f.p!==undefined&&f.q!==undefined&&f.g!==undefined&&f.y!==undefined&&f.x!==undefined){var w=new KJUR.crypto.DSA();w.setPrivate(f.p,f.q,f.g,f.y,f.x);return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d===undefined){var w=new RSAKey();w.setPublic(b64utohex(f.n),b64utohex(f.e));return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p!==undefined&&f.q!==undefined&&f.dp!==undefined&&f.dq!==undefined&&f.qi!==undefined){var w=new RSAKey();w.setPrivateEx(b64utohex(f.n),b64utohex(f.e),b64utohex(f.d),b64utohex(f.p),b64utohex(f.q),b64utohex(f.dp),b64utohex(f.dq),b64utohex(f.qi));return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined){var w=new RSAKey();w.setPrivate(b64utohex(f.n),b64utohex(f.e),b64utohex(f.d));return w}if(f.kty==="EC"&&f.crv!==undefined&&f.x!==undefined&&f.y!==undefined&&f.d===undefined){var d=new KJUR.crypto.ECDSA({curve:f.crv});var l=d.ecparams.keylen/4;var r=("0000000000"+b64utohex(f.x)).slice(-l);var n=("0000000000"+b64utohex(f.y)).slice(-l);var m="04"+r+n;d.setPublicKeyHex(m);return d}if(f.kty==="EC"&&f.crv!==undefined&&f.x!==undefined&&f.y!==undefined&&f.d!==undefined){var d=new KJUR.crypto.ECDSA({curve:f.crv});var l=d.ecparams.keylen/4;var r=("0000000000"+b64utohex(f.x)).slice(-l);var n=("0000000000"+b64utohex(f.y)).slice(-l);var m="04"+r+n;var a=("0000000000"+b64utohex(f.d)).slice(-l);d.setPublicKeyHex(m);d.setPrivateKeyHex(a);return d}if(f.indexOf("-END CERTIFICATE-",0)!=-1||f.indexOf("-END X509 CERTIFICATE-",0)!=-1||f.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(f)}if(h==="pkcs8pub"){return KEYUTIL.getKeyFromPublicPKCS8Hex(f)}if(f.indexOf("-END PUBLIC KEY-")!=-1){return KEYUTIL.getKeyFromPublicPKCS8PEM(f)}if(h==="pkcs5prv"){var w=new RSAKey();w.readPrivateKeyFromASN1HexString(f);return w}if(h==="pkcs5prv"){var w=new RSAKey();w.readPrivateKeyFromASN1HexString(f);return w}if(f.indexOf("-END RSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")==-1){var i=KEYUTIL.getHexFromPEM(f,"RSA PRIVATE KEY");return KEYUTIL.getKey(i,null,"pkcs5prv")}if(f.indexOf("-END DSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")==-1){var u=this.getHexFromPEM(f,"DSA PRIVATE KEY");var t=ASN1HEX.getVbyList(u,0,[1],"02");var s=ASN1HEX.getVbyList(u,0,[2],"02");var v=ASN1HEX.getVbyList(u,0,[3],"02");var j=ASN1HEX.getVbyList(u,0,[4],"02");var k=ASN1HEX.getVbyList(u,0,[5],"02");var w=new KJUR.crypto.DSA();w.setPrivate(new BigInteger(t,16),new BigInteger(s,16),new BigInteger(v,16),new BigInteger(j,16),new BigInteger(k,16));return w}if(f.indexOf("-END PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(f)}if(f.indexOf("-END RSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(f,e)}if(f.indexOf("-END EC PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){var u=KEYUTIL.getDecryptedKeyHex(f,e);var w=ASN1HEX.getVbyList(u,0,[1],"04");var c=ASN1HEX.getVbyList(u,0,[2,0],"06");var o=ASN1HEX.getVbyList(u,0,[3,0],"03").substr(2);var b="";if(KJUR.crypto.OID.oidhex2name[c]!==undefined){b=KJUR.crypto.OID.oidhex2name[c]}else{throw"undefined OID(hex) in KJUR.crypto.OID: "+c}var d=new KJUR.crypto.ECDSA({name:b});d.setPublicKeyHex(o);d.setPrivateKeyHex(w);d.isPublic=false;return d}if(f.indexOf("-END DSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){var u=KEYUTIL.getDecryptedKeyHex(f,e);var t=ASN1HEX.getVbyList(u,0,[1],"02");var s=ASN1HEX.getVbyList(u,0,[2],"02");var v=ASN1HEX.getVbyList(u,0,[3],"02");var j=ASN1HEX.getVbyList(u,0,[4],"02");var k=ASN1HEX.getVbyList(u,0,[5],"02");var w=new KJUR.crypto.DSA();w.setPrivate(new BigInteger(t,16),new BigInteger(s,16),new BigInteger(v,16),new BigInteger(j,16),new BigInteger(k,16));return w}if(f.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromEncryptedPKCS8PEM(f,e)}throw"not supported argument"};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw"unknown algorithm: "+a}}};KEYUTIL.getPEM=function(a,r,o,g,j){var v=KJUR.asn1;var u=KJUR.crypto;function p(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return w}function q(w){var s=KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:w.prvKeyHex}},{tag:["a0",true,{oid:{name:w.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+w.pubKeyHex}}]}]});return s}function n(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return w}if(((typeof RSAKey!="undefined"&&a instanceof RSAKey)||(typeof u.DSA!="undefined"&&a instanceof u.DSA)||(typeof u.ECDSA!="undefined"&&a instanceof u.ECDSA))&&a.isPublic==true&&(r===undefined||r=="PKCS8PUB")){var t=new KJUR.asn1.x509.SubjectPublicKeyInfo(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"PUBLIC KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o===undefined||o==null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"RSA PRIVATE KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o===undefined||o==null)&&a.isPrivate==true){var f=new KJUR.asn1.DERObjectIdentifier({name:a.curveName});var l=f.getEncodedHex();var e=q(a);var k=e.getEncodedHex();var i="";i+=v.ASN1Util.getPEMStringFromHex(l,"EC PARAMETERS");i+=v.ASN1Util.getPEMStringFromHex(k,"EC PRIVATE KEY");return i}if(r=="PKCS1PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o===undefined||o==null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"DSA PRIVATE KEY")}if(r=="PKCS5PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=q(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",m,o,g)}var h=function(w,s){var y=b(w,s);var x=new KJUR.asn1.ASN1Util.newObject({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:y.pbkdf2Salt}},{"int":y.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:y.encryptionSchemeIV}}]}]}]},{octstr:{hex:y.ciphertext}}]});return x.getEncodedHex()};var b=function(D,E){var x=100;var C=CryptoJS.lib.WordArray.random(8);var B="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var y=CryptoJS.PBKDF2(E,C,{keySize:192/32,iterations:x});var z=CryptoJS.enc.Hex.parse(D);var A=CryptoJS.TripleDES.encrypt(z,y,{iv:s})+"";var w={};w.ciphertext=A;w.pbkdf2Salt=CryptoJS.enc.Hex.stringify(C);w.pbkdf2Iter=x;w.encryptionSchemeAlg=B;w.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return w};if(r=="PKCS8PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&a.isPrivate==true){var d=p(a);var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&a.isPrivate==true){var d=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:a.prvKeyHex}},{tag:["a1",true,{bitstr:{hex:"00"+a.pubKeyHex}}]}]});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:a.curveName}}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&a.isPrivate==true){var d=new KJUR.asn1.DERInteger({bigint:a.x});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:a.p}},{"int":{bigint:a.q}},{"int":{bigint:a.g}}]}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}throw"unsupported object nor format"};KEYUTIL.getKeyFromCSRPEM=function(b){var a=KEYUTIL.getHexFromPEM(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(c){var b={};var e=c;if(e.substr(0,2)!="30"){throw"malformed CSR(code:001)"}var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,0);if(d.length<1){throw"malformed CSR(code:002)"}if(e.substr(d[0],2)!="30"){throw"malformed CSR(code:003)"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(e,d[0]);if(a.length<3){throw"malformed CSR(code:004)"}b.p8pubkeyhex=ASN1HEX.getHexOfTLV_AtObj(e,a[2]);return b};KEYUTIL.getJWKFromKey=function(d){var b={};if(d instanceof RSAKey&&d.isPrivate){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));b.d=hextob64u(d.d.toString(16));b.p=hextob64u(d.p.toString(16));b.q=hextob64u(d.q.toString(16));b.dp=hextob64u(d.dmp1.toString(16));b.dq=hextob64u(d.dmq1.toString(16));b.qi=hextob64u(d.coeff.toString(16));return b}else{if(d instanceof RSAKey&&d.isPublic){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPrivate){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);b.d=hextob64u(d.prvKeyHex);return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPublic){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);return b}}}}throw"not supported key object"}; \ No newline at end of file +var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",getHexFromPEM:function(p,q){return ASN1HEX.pemToHex(p,q)},getDecryptedKeyHexByKeyIV:function(q,t,s,r){var p=c(t);return p(q,s,r)},parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getRSAKeyFromEncryptedPKCS5PEM:function(r,q){var s=this.getDecryptedKeyHex(r,q);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(s);return p},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw"KEYUTIL unsupported algorithm: "+t}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},getEncryptedPKCS5PEMFromRSAKey:function(D,E,r,t){var B=new KJUR.asn1.DERInteger({"int":0});var w=new KJUR.asn1.DERInteger({bigint:D.n});var A=new KJUR.asn1.DERInteger({"int":D.e});var C=new KJUR.asn1.DERInteger({bigint:D.d});var u=new KJUR.asn1.DERInteger({bigint:D.p});var s=new KJUR.asn1.DERInteger({bigint:D.q});var z=new KJUR.asn1.DERInteger({bigint:D.dmp1});var v=new KJUR.asn1.DERInteger({bigint:D.dmq1});var y=new KJUR.asn1.DERInteger({bigint:D.coeff});var F=new KJUR.asn1.DERSequence({array:[B,w,A,C,u,s,z,v,y]});var x=F.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,E,r,t)},newEncryptedPKCS5PEM:function(p,q,t,u){if(typeof q=="undefined"||q==null){q=1024}if(typeof t=="undefined"||t==null){t="10001"}var r=new RSAKey();r.generate(q,t);var s=null;if(typeof u=="undefined"||u==null){s=this.getEncryptedPKCS5PEMFromRSAKey(r,p)}else{s=this.getEncryptedPKCS5PEMFromRSAKey(r,p,u)}return s},getRSAKeyFromPlainPKCS8PEM:function(r){if(r.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var q=ASN1HEX.pemToHex(r,"PRIVATE KEY");var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getRSAKeyFromPlainPKCS8Hex:function(q){var p=new RSAKey();p.readPKCS8PrvKeyHex(q);return p},parseHexOfEncryptedPKCS8:function(w){var s={};var r=ASN1HEX.getPosArrayOfChildren_AtObj(w,0);if(r.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+r.length}s.ciphertext=ASN1HEX.getHexOfV_AtObj(w,r[1]);var y=ASN1HEX.getPosArrayOfChildren_AtObj(w,r[0]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+y.length}if(ASN1HEX.getHexOfV_AtObj(w,y[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(w,y[1]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+p.length}var q=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[1]);if(q.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length}if(ASN1HEX.getHexOfV_AtObj(w,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}s.encryptionSchemeAlg="TripleDES";s.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(w,q[1]);var t=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[0]);if(t.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+t.length}if(ASN1HEX.getHexOfV_AtObj(w,t[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var x=ASN1HEX.getPosArrayOfChildren_AtObj(w,t[1]);if(x.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length}s.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(w,x[0]);var u=ASN1HEX.getHexOfV_AtObj(w,x[1]);try{s.pbkdf2Iter=parseInt(u,16)}catch(v){throw"malformed format pbkdf2Iter: "+u}return s},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=ASN1HEX.pemToHex(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getRSAKeyFromEncryptedPKCS8PEM:function(s,r){var q=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,r);var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(s.substr(r[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,r[1]);if(p.length!=2){throw"malformed PKCS8 private key(code:004)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}if(s.substr(r[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}q.keyidx=ASN1HEX.getStartPosOfV_AtObj(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=ASN1HEX.pemToHex(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var q=this.parsePlainPrivatePKCS8Hex(p);var r;if(q.algoid=="2a864886f70d010101"){r=new RSAKey()}else{if(q.algoid=="2a8648ce380401"){r=new KJUR.crypto.DSA()}else{if(q.algoid=="2a8648ce3d0201"){r=new KJUR.crypto.ECDSA()}else{throw"unsupported private key algorithm"}}}r.readPKCS8PrvKeyHex(p);return r},getRSAKeyFromPublicPKCS8PEM:function(q){var r=ASN1HEX.pemToHex(q,"PUBLIC KEY");var p=this.getRSAKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8PEM:function(q){var r=ASN1HEX.pemToHex(q,"PUBLIC KEY");var p=this.getKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8Hex:function(q){var p;var r=ASN1HEX.getVbyList(q,0,[0,0],"06");if(r==="2a864886f70d010101"){p=new RSAKey()}else{if(r==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(r==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw"unsupported PKCS#8 public key hex"}}}p.readPKCS8PubKeyHex(q);return p},parsePublicRawRSAKeyHex:function(r){var p={};if(r.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"malformed RSA key(code:002)"}if(r.substr(q[0],2)!="02"){throw"malformed RSA key(code:003)"}p.n=ASN1HEX.getHexOfV_AtObj(r,q[0]);if(r.substr(q[1],2)!="02"){throw"malformed RSA key(code:004)"}p.e=ASN1HEX.getHexOfV_AtObj(r,q[1]);return p},parsePrivateRawRSAKeyHexAtObj:function(q,u){var t=ASN1HEX;var r=t.getHexOfV_AtObj;var s=t.getDecendantIndexByNthList(q,0,[2,0]);var p=t.getPosArrayOfChildren_AtObj(q,s);if(p.length!==9){throw"malformed PKCS#8 plain RSA private key"}u.key={};u.key.n=r(q,p[1]);u.key.e=r(q,p[2]);u.key.d=r(q,p[3]);u.key.p=r(q,p[4]);u.key.q=r(q,p[5]);u.key.dp=r(q,p[6]);u.key.dq=r(q,p[7]);u.key.co=r(q,p[8])},parsePrivateRawECKeyHexAtObj:function(p,t){var s=ASN1HEX;var q=t.keyidx;var r=new KJUR.crypto.ECDSA();r.readPKCS8PrvKeyHex(p);t.key=r.prvKeyHex;t.pubkey=r.pubKeyHex},parsePublicPKCS8Hex:function(s){var q={};q.algparam=null;var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=2){throw"outer DERSequence shall have 2 elements: "+r.length}var t=r[0];if(s.substr(t,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,t);if(p.length!=2){throw"malformed PKCS8 public key(code:002)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}else{if(s.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=ASN1HEX.getVbyList(s,p[1],[0],"02");q.algparam.q=ASN1HEX.getVbyList(s,p[1],[1],"02");q.algparam.g=ASN1HEX.getVbyList(s,p[1],[2],"02")}}if(s.substr(r[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}q.key=ASN1HEX.getHexOfV_AtObj(s,r[1]).substr(2);return q},getRSAKeyFromPublicPKCS8Hex:function(p){var q=new RSAKey();q.readPKCS8PubKeyHex(p);return q},}}();KEYUTIL.getKey=function(i,f,j){if(typeof RSAKey!="undefined"&&i instanceof RSAKey){return i}if(typeof KJUR.crypto.ECDSA!="undefined"&&i instanceof KJUR.crypto.ECDSA){return i}if(typeof KJUR.crypto.DSA!="undefined"&&i instanceof KJUR.crypto.DSA){return i}if(i.curve!==undefined&&i.xy!==undefined&&i.d===undefined){return new KJUR.crypto.ECDSA({pub:i.xy,curve:i.curve})}if(i.curve!==undefined&&i.d!==undefined){return new KJUR.crypto.ECDSA({prv:i.d,curve:i.curve})}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d===undefined){var D=new RSAKey();D.setPublic(i.n,i.e);return D}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p!==undefined&&i.q!==undefined&&i.dp!==undefined&&i.dq!==undefined&&i.co!==undefined&&i.qi===undefined){var D=new RSAKey();D.setPrivateEx(i.n,i.e,i.d,i.p,i.q,i.dp,i.dq,i.co);return D}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p===undefined){var D=new RSAKey();D.setPrivate(i.n,i.e,i.d);return D}if(i.p!==undefined&&i.q!==undefined&&i.g!==undefined&&i.y!==undefined&&i.x===undefined){var D=new KJUR.crypto.DSA();D.setPublic(i.p,i.q,i.g,i.y);return D}if(i.p!==undefined&&i.q!==undefined&&i.g!==undefined&&i.y!==undefined&&i.x!==undefined){var D=new KJUR.crypto.DSA();D.setPrivate(i.p,i.q,i.g,i.y,i.x);return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d===undefined){var D=new RSAKey();D.setPublic(b64utohex(i.n),b64utohex(i.e));return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p!==undefined&&i.q!==undefined&&i.dp!==undefined&&i.dq!==undefined&&i.qi!==undefined){var D=new RSAKey();D.setPrivateEx(b64utohex(i.n),b64utohex(i.e),b64utohex(i.d),b64utohex(i.p),b64utohex(i.q),b64utohex(i.dp),b64utohex(i.dq),b64utohex(i.qi));return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined){var D=new RSAKey();D.setPrivate(b64utohex(i.n),b64utohex(i.e),b64utohex(i.d));return D}if(i.kty==="EC"&&i.crv!==undefined&&i.x!==undefined&&i.y!==undefined&&i.d===undefined){var e=new KJUR.crypto.ECDSA({curve:i.crv});var n=e.ecparams.keylen/4;var t=("0000000000"+b64utohex(i.x)).slice(-n);var r=("0000000000"+b64utohex(i.y)).slice(-n);var o="04"+t+r;e.setPublicKeyHex(o);return e}if(i.kty==="EC"&&i.crv!==undefined&&i.x!==undefined&&i.y!==undefined&&i.d!==undefined){var e=new KJUR.crypto.ECDSA({curve:i.crv});var n=e.ecparams.keylen/4;var t=("0000000000"+b64utohex(i.x)).slice(-n);var r=("0000000000"+b64utohex(i.y)).slice(-n);var o="04"+t+r;var b=("0000000000"+b64utohex(i.d)).slice(-n);e.setPublicKeyHex(o);e.setPrivateKeyHex(b);return e}if(j==="pkcs5prv"){var A=i,w=ASN1HEX,C,D;C=w.getPosArrayOfChildren_AtObj(A,0);if(C.length===9){D=new RSAKey();D.readPrivateKeyFromASN1HexString(i)}else{if(C.length===6){D=new KJUR.crypto.DSA();D.readPKCS5PrvKeyHex(A)}else{if(C.length>2&&A.substr(C[1],2)==="04"){D=new KJUR.crypto.ECDSA();D.readPKCS5PrvKeyHex(A)}else{throw"unsupported PKCS#1/5 hexadecimal key"}}}return D}if(j==="pkcs8prv"){var D=KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(i);return D}if(j==="pkcs8pub"){return KEYUTIL.getKeyFromPublicPKCS8Hex(i)}if(j==="x509pub"){return X509.getPublicKeyFromCertHex(i)}if(i.indexOf("-END CERTIFICATE-",0)!=-1||i.indexOf("-END X509 CERTIFICATE-",0)!=-1||i.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(i)}if(i.indexOf("-END PUBLIC KEY-")!=-1){return KEYUTIL.getKeyFromPublicPKCS8PEM(i)}if(i.indexOf("-END RSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")==-1){var k=ASN1HEX.pemToHex(i,"RSA PRIVATE KEY");return KEYUTIL.getKey(k,null,"pkcs5prv")}if(i.indexOf("-END DSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")==-1){var z=ASN1HEX.pemToHex(i,"DSA PRIVATE KEY");var v=ASN1HEX.getVbyList(z,0,[1],"02");var u=ASN1HEX.getVbyList(z,0,[2],"02");var B=ASN1HEX.getVbyList(z,0,[3],"02");var l=ASN1HEX.getVbyList(z,0,[4],"02");var m=ASN1HEX.getVbyList(z,0,[5],"02");var D=new KJUR.crypto.DSA();D.setPrivate(new BigInteger(v,16),new BigInteger(u,16),new BigInteger(B,16),new BigInteger(l,16),new BigInteger(m,16));return D}if(i.indexOf("-END PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(i)}if(i.indexOf("-END RSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(i,f)}if(i.indexOf("-END EC PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){var z=KEYUTIL.getDecryptedKeyHex(i,f);var D=ASN1HEX.getVbyList(z,0,[1],"04");var d=ASN1HEX.getVbyList(z,0,[2,0],"06");var s=ASN1HEX.getVbyList(z,0,[3,0],"03").substr(2);var c="";if(KJUR.crypto.OID.oidhex2name[d]!==undefined){c=KJUR.crypto.OID.oidhex2name[d]}else{throw"undefined OID(hex) in KJUR.crypto.OID: "+d}var e=new KJUR.crypto.ECDSA({curve:c});e.setPublicKeyHex(s);e.setPrivateKeyHex(D);e.isPublic=false;return e}if(i.indexOf("-END DSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){var z=KEYUTIL.getDecryptedKeyHex(i,f);var v=ASN1HEX.getVbyList(z,0,[1],"02");var u=ASN1HEX.getVbyList(z,0,[2],"02");var B=ASN1HEX.getVbyList(z,0,[3],"02");var l=ASN1HEX.getVbyList(z,0,[4],"02");var m=ASN1HEX.getVbyList(z,0,[5],"02");var D=new KJUR.crypto.DSA();D.setPrivate(new BigInteger(v,16),new BigInteger(u,16),new BigInteger(B,16),new BigInteger(l,16),new BigInteger(m,16));return D}if(i.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromEncryptedPKCS8PEM(i,f)}throw"not supported argument"};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw"unknown algorithm: "+a}}};KEYUTIL.getPEM=function(a,r,o,g,j){var v=KJUR.asn1;var u=KJUR.crypto;function p(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return w}function q(w){var s=KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:w.prvKeyHex}},{tag:["a0",true,{oid:{name:w.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+w.pubKeyHex}}]}]});return s}function n(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return w}if(((typeof RSAKey!="undefined"&&a instanceof RSAKey)||(typeof u.DSA!="undefined"&&a instanceof u.DSA)||(typeof u.ECDSA!="undefined"&&a instanceof u.ECDSA))&&a.isPublic==true&&(r===undefined||r=="PKCS8PUB")){var t=new KJUR.asn1.x509.SubjectPublicKeyInfo(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"PUBLIC KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o===undefined||o==null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"RSA PRIVATE KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o===undefined||o==null)&&a.isPrivate==true){var f=new KJUR.asn1.DERObjectIdentifier({name:a.curveName});var l=f.getEncodedHex();var e=q(a);var k=e.getEncodedHex();var i="";i+=v.ASN1Util.getPEMStringFromHex(l,"EC PARAMETERS");i+=v.ASN1Util.getPEMStringFromHex(k,"EC PRIVATE KEY");return i}if(r=="PKCS1PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o===undefined||o==null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"DSA PRIVATE KEY")}if(r=="PKCS5PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=q(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",m,o,g)}var h=function(w,s){var y=b(w,s);var x=new KJUR.asn1.ASN1Util.newObject({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:y.pbkdf2Salt}},{"int":y.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:y.encryptionSchemeIV}}]}]}]},{octstr:{hex:y.ciphertext}}]});return x.getEncodedHex()};var b=function(D,E){var x=100;var C=CryptoJS.lib.WordArray.random(8);var B="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var y=CryptoJS.PBKDF2(E,C,{keySize:192/32,iterations:x});var z=CryptoJS.enc.Hex.parse(D);var A=CryptoJS.TripleDES.encrypt(z,y,{iv:s})+"";var w={};w.ciphertext=A;w.pbkdf2Salt=CryptoJS.enc.Hex.stringify(C);w.pbkdf2Iter=x;w.encryptionSchemeAlg=B;w.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return w};if(r=="PKCS8PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&a.isPrivate==true){var d=p(a);var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&a.isPrivate==true){var d=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:a.prvKeyHex}},{tag:["a1",true,{bitstr:{hex:"00"+a.pubKeyHex}}]}]});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:a.curveName}}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&a.isPrivate==true){var d=new KJUR.asn1.DERInteger({bigint:a.x});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:a.p}},{"int":{bigint:a.q}},{"int":{bigint:a.g}}]}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}throw"unsupported object nor format"};KEYUTIL.getKeyFromCSRPEM=function(b){var a=ASN1HEX.pemToHex(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(c){var b={};var e=c;if(e.substr(0,2)!="30"){throw"malformed CSR(code:001)"}var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,0);if(d.length<1){throw"malformed CSR(code:002)"}if(e.substr(d[0],2)!="30"){throw"malformed CSR(code:003)"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(e,d[0]);if(a.length<3){throw"malformed CSR(code:004)"}b.p8pubkeyhex=ASN1HEX.getHexOfTLV_AtObj(e,a[2]);return b};KEYUTIL.getJWKFromKey=function(d){var b={};if(d instanceof RSAKey&&d.isPrivate){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));b.d=hextob64u(d.d.toString(16));b.p=hextob64u(d.p.toString(16));b.q=hextob64u(d.q.toString(16));b.dp=hextob64u(d.dmp1.toString(16));b.dq=hextob64u(d.dmq1.toString(16));b.qi=hextob64u(d.coeff.toString(16));return b}else{if(d instanceof RSAKey&&d.isPublic){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPrivate){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);b.d=hextob64u(d.prvKeyHex);return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPublic){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);return b}}}}throw"not supported key object"}; \ No newline at end of file diff --git a/min/pkcs5pkey-1.0.min.js b/min/pkcs5pkey-1.0.min.js index 8f6dd27c..b1c6196d 100644 --- a/min/pkcs5pkey-1.0.min.js +++ b/min/pkcs5pkey-1.0.min.js @@ -1,3 +1,3 @@ -/*! pkcs5pkey-1.0.7.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! pkcs5pkey-1.1.0.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -var PKCS5PKEY=function(){var c=function(n,p,o){return i(CryptoJS.AES,n,p,o)};var d=function(n,p,o){return i(CryptoJS.TripleDES,n,p,o)};var i=function(q,v,s,o){var p=CryptoJS.enc.Hex.parse(v);var u=CryptoJS.enc.Hex.parse(s);var n=CryptoJS.enc.Hex.parse(o);var r={};r.key=u;r.iv=n;r.ciphertext=p;var t=q.decrypt(r,u,{iv:n});return CryptoJS.enc.Hex.stringify(t)};var j=function(n,p,o){return e(CryptoJS.AES,n,p,o)};var m=function(n,p,o){return e(CryptoJS.TripleDES,n,p,o)};var e=function(s,x,v,p){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(v);var o=CryptoJS.enc.Hex.parse(p);var n={};var u=s.encrypt(r,w,{iv:o});var q=CryptoJS.enc.Hex.parse(u.toString());var t=CryptoJS.enc.Base64.stringify(q);return t};var g={"AES-256-CBC":{proc:c,eproc:j,keylen:32,ivlen:16},"AES-192-CBC":{proc:c,eproc:j,keylen:24,ivlen:16},"AES-128-CBC":{proc:c,eproc:j,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:d,eproc:m,keylen:24,ivlen:8}};var b=function(n){return g[n]["proc"]};var k=function(n){var p=CryptoJS.lib.WordArray.random(n);var o=CryptoJS.enc.Hex.stringify(p);return o};var l=function(t){var u={};var o=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(o){u.cipher=o[1];u.ivsalt=o[2]}var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(n){u.type=n[1]}var r=-1;var v=0;if(t.indexOf("\r\n\r\n")!=-1){r=t.indexOf("\r\n\r\n");v=2}if(t.indexOf("\n\n")!=-1){r=t.indexOf("\n\n");v=1}var q=t.indexOf("-----END");if(r!=-1&&q!=-1){var p=t.substring(r+v*2,q-v);p=p.replace(/\s+/g,"");u.data=p}return u};var h=function(o,w,n){var t=n.substring(0,16);var r=CryptoJS.enc.Hex.parse(t);var p=CryptoJS.enc.Utf8.parse(w);var s=g[o]["keylen"]+g[o]["ivlen"];var v="";var u=null;for(;;){var q=CryptoJS.algo.MD5.create();if(u!=null){q.update(u)}q.update(p);q.update(r);u=q.finalize();v=v+CryptoJS.enc.Hex.stringify(u);if(v.length>=s*2){break}}var x={};x.keyhex=v.substr(0,g[o]["keylen"]*2);x.ivhex=v.substr(g[o]["keylen"]*2,g[o]["ivlen"]*2);return x};var a=function(n,t,p,u){var q=CryptoJS.enc.Base64.parse(n);var o=CryptoJS.enc.Hex.stringify(q);var s=g[t]["proc"];var r=s(o,p,u);return r};var f=function(n,q,o,s){var p=g[q]["eproc"];var r=p(n,o,s);return r};return{version:"1.0.5",getHexFromPEM:function(o,r){var p=o;if(p.indexOf("BEGIN "+r)==-1){throw"can't find PEM header: "+r}p=p.replace("-----BEGIN "+r+"-----","");p=p.replace("-----END "+r+"-----","");var q=p.replace(/\s+/g,"");var n=b64tohex(q);return n},getDecryptedKeyHexByKeyIV:function(o,r,q,p){var n=b(r);return n(o,q,p)},parsePKCS5PEM:function(n){return l(n)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(o,n,p){return h(o,n,p)},decryptKeyB64:function(n,p,o,q){return a(n,p,o,q)},getDecryptedKeyHex:function(w,v){var o=l(w);var r=o.type;var p=o.cipher;var n=o.ivsalt;var q=o.data;var u=h(p,v,n);var t=u.keyhex;var s=a(q,p,t,n);return s},getRSAKeyFromEncryptedPKCS5PEM:function(p,o){var q=this.getDecryptedKeyHex(p,o);var n=new RSAKey();n.readPrivateKeyFromASN1HexString(q);return n},getEncryptedPKCS5PEMFromPrvKeyHex:function(q,x,r,p){if(typeof r=="undefined"||r==null){r="AES-256-CBC"}if(typeof g[r]=="undefined"){throw"PKCS5PKEY unsupported algorithm: "+r}if(typeof p=="undefined"||p==null){var t=g[r]["ivlen"];var s=k(t);p=s.toUpperCase()}var w=h(r,x,p);var v=w.keyhex;var u=f(q,r,v,p);var o=u.replace(/(.{64})/g,"$1\r\n");var n="-----BEGIN RSA PRIVATE KEY-----\r\n";n+="Proc-Type: 4,ENCRYPTED\r\n";n+="DEK-Info: "+r+","+p+"\r\n";n+="\r\n";n+=o;n+="\r\n-----END RSA PRIVATE KEY-----\r\n";return n},getEncryptedPKCS5PEMFromRSAKey:function(C,D,o,s){var A=new KJUR.asn1.DERInteger({"int":0});var v=new KJUR.asn1.DERInteger({bigint:C.n});var z=new KJUR.asn1.DERInteger({"int":C.e});var B=new KJUR.asn1.DERInteger({bigint:C.d});var t=new KJUR.asn1.DERInteger({bigint:C.p});var r=new KJUR.asn1.DERInteger({bigint:C.q});var y=new KJUR.asn1.DERInteger({bigint:C.dmp1});var u=new KJUR.asn1.DERInteger({bigint:C.dmq1});var x=new KJUR.asn1.DERInteger({bigint:C.coeff});var E=new KJUR.asn1.DERSequence({array:[A,v,z,B,t,r,y,u,x]});var w=E.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex(w,D,o,s)},newEncryptedPKCS5PEM:function(n,o,r,s){if(typeof o=="undefined"||o==null){o=1024}if(typeof r=="undefined"||r==null){r="10001"}var p=new RSAKey();p.generate(o,r);var q=null;if(typeof s=="undefined"||s==null){q=this.getEncryptedPKCS5PEMFromRSAKey(pkey,n)}else{q=this.getEncryptedPKCS5PEMFromRSAKey(pkey,n,s)}return q},getRSAKeyFromPlainPKCS8PEM:function(p){if(p.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var o=this.getHexFromPEM(p,"PRIVATE KEY");var n=this.getRSAKeyFromPlainPKCS8Hex(o);return n},getRSAKeyFromPlainPKCS8Hex:function(q){var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=3){throw"outer DERSequence shall have 3 elements: "+p.length}var o=ASN1HEX.getHexOfTLV_AtObj(q,p[1]);if(o!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmIdentifier is not rsaEnc: "+o}var r=ASN1HEX.getHexOfTLV_AtObj(q,p[2]);var s=ASN1HEX.getHexOfV_AtObj(r,0);var n=new RSAKey();n.readPrivateKeyFromASN1HexString(s);return n},parseHexOfEncryptedPKCS8:function(u){var q={};var p=ASN1HEX.getPosArrayOfChildren_AtObj(u,0);if(p.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+p.length}q.ciphertext=ASN1HEX.getHexOfV_AtObj(u,p[1]);var w=ASN1HEX.getPosArrayOfChildren_AtObj(u,p[0]);if(w.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+w.length}if(ASN1HEX.getHexOfV_AtObj(u,w[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(u,w[1]);if(w.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+n.length}var o=ASN1HEX.getPosArrayOfChildren_AtObj(u,n[1]);if(o.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+o.length}if(ASN1HEX.getHexOfV_AtObj(u,o[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}q.encryptionSchemeAlg="TripleDES";q.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(u,o[1]);var r=ASN1HEX.getPosArrayOfChildren_AtObj(u,n[0]);if(r.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+r.length}if(ASN1HEX.getHexOfV_AtObj(u,r[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var v=ASN1HEX.getPosArrayOfChildren_AtObj(u,r[1]);if(v.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+v.length}q.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(u,v[0]);var s=ASN1HEX.getHexOfV_AtObj(u,v[1]);try{q.pbkdf2Iter=parseInt(s,16)}catch(t){throw"malformed format pbkdf2Iter: "+s}return q},getPBKDF2KeyHexFromParam:function(s,n){var r=CryptoJS.enc.Hex.parse(s.pbkdf2Salt);var o=s.pbkdf2Iter;var q=CryptoJS.PBKDF2(n,r,{keySize:192/32,iterations:o});var p=CryptoJS.enc.Hex.stringify(q);return p},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(v,w){var p=this.getHexFromPEM(v,"ENCRYPTED PRIVATE KEY");var n=this.parseHexOfEncryptedPKCS8(p);var s=PKCS5PKEY.getPBKDF2KeyHexFromParam(n,w);var t={};t.ciphertext=CryptoJS.enc.Hex.parse(n.ciphertext);var r=CryptoJS.enc.Hex.parse(s);var q=CryptoJS.enc.Hex.parse(n.encryptionSchemeIV);var u=CryptoJS.TripleDES.decrypt(t,r,{iv:q});var o=CryptoJS.enc.Hex.stringify(u);return o},getRSAKeyFromEncryptedPKCS8PEM:function(q,p){var o=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(q,p);var n=this.getRSAKeyFromPlainPKCS8Hex(o);return n},getKeyFromEncryptedPKCS8PEM:function(q,o){var n=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(q,o);var p=this.getKeyFromPlainPrivatePKCS8Hex(n);return p},parsePlainPrivatePKCS8Hex:function(q){var o={};o.algparam=null;if(q.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(q.substr(p[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(q,p[1]);if(n.length!=2){throw"malformed PKCS8 private key(code:004)"}if(q.substr(n[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}o.algoid=ASN1HEX.getHexOfV_AtObj(q,n[0]);if(q.substr(n[1],2)=="06"){o.algparam=ASN1HEX.getHexOfV_AtObj(q,n[1])}if(q.substr(p[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}o.keyidx=ASN1HEX.getStartPosOfV_AtObj(q,p[2]);return o},getKeyFromPlainPrivatePKCS8PEM:function(o){var n=this.getHexFromPEM(o,"PRIVATE KEY");var p=this.getKeyFromPlainPrivatePKCS8Hex(n);return p},getKeyFromPlainPrivatePKCS8Hex:function(n){var p=this.parsePlainPrivatePKCS8Hex(n);if(p.algoid=="2a864886f70d010101"){this.parsePrivateRawRSAKeyHexAtObj(n,p);var o=p.key;var q=new RSAKey();q.setPrivateEx(o.n,o.e,o.d,o.p,o.q,o.dp,o.dq,o.co);return q}else{if(p.algoid=="2a8648ce3d0201"){this.parsePrivateRawECKeyHexAtObj(n,p);if(KJUR.crypto.OID.oidhex2name[p.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+p.algparam}var r=KJUR.crypto.OID.oidhex2name[p.algparam];var q=new KJUR.crypto.ECDSA({curve:r,prv:p.key});return q}else{throw"unsupported private key algorithm"}}},getRSAKeyFromPublicPKCS8PEM:function(o){var p=this.getHexFromPEM(o,"PUBLIC KEY");var n=this.getRSAKeyFromPublicPKCS8Hex(p);return n},getKeyFromPublicPKCS8PEM:function(o){var p=this.getHexFromPEM(o,"PUBLIC KEY");var n=this.getKeyFromPublicPKCS8Hex(p);return n},getKeyFromPublicPKCS8Hex:function(o){var n=this.parsePublicPKCS8Hex(o);if(n.algoid=="2a864886f70d010101"){var r=this.parsePublicRawRSAKeyHex(n.key);var p=new RSAKey();p.setPublic(r.n,r.e);return p}else{if(n.algoid=="2a8648ce3d0201"){if(KJUR.crypto.OID.oidhex2name[n.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+n.algparam}var q=KJUR.crypto.OID.oidhex2name[n.algparam];var p=new KJUR.crypto.ECDSA({curve:q,pub:n.key});return p}else{throw"unsupported public key algorithm"}}},parsePublicRawRSAKeyHex:function(p){var n={};if(p.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,0);if(o.length!=2){throw"malformed RSA key(code:002)"}if(p.substr(o[0],2)!="02"){throw"malformed RSA key(code:003)"}n.n=ASN1HEX.getHexOfV_AtObj(p,o[0]);if(p.substr(o[1],2)!="02"){throw"malformed RSA key(code:004)"}n.e=ASN1HEX.getHexOfV_AtObj(p,o[1]);return n},parsePrivateRawRSAKeyHexAtObj:function(o,q){var p=q.keyidx;if(o.substr(p,2)!="30"){throw"malformed RSA private key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(o,p);if(n.length!=9){throw"malformed RSA private key(code:002)"}q.key={};q.key.n=ASN1HEX.getHexOfV_AtObj(o,n[1]);q.key.e=ASN1HEX.getHexOfV_AtObj(o,n[2]);q.key.d=ASN1HEX.getHexOfV_AtObj(o,n[3]);q.key.p=ASN1HEX.getHexOfV_AtObj(o,n[4]);q.key.q=ASN1HEX.getHexOfV_AtObj(o,n[5]);q.key.dp=ASN1HEX.getHexOfV_AtObj(o,n[6]);q.key.dq=ASN1HEX.getHexOfV_AtObj(o,n[7]);q.key.co=ASN1HEX.getHexOfV_AtObj(o,n[8])},parsePrivateRawECKeyHexAtObj:function(o,q){var p=q.keyidx;if(o.substr(p,2)!="30"){throw"malformed ECC private key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(o,p);if(n.length!=3){throw"malformed ECC private key(code:002)"}if(o.substr(n[1],2)!="04"){throw"malformed ECC private key(code:003)"}q.key=ASN1HEX.getHexOfV_AtObj(o,n[1])},parsePublicPKCS8Hex:function(q){var o={};o.algparam=null;var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=2){throw"outer DERSequence shall have 2 elements: "+p.length}var r=p[0];if(q.substr(r,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(q,r);if(n.length!=2){throw"malformed PKCS8 public key(code:002)"}if(q.substr(n[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}o.algoid=ASN1HEX.getHexOfV_AtObj(q,n[0]);if(q.substr(n[1],2)=="06"){o.algparam=ASN1HEX.getHexOfV_AtObj(q,n[1])}if(q.substr(p[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}o.key=ASN1HEX.getHexOfV_AtObj(q,p[1]).substr(2);return o},getRSAKeyFromPublicPKCS8Hex:function(r){var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"outer DERSequence shall have 2 elements: "+q.length}var p=ASN1HEX.getHexOfTLV_AtObj(r,q[0]);if(p!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmId is not rsaEncryption"}if(r.substr(q[1],2)!="03"){throw"PKCS8 Public Key is not BITSTRING encapslated."}var t=ASN1HEX.getStartPosOfV_AtObj(r,q[1])+2;if(r.substr(t,2)!="30"){throw"PKCS8 Public Key is not SEQUENCE."}var n=ASN1HEX.getPosArrayOfChildren_AtObj(r,t);if(n.length!=2){throw"inner DERSequence shall have 2 elements: "+n.length}if(r.substr(n[0],2)!="02"){throw"N is not ASN.1 INTEGER"}if(r.substr(n[1],2)!="02"){throw"E is not ASN.1 INTEGER"}var u=ASN1HEX.getHexOfV_AtObj(r,n[0]);var s=ASN1HEX.getHexOfV_AtObj(r,n[1]);var o=new RSAKey();o.setPublic(u,s);return o},}}(); \ No newline at end of file +var PKCS5PKEY=function(){var c=function(o,q,p){return j(CryptoJS.AES,o,q,p)};var d=function(o,q,p){return j(CryptoJS.TripleDES,o,q,p)};var j=function(r,w,t,p){var q=CryptoJS.enc.Hex.parse(w);var v=CryptoJS.enc.Hex.parse(t);var o=CryptoJS.enc.Hex.parse(p);var s={};s.key=v;s.iv=o;s.ciphertext=q;var u=r.decrypt(s,v,{iv:o});return CryptoJS.enc.Hex.stringify(u)};var k=function(o,q,p){return e(CryptoJS.AES,o,q,p)};var n=function(o,q,p){return e(CryptoJS.TripleDES,o,q,p)};var e=function(t,y,w,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(w);var p=CryptoJS.enc.Hex.parse(q);var o={};var v=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(v.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var g={"AES-256-CBC":{proc:c,eproc:k,keylen:32,ivlen:16},"AES-192-CBC":{proc:c,eproc:k,keylen:24,ivlen:16},"AES-128-CBC":{proc:c,eproc:k,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:d,eproc:n,keylen:24,ivlen:8}};var b=function(o){return g[o]["proc"]};var l=function(o){var q=CryptoJS.lib.WordArray.random(o);var p=CryptoJS.enc.Hex.stringify(q);return p};var m=function(u){var v={};var p=u.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(p){v.cipher=p[1];v.ivsalt=p[2]}var o=u.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(o){v.type=o[1]}var t=-1;var w=0;if(u.indexOf("\r\n\r\n")!=-1){t=u.indexOf("\r\n\r\n");w=2}if(u.indexOf("\n\n")!=-1){t=u.indexOf("\n\n");w=1}var r=u.indexOf("-----END");if(t!=-1&&r!=-1){var q=u.substring(t+w*2,r-w);q=q.replace(/\s+/g,"");v.data=q}return v};var i=function(p,x,o){var u=o.substring(0,16);var s=CryptoJS.enc.Hex.parse(u);var q=CryptoJS.enc.Utf8.parse(x);var t=g[p]["keylen"]+g[p]["ivlen"];var w="";var v=null;for(;;){var r=CryptoJS.algo.MD5.create();if(v!=null){r.update(v)}r.update(q);r.update(s);v=r.finalize();w=w+CryptoJS.enc.Hex.stringify(v);if(w.length>=t*2){break}}var y={};y.keyhex=w.substr(0,g[p]["keylen"]*2);y.ivhex=w.substr(g[p]["keylen"]*2,g[p]["ivlen"]*2);return y};var a=function(o,u,q,v){var r=CryptoJS.enc.Base64.parse(o);var p=CryptoJS.enc.Hex.stringify(r);var t=g[u]["proc"];var s=t(p,q,v);return s};var f=function(o,r,p,t){var q=g[r]["eproc"];var s=q(o,p,t);return s};return{version:"1.0.5",getHexFromPEM:function(o,p){return ASN1HEX.pemToHex(o,p)},getDecryptedKeyHexByKeyIV:function(p,s,r,q){var o=b(s);return o(p,r,q)},parsePKCS5PEM:function(o){return m(o)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(p,o,q){return i(p,o,q)},decryptKeyB64:function(o,q,p,r){return a(o,q,p,r)},getDecryptedKeyHex:function(x,w){var p=m(x);var s=p.type;var q=p.cipher;var o=p.ivsalt;var r=p.data;var v=i(q,w,o);var u=v.keyhex;var t=a(r,q,u,o);return t},getRSAKeyFromEncryptedPKCS5PEM:function(q,p){var r=this.getDecryptedKeyHex(q,p);var o=new RSAKey();o.readPrivateKeyFromASN1HexString(r);return o},getEncryptedPKCS5PEMFromPrvKeyHex:function(r,y,s,q){if(typeof s=="undefined"||s==null){s="AES-256-CBC"}if(typeof g[s]=="undefined"){throw"PKCS5PKEY unsupported algorithm: "+s}if(typeof q=="undefined"||q==null){var u=g[s]["ivlen"];var t=l(u);q=t.toUpperCase()}var x=i(s,y,q);var w=x.keyhex;var v=f(r,s,w,q);var p=v.replace(/(.{64})/g,"$1\r\n");var o="-----BEGIN RSA PRIVATE KEY-----\r\n";o+="Proc-Type: 4,ENCRYPTED\r\n";o+="DEK-Info: "+s+","+q+"\r\n";o+="\r\n";o+=p;o+="\r\n-----END RSA PRIVATE KEY-----\r\n";return o},getEncryptedPKCS5PEMFromRSAKey:function(C,D,o,s){var A=new KJUR.asn1.DERInteger({"int":0});var v=new KJUR.asn1.DERInteger({bigint:C.n});var z=new KJUR.asn1.DERInteger({"int":C.e});var B=new KJUR.asn1.DERInteger({bigint:C.d});var t=new KJUR.asn1.DERInteger({bigint:C.p});var r=new KJUR.asn1.DERInteger({bigint:C.q});var y=new KJUR.asn1.DERInteger({bigint:C.dmp1});var u=new KJUR.asn1.DERInteger({bigint:C.dmq1});var x=new KJUR.asn1.DERInteger({bigint:C.coeff});var E=new KJUR.asn1.DERSequence({array:[A,v,z,B,t,r,y,u,x]});var w=E.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex(w,D,o,s)},newEncryptedPKCS5PEM:function(o,p,s,t){if(typeof p=="undefined"||p==null){p=1024}if(typeof s=="undefined"||s==null){s="10001"}var q=new RSAKey();q.generate(p,s);var r=null;if(typeof t=="undefined"||t==null){r=this.getEncryptedPKCS5PEMFromRSAKey(pkey,o)}else{r=this.getEncryptedPKCS5PEMFromRSAKey(pkey,o,t)}return r},getRSAKeyFromPlainPKCS8PEM:function(q){if(q.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var p=ASN1HEX.pemToHex(q,"PRIVATE KEY");var o=this.getRSAKeyFromPlainPKCS8Hex(p);return o},getRSAKeyFromPlainPKCS8Hex:function(p){var o=new RSAKey();o.readPKCS8PrvKeyHex(p);return o},parseHexOfEncryptedPKCS8:function(v){var r={};var q=ASN1HEX.getPosArrayOfChildren_AtObj(v,0);if(q.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+q.length}r.ciphertext=ASN1HEX.getHexOfV_AtObj(v,q[1]);var x=ASN1HEX.getPosArrayOfChildren_AtObj(v,q[0]);if(x.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+x.length}if(ASN1HEX.getHexOfV_AtObj(v,x[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(v,x[1]);if(x.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length}var p=ASN1HEX.getPosArrayOfChildren_AtObj(v,o[1]);if(p.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+p.length}if(ASN1HEX.getHexOfV_AtObj(v,p[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}r.encryptionSchemeAlg="TripleDES";r.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(v,p[1]);var s=ASN1HEX.getPosArrayOfChildren_AtObj(v,o[0]);if(s.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+s.length}if(ASN1HEX.getHexOfV_AtObj(v,s[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var w=ASN1HEX.getPosArrayOfChildren_AtObj(v,s[1]);if(w.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+w.length}r.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(v,w[0]);var t=ASN1HEX.getHexOfV_AtObj(v,w[1]);try{r.pbkdf2Iter=parseInt(t,16)}catch(u){throw"malformed format pbkdf2Iter: "+t}return r},getPBKDF2KeyHexFromParam:function(t,o){var s=CryptoJS.enc.Hex.parse(t.pbkdf2Salt);var p=t.pbkdf2Iter;var r=CryptoJS.PBKDF2(o,s,{keySize:192/32,iterations:p});var q=CryptoJS.enc.Hex.stringify(r);return q},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(w,x){var q=ASN1HEX.pemToHex(w,"ENCRYPTED PRIVATE KEY");var o=this.parseHexOfEncryptedPKCS8(q);var t=PKCS5PKEY.getPBKDF2KeyHexFromParam(o,x);var u={};u.ciphertext=CryptoJS.enc.Hex.parse(o.ciphertext);var s=CryptoJS.enc.Hex.parse(t);var r=CryptoJS.enc.Hex.parse(o.encryptionSchemeIV);var v=CryptoJS.TripleDES.decrypt(u,s,{iv:r});var p=CryptoJS.enc.Hex.stringify(v);return p},getRSAKeyFromEncryptedPKCS8PEM:function(r,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(r,q);var o=this.getRSAKeyFromPlainPKCS8Hex(p);return o},getKeyFromEncryptedPKCS8PEM:function(r,p){var o=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(r,p);var q=this.getKeyFromPlainPrivatePKCS8Hex(o);return q},parsePlainPrivatePKCS8Hex:function(r){var p={};p.algparam=null;if(r.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(r.substr(q[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(r,q[1]);if(o.length!=2){throw"malformed PKCS8 private key(code:004)"}if(r.substr(o[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}p.algoid=ASN1HEX.getHexOfV_AtObj(r,o[0]);if(r.substr(o[1],2)=="06"){p.algparam=ASN1HEX.getHexOfV_AtObj(r,o[1])}if(r.substr(q[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}p.keyidx=ASN1HEX.getStartPosOfV_AtObj(r,q[2]);return p},getKeyFromPlainPrivatePKCS8PEM:function(p){var o=ASN1HEX.pemToHex(p,"PRIVATE KEY");var q=this.getKeyFromPlainPrivatePKCS8Hex(o);return q},getKeyFromPlainPrivatePKCS8Hex:function(o){var p=this.parsePlainPrivatePKCS8Hex(o);var q;if(p.algoid=="2a864886f70d010101"){q=new RSAKey()}else{if(p.algoid=="2a8648ce380401"){q=new KJUR.crypto.DSA()}else{if(p.algoid=="2a8648ce3d0201"){q=new KJUR.crypto.ECDSA()}else{throw"unsupported private key algorithm"}}}q.readPKCS8PrvKeyHex(o);return q},getRSAKeyFromPublicPKCS8PEM:function(p){var q=ASN1HEX.pemToHex(p,"PUBLIC KEY");var o=this.getRSAKeyFromPublicPKCS8Hex(q);return o},getKeyFromPublicPKCS8PEM:function(p){var q=ASN1HEX.pemToHex(p,"PUBLIC KEY");var o=this.getKeyFromPublicPKCS8Hex(q);return o},getKeyFromPublicPKCS8Hex:function(o){var p;var q=ASN1HEX.getVbyList(h,0,[0,0],"06");if(q==="2a864886f70d010101"){p=new RSAKey()}else{if(q==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(q==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw"unsupported PKCS#8 public key hex"}}}p.readPKCS8PubKeyHex(h);return p},parsePublicRawRSAKeyHex:function(q){var o={};if(q.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=2){throw"malformed RSA key(code:002)"}if(q.substr(p[0],2)!="02"){throw"malformed RSA key(code:003)"}o.n=ASN1HEX.getHexOfV_AtObj(q,p[0]);if(q.substr(p[1],2)!="02"){throw"malformed RSA key(code:004)"}o.e=ASN1HEX.getHexOfV_AtObj(q,p[1]);return o},parsePrivateRawRSAKeyHexAtObj:function(p,r){var q=r.keyidx;if(p.substr(q,2)!="30"){throw"malformed RSA private key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,q);if(o.length!=9){throw"malformed RSA private key(code:002)"}r.key={};r.key.n=ASN1HEX.getHexOfV_AtObj(p,o[1]);r.key.e=ASN1HEX.getHexOfV_AtObj(p,o[2]);r.key.d=ASN1HEX.getHexOfV_AtObj(p,o[3]);r.key.p=ASN1HEX.getHexOfV_AtObj(p,o[4]);r.key.q=ASN1HEX.getHexOfV_AtObj(p,o[5]);r.key.dp=ASN1HEX.getHexOfV_AtObj(p,o[6]);r.key.dq=ASN1HEX.getHexOfV_AtObj(p,o[7]);r.key.co=ASN1HEX.getHexOfV_AtObj(p,o[8])},parsePrivateRawECKeyHexAtObj:function(p,r){var q=r.keyidx;if(p.substr(q,2)!="30"){throw"malformed ECC private key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,q);if(o.length!=3){throw"malformed ECC private key(code:002)"}if(p.substr(o[1],2)!="04"){throw"malformed ECC private key(code:003)"}r.key=ASN1HEX.getHexOfV_AtObj(p,o[1])},parsePublicPKCS8Hex:function(r){var p={};p.algparam=null;var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"outer DERSequence shall have 2 elements: "+q.length}var s=q[0];if(r.substr(s,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(r,s);if(o.length!=2){throw"malformed PKCS8 public key(code:002)"}if(r.substr(o[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}p.algoid=ASN1HEX.getHexOfV_AtObj(r,o[0]);if(r.substr(o[1],2)=="06"){p.algparam=ASN1HEX.getHexOfV_AtObj(r,o[1])}if(r.substr(q[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}p.key=ASN1HEX.getHexOfV_AtObj(r,q[1]).substr(2);return p},getRSAKeyFromPublicPKCS8Hex:function(o){var p=new RSAKey();p.readPKCS8PubKeyHex(o);return p},}}(); \ No newline at end of file diff --git a/min/rsapem-1.1.min.js b/min/rsapem-1.1.min.js index 7eb760d2..0ef4e6ef 100644 --- a/min/rsapem-1.1.min.js +++ b/min/rsapem-1.1.min.js @@ -1,3 +1,3 @@ -/*! rsapem-1.1.js (c) 2012 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! rsapem-1.2.0.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -function _rsapem_pemToBase64(b){var a=b;a=a.replace("-----BEGIN RSA PRIVATE KEY-----","");a=a.replace("-----END RSA PRIVATE KEY-----","");a=a.replace(/[ \n]+/g,"");return a}function _rsapem_getPosArrayOfChildrenFromHex(d){var j=new Array();var k=ASN1HEX.getStartPosOfV_AtObj(d,0);var f=ASN1HEX.getPosOfNextSibling_AtObj(d,k);var h=ASN1HEX.getPosOfNextSibling_AtObj(d,f);var b=ASN1HEX.getPosOfNextSibling_AtObj(d,h);var l=ASN1HEX.getPosOfNextSibling_AtObj(d,b);var e=ASN1HEX.getPosOfNextSibling_AtObj(d,l);var g=ASN1HEX.getPosOfNextSibling_AtObj(d,e);var c=ASN1HEX.getPosOfNextSibling_AtObj(d,g);var i=ASN1HEX.getPosOfNextSibling_AtObj(d,c);j.push(k,f,h,b,l,e,g,c,i);return j}function _rsapem_getHexValueArrayOfChildrenFromHex(i){var o=_rsapem_getPosArrayOfChildrenFromHex(i);var r=ASN1HEX.getHexOfV_AtObj(i,o[0]);var f=ASN1HEX.getHexOfV_AtObj(i,o[1]);var j=ASN1HEX.getHexOfV_AtObj(i,o[2]);var k=ASN1HEX.getHexOfV_AtObj(i,o[3]);var c=ASN1HEX.getHexOfV_AtObj(i,o[4]);var b=ASN1HEX.getHexOfV_AtObj(i,o[5]);var h=ASN1HEX.getHexOfV_AtObj(i,o[6]);var g=ASN1HEX.getHexOfV_AtObj(i,o[7]);var l=ASN1HEX.getHexOfV_AtObj(i,o[8]);var m=new Array();m.push(r,f,j,k,c,b,h,g,l);return m}function _rsapem_readPrivateKeyFromASN1HexString(c){var b=_rsapem_getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])}function _rsapem_readPrivateKeyFromPEMString(e){var c=_rsapem_pemToBase64(e);var d=b64tohex(c);var b=_rsapem_getHexValueArrayOfChildrenFromHex(d);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])}RSAKey.prototype.readPrivateKeyFromPEMString=_rsapem_readPrivateKeyFromPEMString;RSAKey.prototype.readPrivateKeyFromASN1HexString=_rsapem_readPrivateKeyFromASN1HexString; \ No newline at end of file +RSAKey.pemToBase64=function(b){var a=b;a=a.replace("-----BEGIN RSA PRIVATE KEY-----","");a=a.replace("-----END RSA PRIVATE KEY-----","");a=a.replace(/[ \n]+/g,"");return a};RSAKey.getPosArrayOfChildrenFromHex=function(g){var j=new Array();var i=ASN1HEX.getStartPosOfV_AtObj(g,0);var b=ASN1HEX.getPosOfNextSibling_AtObj(g,i);var e=ASN1HEX.getPosOfNextSibling_AtObj(g,b);var f=ASN1HEX.getPosOfNextSibling_AtObj(g,e);var l=ASN1HEX.getPosOfNextSibling_AtObj(g,f);var k=ASN1HEX.getPosOfNextSibling_AtObj(g,l);var d=ASN1HEX.getPosOfNextSibling_AtObj(g,k);var c=ASN1HEX.getPosOfNextSibling_AtObj(g,d);var h=ASN1HEX.getPosOfNextSibling_AtObj(g,c);j.push(i,b,e,f,l,k,d,c,h);return j};RSAKey.getHexValueArrayOfChildrenFromHex=function(f){var l=RSAKey.getPosArrayOfChildrenFromHex(f);var e=ASN1HEX.getHexOfV_AtObj(f,l[0]);var j=ASN1HEX.getHexOfV_AtObj(f,l[1]);var b=ASN1HEX.getHexOfV_AtObj(f,l[2]);var c=ASN1HEX.getHexOfV_AtObj(f,l[3]);var h=ASN1HEX.getHexOfV_AtObj(f,l[4]);var g=ASN1HEX.getHexOfV_AtObj(f,l[5]);var m=ASN1HEX.getHexOfV_AtObj(f,l[6]);var k=ASN1HEX.getHexOfV_AtObj(f,l[7]);var d=ASN1HEX.getHexOfV_AtObj(f,l[8]);var i=new Array();i.push(e,j,b,c,h,g,m,k,d);return i};RSAKey.prototype.readPrivateKeyFromPEMString=function(e){var c=RSAKey.pemToBase64(e);var d=b64tohex(c);var b=RSAKey.getHexValueArrayOfChildrenFromHex(d);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPrivateKeyFromASN1HexString=function(a){this.readPKCS5PrvKeyHex(a)};RSAKey.prototype.readPKCS5PrvKeyHex=function(c){var b=RSAKey.getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPKCS8PrvKeyHex=function(e){var c,j,l,b,a,f,d,k;var m=ASN1HEX;var g=m.getVbyList;if(m.isASN1HEX(e)===false){throw"not ASN.1 hex string"}try{c=g(e,0,[2,0,1],"02");j=g(e,0,[2,0,2],"02");l=g(e,0,[2,0,3],"02");b=g(e,0,[2,0,4],"02");a=g(e,0,[2,0,5],"02");f=g(e,0,[2,0,6],"02");d=g(e,0,[2,0,7],"02");k=g(e,0,[2,0,8],"02")}catch(i){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(c,j,l,b,a,f,d,k)};RSAKey.prototype.readPKCS5PubKeyHex=function(b){if(ASN1HEX.isASN1HEX(b)===false){throw"keyHex is not ASN.1 hex string"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(b,0);if(a.length!==2||b.substr(a[0],2)!=="02"||b.substr(a[1],2)!=="02"){throw"wrong hex for PKCS#5 public key"}var d=ASN1HEX.getHexOfV_AtObj(b,a[0]);var c=ASN1HEX.getHexOfV_AtObj(b,a[1]);this.setPublic(d,c)};RSAKey.prototype.readPKCS8PubKeyHex=function(b){if(ASN1HEX.isASN1HEX(b)===false){throw"not ASN.1 hex string"}if(ASN1HEX.getDecendantHexTLVByNthList(b,0,[0,0])!=="06092a864886f70d010101"){throw"not PKCS8 RSA public key"}var a=ASN1HEX.getDecendantHexTLVByNthList(b,0,[1,0]);this.readPKCS5PubKeyHex(a)};RSAKey.prototype.readCertPubKeyHex=function(b,c){if(c!==5){c=6}if(ASN1HEX.isASN1HEX(b)===false){throw"not ASN.1 hex string"}var a=ASN1HEX.getDecendantHexTLVByNthList(b,0,[0,c]);this.readPKCS8PubKeyHex(a)}; \ No newline at end of file diff --git a/min/x509-1.1.min.js b/min/x509-1.1.min.js index af15c3bc..adb8bd9c 100644 --- a/min/x509-1.1.min.js +++ b/min/x509-1.1.min.js @@ -1,3 +1,3 @@ -/*! x509-1.1.10.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! x509-1.1.11.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -function X509(){this.subjectPublicKeyRSA=null;this.subjectPublicKeyRSA_hN=null;this.subjectPublicKeyRSA_hE=null;this.hex=null;this.getSerialNumberHex=function(){return ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,1])};this.getSignatureAlgorithmField=function(){var b=ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,2,0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(b);var c=KJUR.asn1.x509.OID.oid2name(a);return c};this.getIssuerHex=function(){return ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,3])};this.getIssuerString=function(){return X509.hex2dn(ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,3]))};this.getSubjectHex=function(){return ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,5])};this.getSubjectString=function(){return X509.hex2dn(ASN1HEX.getDecendantHexTLVByNthList(this.hex,0,[0,5]))};this.getNotBefore=function(){var a=ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,4,0]);a=a.replace(/(..)/g,"%$1");a=decodeURIComponent(a);return a};this.getNotAfter=function(){var a=ASN1HEX.getDecendantHexVByNthList(this.hex,0,[0,4,1]);a=a.replace(/(..)/g,"%$1");a=decodeURIComponent(a);return a};this.readCertPEM=function(c){var e=X509.pemToHex(c);var b=X509.getPublicKeyHexArrayFromCertHex(e);var d=new RSAKey();d.setPublic(b[0],b[1]);this.subjectPublicKeyRSA=d;this.subjectPublicKeyRSA_hN=b[0];this.subjectPublicKeyRSA_hE=b[1];this.hex=e};this.readCertPEMWithoutRSAInit=function(c){var d=X509.pemToHex(c);var b=X509.getPublicKeyHexArrayFromCertHex(d);if(typeof this.subjectPublicKeyRSA.setPublic==="function"){this.subjectPublicKeyRSA.setPublic(b[0],b[1])}this.subjectPublicKeyRSA_hN=b[0];this.subjectPublicKeyRSA_hE=b[1];this.hex=d};this.getInfo=function(){var p="Basic Fields\n";p+=" serial number: "+this.getSerialNumberHex()+"\n";p+=" signature algorithm: "+this.getSignatureAlgorithmField()+"\n";p+=" issuer: "+this.getIssuerString()+"\n";p+=" notBefore: "+this.getNotBefore()+"\n";p+=" notAfter: "+this.getNotAfter()+"\n";p+=" subject: "+this.getSubjectString()+"\n";p+=" subject public key info: \n";var j=X509.getSubjectPublicKeyInfoPosFromCertHex(this.hex);var d=ASN1HEX.getHexOfTLV_AtObj(this.hex,j);var n=KEYUTIL.getKey(d,null,"pkcs8pub");if(n instanceof RSAKey){p+=" key algorithm: RSA\n";p+=" n="+n.n.toString(16).substr(0,16)+"...\n";p+=" e="+n.e.toString(16)+"\n"}p+="X509v3 Extensions:\n";var m=X509.getV3ExtInfoListOfCertHex(this.hex);for(var e=0;e>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}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"; +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{throw"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}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; +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;this.isPublic=false;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; @@ -235,24 +235,24 @@ var jsonParse=(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][ /*! asn1-1.0.12.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license */ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+i.toString(16)}var f=128+g;return f.toString(16)+h}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(this.s)};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};YAHOO.lang.extend(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(f){utc=f.getTime()+(f.getTimezoneOffset()*60000);var e=new Date(utc);return e};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};YAHOO.lang.extend(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};YAHOO.lang.extend(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";this.hTLV="0101ff"};YAHOO.lang.extend(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};YAHOO.lang.extend(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=(b*2))){break}if(d>=200){break}c.push(e);g=e;d++}return c};ASN1HEX.getNthChildIndex_AtObj=function(d,b,e){var c=ASN1HEX.getPosArrayOfChildren_AtObj(d,b);return c[e]};ASN1HEX.getDecendantIndexByNthList=function(e,d,c){if(c.length==0){return d}var f=c.shift();var b=ASN1HEX.getPosArrayOfChildren_AtObj(e,d);return ASN1HEX.getDecendantIndexByNthList(e,b[f],c)};ASN1HEX.getDecendantHexTLVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfTLV_AtObj(d,a)};ASN1HEX.getDecendantHexVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.getVbyList=function(d,c,b,e){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);if(a===undefined){throw"can't find nthList object"}if(e!==undefined){if(d.substr(a,2)!=e){throw"checking tag doesn't match: "+d.substr(a,2)+"!="+e}}return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(q,c,k,g){var e=q;if(q instanceof KJUR.asn1.ASN1Object){e=q.getEncodedHex()}var o=function(x,i){if(x.length<=i*2){return x}else{var v=x.substr(0,i)+"..(total "+x.length/2+"bytes).."+x.substr(x.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(k===undefined){k=0}if(g===undefined){g=""}var t=c.ommit_long_octet;if(e.substr(k,2)=="01"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(e.substr(k,2)=="02"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"INTEGER "+o(h,t)+"\n"}if(e.substr(k,2)=="03"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"BITSTRING "+o(h,t)+"\n"}if(e.substr(k,2)=="04"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(ASN1HEX.isASN1HEX(h)){var j=g+"OCTETSTRING, encapsulates\n";j=j+ASN1HEX.dump(h,c,0,g+" ");return j}else{return g+"OCTETSTRING "+o(h,t)+"\n"}}if(e.substr(k,2)=="05"){return g+"NULL\n"}if(e.substr(k,2)=="06"){var l=ASN1HEX.getHexOfV_AtObj(e,k);var a=KJUR.asn1.ASN1Util.oidHexToInt(l);var n=KJUR.asn1.x509.OID.oid2name(a);var b=a.replace(/\./g," ");if(n!=""){return g+"ObjectIdentifier "+n+" ("+b+")\n"}else{return g+"ObjectIdentifier ("+b+")\n"}}if(e.substr(k,2)=="0c"){return g+"UTF8String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="13"){return g+"PrintableString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="14"){return g+"TeletexString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="16"){return g+"IA5String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="17"){return g+"UTCTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="18"){return g+"GeneralizedTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="30"){if(e.substr(k,4)=="3000"){return g+"SEQUENCE {}\n"}var j=g+"SEQUENCE\n";var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,k);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var u=ASN1HEX.getHexOfV_AtObj(e,d[0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(u);var n=KJUR.asn1.x509.OID.oid2name(a);var p=JSON.parse(JSON.stringify(c));p.x509ExtName=n;f=p}for(var r=0;r=(b*2))){break}if(d>=200){break}c.push(e);g=e;d++}return c};ASN1HEX.getNthChildIndex_AtObj=function(d,b,e){var c=ASN1HEX.getPosArrayOfChildren_AtObj(d,b);return c[e]};ASN1HEX.getDecendantIndexByNthList=function(e,d,c){if(c.length==0){return d}var f=c.shift();var b=ASN1HEX.getPosArrayOfChildren_AtObj(e,d);return ASN1HEX.getDecendantIndexByNthList(e,b[f],c)};ASN1HEX.getDecendantHexTLVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfTLV_AtObj(d,a)};ASN1HEX.getDecendantHexVByNthList=function(d,c,b){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.getVbyList=function(d,c,b,e){var a=ASN1HEX.getDecendantIndexByNthList(d,c,b);if(a===undefined){throw"can't find nthList object"}if(e!==undefined){if(d.substr(a,2)!=e){throw"checking tag doesn't match: "+d.substr(a,2)+"!="+e}}return ASN1HEX.getHexOfV_AtObj(d,a)};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(q,c,k,g){var e=q;if(q instanceof KJUR.asn1.ASN1Object){e=q.getEncodedHex()}var o=function(x,i){if(x.length<=i*2){return x}else{var v=x.substr(0,i)+"..(total "+x.length/2+"bytes).."+x.substr(x.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(k===undefined){k=0}if(g===undefined){g=""}var t=c.ommit_long_octet;if(e.substr(k,2)=="01"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(e.substr(k,2)=="02"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"INTEGER "+o(h,t)+"\n"}if(e.substr(k,2)=="03"){var h=ASN1HEX.getHexOfV_AtObj(e,k);return g+"BITSTRING "+o(h,t)+"\n"}if(e.substr(k,2)=="04"){var h=ASN1HEX.getHexOfV_AtObj(e,k);if(ASN1HEX.isASN1HEX(h)){var j=g+"OCTETSTRING, encapsulates\n";j=j+ASN1HEX.dump(h,c,0,g+" ");return j}else{return g+"OCTETSTRING "+o(h,t)+"\n"}}if(e.substr(k,2)=="05"){return g+"NULL\n"}if(e.substr(k,2)=="06"){var l=ASN1HEX.getHexOfV_AtObj(e,k);var a=KJUR.asn1.ASN1Util.oidHexToInt(l);var n=KJUR.asn1.x509.OID.oid2name(a);var b=a.replace(/\./g," ");if(n!=""){return g+"ObjectIdentifier "+n+" ("+b+")\n"}else{return g+"ObjectIdentifier ("+b+")\n"}}if(e.substr(k,2)=="0c"){return g+"UTF8String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="13"){return g+"PrintableString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="14"){return g+"TeletexString '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="16"){return g+"IA5String '"+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"'\n"}if(e.substr(k,2)=="17"){return g+"UTCTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="18"){return g+"GeneralizedTime "+hextoutf8(ASN1HEX.getHexOfV_AtObj(e,k))+"\n"}if(e.substr(k,2)=="30"){if(e.substr(k,4)=="3000"){return g+"SEQUENCE {}\n"}var j=g+"SEQUENCE\n";var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,k);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var u=ASN1HEX.getHexOfV_AtObj(e,d[0]);var a=KJUR.asn1.ASN1Util.oidHexToInt(u);var n=KJUR.asn1.x509.OID.oid2name(a);var p=JSON.parse(JSON.stringify(c));p.x509ExtName=n;f=p}for(var r=0;r0){var d=new KJUR.asn1.DERSequence({array:this.extensionsArray});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a3",obj:d});this.asn1Array.push(b)}var e=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=e.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension=function(b){KJUR.asn1.x509.Extension.superclass.constructor.call(this);var a=null;this.getEncodedHex=function(){var f=new KJUR.asn1.DERObjectIdentifier({oid:this.oid});var e=new KJUR.asn1.DEROctetString({hex:this.getExtnValueHex()});var d=new Array();d.push(f);if(this.critical){d.push(new KJUR.asn1.DERBoolean())}d.push(e);var c=new KJUR.asn1.DERSequence({array:d});return c.getEncodedHex()};this.critical=false;if(typeof b!="undefined"){if(typeof b.critical!="undefined"){this.critical=b.critical}}};YAHOO.lang.extend(KJUR.asn1.x509.Extension,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension.appendByNameToArray=function(e,c,b){if(e.toLowerCase()=="basicconstraints"){var d=new KJUR.asn1.x509.BasicConstraints(c);b.push(d)}else{if(e.toLowerCase()=="keyusage"){var d=new KJUR.asn1.x509.KeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="crldistributionpoints"){var d=new KJUR.asn1.x509.CRLDistributionPoints(c);b.push(d)}else{if(e.toLowerCase()=="extkeyusage"){var d=new KJUR.asn1.x509.ExtKeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="authoritykeyidentifier"){var d=new KJUR.asn1.x509.AuthorityKeyIdentifier(c);b.push(d)}else{if(e.toLowerCase()=="authorityinfoaccess"){var d=new KJUR.asn1.x509.AuthorityInfoAccess(c);b.push(d)}else{if(e.toLowerCase()=="subjectaltname"){var d=new KJUR.asn1.x509.SubjectAltName(c);b.push(d)}else{if(e.toLowerCase()=="issueraltname"){var d=new KJUR.asn1.x509.IssuerAltName(c);b.push(d)}else{throw"unsupported extension name: "+e}}}}}}}}};KJUR.asn1.x509.KeyUsage=function(a){KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.15";if(typeof a!="undefined"){if(typeof a.bin!="undefined"){this.asn1ExtnValue=new KJUR.asn1.DERBitString(a)}}};YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage,KJUR.asn1.x509.Extension);KJUR.asn1.x509.BasicConstraints=function(c){KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this,c);var a=false;var b=-1;this.getExtnValueHex=function(){var e=new Array();if(this.cA){e.push(new KJUR.asn1.DERBoolean())}if(this.pathLen>-1){e.push(new KJUR.asn1.DERInteger({"int":this.pathLen}))}var d=new KJUR.asn1.DERSequence({array:e});this.asn1ExtnValue=d;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(typeof c!="undefined"){if(typeof c.cA!="undefined"){this.cA=c.cA}if(typeof c.pathLen!="undefined"){this.pathLen=c.pathLen}}};YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(a){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence({array:b})};this.setByOneURI=function(e){var b=new KJUR.asn1.x509.GeneralNames([{uri:e}]);var d=new KJUR.asn1.x509.DistributionPointName(b);var c=new KJUR.asn1.x509.DistributionPoint({dpobj:d});this.setByDPArray([c])};this.oid="2.5.29.31";if(typeof a!="undefined"){if(typeof a.array!="undefined"){this.setByDPArray(a.array)}else{if(typeof a.uri!="undefined"){this.setByOneURI(a.uri)}}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.ExtKeyUsage=function(a){KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,a);this.setPurposeArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence();for(var c=0;c0){var c=new KJUR.asn1.DERSequence({array:this.aRevokedCert});this.asn1Array.push(c)}var d=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=d.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize=function(){this.asn1Version=null;this.asn1SignatureAlg=null;this.asn1Issuer=null;this.asn1ThisUpdate=null;this.asn1NextUpdate=null;this.aRevokedCert=new Array()};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList,KJUR.asn1.ASN1Object);KJUR.asn1.x509.CRLEntry=function(c){KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this);var b=null;var a=null;this.setCertSerial=function(d){this.sn=new KJUR.asn1.DERInteger(d)};this.setRevocationDate=function(d){this.time=new KJUR.asn1.x509.Time(d)};this.getEncodedHex=function(){var d=new KJUR.asn1.DERSequence({array:[this.sn,this.time]});this.TLV=d.getEncodedHex();return this.TLV};if(typeof c!="undefined"){if(typeof c.time!="undefined"){this.setRevocationDate(c.time)}if(typeof c.sn!="undefined"){this.setCertSerial(c.sn)}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry,KJUR.asn1.ASN1Object);KJUR.asn1.x509.X500Name=function(b){KJUR.asn1.x509.X500Name.superclass.constructor.call(this);this.asn1Array=new Array();this.setByString=function(c){var d=c.split("/");d.shift();for(var e=0;e0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.RDN=function(a){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=new Array();this.addByString=function(b){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:b}))};this.addByMultiValuedString=function(d){var b=KJUR.asn1.x509.RDN.parseString(d);for(var c=0;c0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(b){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var d=null;var c=null;var a="utf8";this.setByString=function(f){var e=f.match(/^([^=]+)=(.+)$/);if(e){this.setByAttrTypeAndValueStr(e[1],e[2])}else{throw"malformed attrTypeAndValueStr: "+f}};this.setByAttrTypeAndValueStr=function(g,f){this.typeObj=KJUR.asn1.x509.OID.atype2obj(g);var e=a;if(g=="C"){e="prn"}this.valueObj=this.getValueObj(e,f)};this.getValueObj=function(f,e){if(f=="utf8"){return new KJUR.asn1.DERUTF8String({str:e})}if(f=="prn"){return new KJUR.asn1.DERPrintableString({str:e})}if(f=="tel"){return new KJUR.asn1.DERTeletexString({str:e})}if(f=="ia5"){return new KJUR.asn1.DERIA5String({str:e})}throw"unsupported directory string type: type="+f+" value="+e};this.getEncodedHex=function(){var e=new KJUR.asn1.DERSequence({array:[this.typeObj,this.valueObj]});this.TLV=e.getEncodedHex();return this.TLV};if(typeof b!="undefined"){if(typeof b.str!="undefined"){this.setByString(b.str)}}};YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(d){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var b=null;var c=null;var a=null;this.setRSAKey=function(e){if(!RSAKey.prototype.isPrototypeOf(e)){throw"argument is not RSAKey instance"}this.rsaKey=e;var g=new KJUR.asn1.DERInteger({bigint:e.n});var f=new KJUR.asn1.DERInteger({"int":e.e});var i=new KJUR.asn1.DERSequence({array:[g,f]});var h=i.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+h})};this.setRSAPEM=function(g){if(g.match(/-----BEGIN PUBLIC KEY-----/)){var n=g;n=n.replace(/^-----[^-]+-----/,"");n=n.replace(/-----[^-]+-----\s*$/,"");var m=n.replace(/\s+/g,"");var f=CryptoJS.enc.Base64.parse(m);var i=CryptoJS.enc.Hex.stringify(f);var k=_rsapem_getHexValueArrayOfChildrenFromHex(i);var h=k[1];var l=h.substr(2);var e=_rsapem_getHexValueArrayOfChildrenFromHex(l);var j=new RSAKey();j.setPublic(e[0],e[1]);this.setRSAKey(j)}else{throw"key not supported"}};this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var e=new KJUR.asn1.DERSequence({array:[this.asn1AlgId,this.asn1SubjPKey]});return e};this.getEncodedHex=function(){var e=this.getASN1Object();this.hTLV=e.getEncodedHex();return this.hTLV};this._setRSAKey=function(e){var g=KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.n}},{"int":{"int":e.e}}]});var f=g.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+f})};this._setEC=function(e){var f=new KJUR.asn1.DERObjectIdentifier({name:e.curveName});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"ecPublicKey",asn1params:f});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+e.pubKeyHex})};this._setDSA=function(e){var f=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.p}},{"int":{bigint:e.q}},{"int":{bigint:e.g}}]});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"dsa",asn1params:f});var g=new KJUR.asn1.DERInteger({bigint:e.y});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+g.getEncodedHex()})};if(typeof d!="undefined"){if(typeof RSAKey!="undefined"&&d instanceof RSAKey){this._setRSAKey(d)}else{if(typeof KJUR.crypto.ECDSA!="undefined"&&d instanceof KJUR.crypto.ECDSA){this._setEC(d)}else{if(typeof KJUR.crypto.DSA!="undefined"&&d instanceof KJUR.crypto.DSA){this._setDSA(d)}else{if(typeof d.rsakey!="undefined"){this.setRSAKey(d.rsakey)}else{if(typeof d.rsapem!="undefined"){this.setRSAPEM(d.rsapem)}}}}}}};YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(c){KJUR.asn1.x509.Time.superclass.constructor.call(this);var b=null;var a=null;this.setTimeParams=function(d){this.timeParams=d};this.getEncodedHex=function(){var d=null;if(this.timeParams!=null){if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime(this.timeParams)}else{d=new KJUR.asn1.DERGeneralizedTime(this.timeParams)}}else{if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime()}else{d=new KJUR.asn1.DERGeneralizedTime()}}this.TLV=d.getEncodedHex();return this.TLV};this.type="utc";if(typeof c!="undefined"){if(typeof c.type!="undefined"){this.type=c.type}else{if(typeof c.str!="undefined"){if(c.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(c.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=c}};YAHOO.lang.extend(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);var a=null;var d=null;var b=null;var c=false;this.getEncodedHex=function(){if(this.nameAlg==null&&this.asn1Alg==null){throw"algorithm not specified"}if(this.nameAlg!=null&&this.asn1Alg==null){this.asn1Alg=KJUR.asn1.x509.OID.name2obj(this.nameAlg)}var f=[this.asn1Alg];if(!this.paramEmpty){f.push(this.asn1Params)}var g=new KJUR.asn1.DERSequence({array:f});this.hTLV=g.getEncodedHex();return this.hTLV};if(typeof e!="undefined"){if(typeof e.name!="undefined"){this.nameAlg=e.name}if(typeof e.asn1params!="undefined"){this.asn1Params=e.asn1params}if(typeof e.paramempty!="undefined"){this.paramEmpty=e.paramempty}}if(this.asn1Params==null){this.asn1Params=new KJUR.asn1.DERNull()}};YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralName=function(d){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var c=null;var b=null;var a={rfc822:"81",dns:"82",dn:"a4",uri:"86"};this.explicit=false;this.setByParam=function(k){var j=null;var g=null;if(k===undefined){return}if(k.rfc822!==undefined){this.type="rfc822";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dns!==undefined){this.type="dns";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.uri!==undefined){this.type="uri";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({str:k.dn})}if(k.ldapdn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({ldapstr:k.ldapdn})}if(k.certissuer!==undefined){this.type="dn";this.explicit=true;var h=k.certissuer;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=X509.pemToHex(h)}if(f==null){throw"certissuer param not cert"}var e=new X509();e.hex=f;var i=e.getIssuerHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(k.certsubj!==undefined){this.type="dn";this.explicit=true;var h=k.certsubj;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=X509.pemToHex(h)}if(f==null){throw"certsubj param not cert"}var e=new X509();e.hex=f;var i=e.getSubjectHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(this.type==null){throw"unsupported type in params="+k}this.asn1Obj=new KJUR.asn1.DERTaggedObject({explicit:this.explicit,tag:a[this.type],obj:g})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(d!==undefined){this.setByParam(d)}};YAHOO.lang.extend(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(b){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null;this.setByParamArray=function(e){for(var c=0;c0){var d=new KJUR.asn1.DERSequence({array:this.extensionsArray});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a3",obj:d});this.asn1Array.push(b)}var e=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=e.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension=function(b){KJUR.asn1.x509.Extension.superclass.constructor.call(this);var a=null;this.getEncodedHex=function(){var f=new KJUR.asn1.DERObjectIdentifier({oid:this.oid});var e=new KJUR.asn1.DEROctetString({hex:this.getExtnValueHex()});var d=new Array();d.push(f);if(this.critical){d.push(new KJUR.asn1.DERBoolean())}d.push(e);var c=new KJUR.asn1.DERSequence({array:d});return c.getEncodedHex()};this.critical=false;if(typeof b!="undefined"){if(typeof b.critical!="undefined"){this.critical=b.critical}}};YAHOO.lang.extend(KJUR.asn1.x509.Extension,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extension.appendByNameToArray=function(e,c,b){if(e.toLowerCase()=="basicconstraints"){var d=new KJUR.asn1.x509.BasicConstraints(c);b.push(d)}else{if(e.toLowerCase()=="keyusage"){var d=new KJUR.asn1.x509.KeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="crldistributionpoints"){var d=new KJUR.asn1.x509.CRLDistributionPoints(c);b.push(d)}else{if(e.toLowerCase()=="extkeyusage"){var d=new KJUR.asn1.x509.ExtKeyUsage(c);b.push(d)}else{if(e.toLowerCase()=="authoritykeyidentifier"){var d=new KJUR.asn1.x509.AuthorityKeyIdentifier(c);b.push(d)}else{if(e.toLowerCase()=="authorityinfoaccess"){var d=new KJUR.asn1.x509.AuthorityInfoAccess(c);b.push(d)}else{if(e.toLowerCase()=="subjectaltname"){var d=new KJUR.asn1.x509.SubjectAltName(c);b.push(d)}else{if(e.toLowerCase()=="issueraltname"){var d=new KJUR.asn1.x509.IssuerAltName(c);b.push(d)}else{throw"unsupported extension name: "+e}}}}}}}}};KJUR.asn1.x509.KeyUsage=function(a){KJUR.asn1.x509.KeyUsage.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.15";if(typeof a!="undefined"){if(typeof a.bin!="undefined"){this.asn1ExtnValue=new KJUR.asn1.DERBitString(a)}}};YAHOO.lang.extend(KJUR.asn1.x509.KeyUsage,KJUR.asn1.x509.Extension);KJUR.asn1.x509.BasicConstraints=function(c){KJUR.asn1.x509.BasicConstraints.superclass.constructor.call(this,c);var a=false;var b=-1;this.getExtnValueHex=function(){var e=new Array();if(this.cA){e.push(new KJUR.asn1.DERBoolean())}if(this.pathLen>-1){e.push(new KJUR.asn1.DERInteger({"int":this.pathLen}))}var d=new KJUR.asn1.DERSequence({array:e});this.asn1ExtnValue=d;return this.asn1ExtnValue.getEncodedHex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(typeof c!="undefined"){if(typeof c.cA!="undefined"){this.cA=c.cA}if(typeof c.pathLen!="undefined"){this.pathLen=c.pathLen}}};YAHOO.lang.extend(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(a){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,a);this.getExtnValueHex=function(){return this.asn1ExtnValue.getEncodedHex()};this.setByDPArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence({array:b})};this.setByOneURI=function(e){var b=new KJUR.asn1.x509.GeneralNames([{uri:e}]);var d=new KJUR.asn1.x509.DistributionPointName(b);var c=new KJUR.asn1.x509.DistributionPoint({dpobj:d});this.setByDPArray([c])};this.oid="2.5.29.31";if(typeof a!="undefined"){if(typeof a.array!="undefined"){this.setByDPArray(a.array)}else{if(typeof a.uri!="undefined"){this.setByOneURI(a.uri)}}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLDistributionPoints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.ExtKeyUsage=function(a){KJUR.asn1.x509.ExtKeyUsage.superclass.constructor.call(this,a);this.setPurposeArray=function(b){this.asn1ExtnValue=new KJUR.asn1.DERSequence();for(var c=0;c0){var c=new KJUR.asn1.DERSequence({array:this.aRevokedCert});this.asn1Array.push(c)}var d=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=d.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize=function(){this.asn1Version=null;this.asn1SignatureAlg=null;this.asn1Issuer=null;this.asn1ThisUpdate=null;this.asn1NextUpdate=null;this.aRevokedCert=new Array()};this._initialize()};YAHOO.lang.extend(KJUR.asn1.x509.TBSCertList,KJUR.asn1.ASN1Object);KJUR.asn1.x509.CRLEntry=function(c){KJUR.asn1.x509.CRLEntry.superclass.constructor.call(this);var b=null;var a=null;this.setCertSerial=function(d){this.sn=new KJUR.asn1.DERInteger(d)};this.setRevocationDate=function(d){this.time=new KJUR.asn1.x509.Time(d)};this.getEncodedHex=function(){var d=new KJUR.asn1.DERSequence({array:[this.sn,this.time]});this.TLV=d.getEncodedHex();return this.TLV};if(typeof c!="undefined"){if(typeof c.time!="undefined"){this.setRevocationDate(c.time)}if(typeof c.sn!="undefined"){this.setCertSerial(c.sn)}}};YAHOO.lang.extend(KJUR.asn1.x509.CRLEntry,KJUR.asn1.ASN1Object);KJUR.asn1.x509.X500Name=function(b){KJUR.asn1.x509.X500Name.superclass.constructor.call(this);this.asn1Array=new Array();this.setByString=function(c){var d=c.split("/");d.shift();for(var e=0;e0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.RDN=function(a){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=new Array();this.addByString=function(b){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:b}))};this.addByMultiValuedString=function(d){var b=KJUR.asn1.x509.RDN.parseString(d);for(var c=0;c0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(b){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);var d=null;var c=null;var a="utf8";this.setByString=function(f){var e=f.match(/^([^=]+)=(.+)$/);if(e){this.setByAttrTypeAndValueStr(e[1],e[2])}else{throw"malformed attrTypeAndValueStr: "+f}};this.setByAttrTypeAndValueStr=function(g,f){this.typeObj=KJUR.asn1.x509.OID.atype2obj(g);var e=a;if(g=="C"){e="prn"}this.valueObj=this.getValueObj(e,f)};this.getValueObj=function(f,e){if(f=="utf8"){return new KJUR.asn1.DERUTF8String({str:e})}if(f=="prn"){return new KJUR.asn1.DERPrintableString({str:e})}if(f=="tel"){return new KJUR.asn1.DERTeletexString({str:e})}if(f=="ia5"){return new KJUR.asn1.DERIA5String({str:e})}throw"unsupported directory string type: type="+f+" value="+e};this.getEncodedHex=function(){var e=new KJUR.asn1.DERSequence({array:[this.typeObj,this.valueObj]});this.TLV=e.getEncodedHex();return this.TLV};if(typeof b!="undefined"){if(typeof b.str!="undefined"){this.setByString(b.str)}}};YAHOO.lang.extend(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(d){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var b=null;var c=null;var a=null;this.setRSAKey=function(e){if(!RSAKey.prototype.isPrototypeOf(e)){throw"argument is not RSAKey instance"}this.rsaKey=e;var g=new KJUR.asn1.DERInteger({bigint:e.n});var f=new KJUR.asn1.DERInteger({"int":e.e});var i=new KJUR.asn1.DERSequence({array:[g,f]});var h=i.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+h})};this.setRSAPEM=function(g){if(g.match(/-----BEGIN PUBLIC KEY-----/)){var n=g;n=n.replace(/^-----[^-]+-----/,"");n=n.replace(/-----[^-]+-----\s*$/,"");var m=n.replace(/\s+/g,"");var f=CryptoJS.enc.Base64.parse(m);var i=CryptoJS.enc.Hex.stringify(f);var k=RSAKey.getHexValueArrayOfChildrenFromHex(i);var h=k[1];var l=h.substr(2);var e=RSAKey.getHexValueArrayOfChildrenFromHex(l);var j=new RSAKey();j.setPublic(e[0],e[1]);this.setRSAKey(j)}else{throw"key not supported"}};this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var e=new KJUR.asn1.DERSequence({array:[this.asn1AlgId,this.asn1SubjPKey]});return e};this.getEncodedHex=function(){var e=this.getASN1Object();this.hTLV=e.getEncodedHex();return this.hTLV};this._setRSAKey=function(e){var g=KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.n}},{"int":{"int":e.e}}]});var f=g.getEncodedHex();this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"rsaEncryption"});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+f})};this._setEC=function(e){var f=new KJUR.asn1.DERObjectIdentifier({name:e.curveName});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"ecPublicKey",asn1params:f});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+e.pubKeyHex})};this._setDSA=function(e){var f=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":{bigint:e.p}},{"int":{bigint:e.q}},{"int":{bigint:e.g}}]});this.asn1AlgId=new KJUR.asn1.x509.AlgorithmIdentifier({name:"dsa",asn1params:f});var g=new KJUR.asn1.DERInteger({bigint:e.y});this.asn1SubjPKey=new KJUR.asn1.DERBitString({hex:"00"+g.getEncodedHex()})};if(typeof d!="undefined"){if(typeof RSAKey!="undefined"&&d instanceof RSAKey){this._setRSAKey(d)}else{if(typeof KJUR.crypto.ECDSA!="undefined"&&d instanceof KJUR.crypto.ECDSA){this._setEC(d)}else{if(typeof KJUR.crypto.DSA!="undefined"&&d instanceof KJUR.crypto.DSA){this._setDSA(d)}else{if(typeof d.rsakey!="undefined"){this.setRSAKey(d.rsakey)}else{if(typeof d.rsapem!="undefined"){this.setRSAPEM(d.rsapem)}}}}}}};YAHOO.lang.extend(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(c){KJUR.asn1.x509.Time.superclass.constructor.call(this);var b=null;var a=null;this.setTimeParams=function(d){this.timeParams=d};this.getEncodedHex=function(){var d=null;if(this.timeParams!=null){if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime(this.timeParams)}else{d=new KJUR.asn1.DERGeneralizedTime(this.timeParams)}}else{if(this.type=="utc"){d=new KJUR.asn1.DERUTCTime()}else{d=new KJUR.asn1.DERGeneralizedTime()}}this.TLV=d.getEncodedHex();return this.TLV};this.type="utc";if(typeof c!="undefined"){if(typeof c.type!="undefined"){this.type=c.type}else{if(typeof c.str!="undefined"){if(c.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(c.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=c}};YAHOO.lang.extend(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);var a=null;var d=null;var b=null;var c=false;this.getEncodedHex=function(){if(this.nameAlg==null&&this.asn1Alg==null){throw"algorithm not specified"}if(this.nameAlg!=null&&this.asn1Alg==null){this.asn1Alg=KJUR.asn1.x509.OID.name2obj(this.nameAlg)}var f=[this.asn1Alg];if(!this.paramEmpty){f.push(this.asn1Params)}var g=new KJUR.asn1.DERSequence({array:f});this.hTLV=g.getEncodedHex();return this.hTLV};if(typeof e!="undefined"){if(typeof e.name!="undefined"){this.nameAlg=e.name}if(typeof e.asn1params!="undefined"){this.asn1Params=e.asn1params}if(typeof e.paramempty!="undefined"){this.paramEmpty=e.paramempty}}if(this.asn1Params==null){this.asn1Params=new KJUR.asn1.DERNull()}};YAHOO.lang.extend(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralName=function(d){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var c=null;var b=null;var a={rfc822:"81",dns:"82",dn:"a4",uri:"86"};this.explicit=false;this.setByParam=function(k){var j=null;var g=null;if(k===undefined){return}if(k.rfc822!==undefined){this.type="rfc822";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dns!==undefined){this.type="dns";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.uri!==undefined){this.type="uri";g=new KJUR.asn1.DERIA5String({str:k[this.type]})}if(k.dn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({str:k.dn})}if(k.ldapdn!==undefined){this.type="dn";g=new KJUR.asn1.x509.X500Name({ldapstr:k.ldapdn})}if(k.certissuer!==undefined){this.type="dn";this.explicit=true;var h=k.certissuer;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=ASN1HEX.pemToHex(h)}if(f==null){throw"certissuer param not cert"}var e=new X509();e.hex=f;var i=e.getIssuerHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(k.certsubj!==undefined){this.type="dn";this.explicit=true;var h=k.certsubj;var f=null;if(h.match(/^[0-9A-Fa-f]+$/)){f==h}if(h.indexOf("-----BEGIN ")!=-1){f=ASN1HEX.pemToHex(h)}if(f==null){throw"certsubj param not cert"}var e=new X509();e.hex=f;var i=e.getSubjectHex();g=new KJUR.asn1.ASN1Object();g.hTLV=i}if(this.type==null){throw"unsupported type in params="+k}this.asn1Obj=new KJUR.asn1.DERTaggedObject({explicit:this.explicit,tag:a[this.type],obj:g})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(d!==undefined){this.setByParam(d)}};YAHOO.lang.extend(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(b){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null;this.setByParamArray=function(e){for(var c=0;c0){h=new a.DERTaggedObject({obj:this.dUnsignedAttrs,tag:"a1",explicit:false})}var g=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,e,this.dSigAlg,this.dSig,];if(h!=null){g.push(h)}var f=new a.DERSequence({array:g});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.SignerInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.EncapsulatedContentInfo=function(c){KJUR.asn1.cms.EncapsulatedContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dEContentType=new a.DERObjectIdentifier({name:"data"});this.dEContent=null;this.isDetached=false;this.eContentValueHex=null;this.setContentType=function(e){if(e.match(/^[0-2][.][0-9.]+$/)){this.dEContentType=new a.DERObjectIdentifier({oid:e})}else{this.dEContentType=new a.DERObjectIdentifier({name:e})}};this.setContentValue=function(e){if(typeof e!="undefined"){if(typeof e.hex=="string"){this.eContentValueHex=e.hex}else{if(typeof e.str=="string"){this.eContentValueHex=utf8tohex(e.str)}}}};this.setContentValueHex=function(e){this.eContentValueHex=e};this.setContentValueStr=function(e){this.eContentValueHex=utf8tohex(e)};this.getEncodedHex=function(){if(typeof this.eContentValueHex!="string"){throw"eContentValue not yet set"}var g=new a.DEROctetString({hex:this.eContentValueHex});this.dEContent=new a.DERTaggedObject({obj:g,tag:"a0",explicit:true});var e=[this.dEContentType];if(!this.isDetached){e.push(this.dEContent)}var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.EncapsulatedContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentInfo=function(c){KJUR.asn1.cms.ContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dContentType=null;this.dContent=null;this.setContentType=function(e){if(typeof e=="string"){this.dContentType=d.OID.name2obj(e)}};this.getEncodedHex=function(){var f=new a.DERTaggedObject({obj:this.dContent,tag:"a0",explicit:true});var e=new a.DERSequence({array:[this.dContentType,f]});this.hTLV=e.getEncodedHex();return this.hTLV};if(typeof c!="undefined"){if(c.type){this.setContentType(c.type)}if(c.obj&&c.obj instanceof a.ASN1Object){this.dContent=c.obj}}};YAHOO.lang.extend(KJUR.asn1.cms.ContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.SignedData=function(c){KJUR.asn1.cms.SignedData.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dCMSVersion=new a.DERInteger({"int":1});this.dDigestAlgs=null;this.digestAlgNameList=[];this.dEncapContentInfo=new b.EncapsulatedContentInfo();this.dCerts=null;this.certificateList=[];this.crlList=[];this.signerInfoList=[new b.SignerInfo()];this.addCertificatesByPEM=function(e){var f=KEYUTIL.getHexFromPEM(e);var g=new a.ASN1Object();g.hTLV=f;this.certificateList.push(g)};this.getEncodedHex=function(){if(typeof this.hTLV=="string"){return this.hTLV}if(this.dDigestAlgs==null){var k=[];for(var j=0;j0){var l=new a.DERSet({array:this.certificateList});this.dCerts=new a.DERTaggedObject({obj:l,tag:"a0",explicit:false})}}if(this.dCerts!=null){e.push(this.dCerts)}var g=new a.DERSet({array:this.signerInfoList});e.push(g);var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV};this.getContentInfo=function(){this.getEncodedHex();var e=new b.ContentInfo({type:"signed-data",obj:this});return e};this.getContentInfoEncodedHex=function(){var e=this.getContentInfo();var f=e.getEncodedHex();return f};this.getPEM=function(){var e=this.getContentInfoEncodedHex();var f=a.ASN1Util.getPEMStringFromHex(e,"CMS");return f}};YAHOO.lang.extend(KJUR.asn1.cms.SignedData,KJUR.asn1.ASN1Object);KJUR.asn1.cms.CMSUtil=new function(){};KJUR.asn1.cms.CMSUtil.newSignedData=function(a){var h=KJUR.asn1.cms;var g=KJUR.asn1.cades;var f=new h.SignedData();f.dEncapContentInfo.setContentValue(a.content);if(typeof a.certs=="object"){for(var b=0;b0){h=new a.DERTaggedObject({obj:this.dUnsignedAttrs,tag:"a1",explicit:false})}var g=[this.dCMSVersion,this.dSignerIdentifier,this.dDigestAlgorithm,e,this.dSigAlg,this.dSig,];if(h!=null){g.push(h)}var f=new a.DERSequence({array:g});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.SignerInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.EncapsulatedContentInfo=function(c){KJUR.asn1.cms.EncapsulatedContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dEContentType=new a.DERObjectIdentifier({name:"data"});this.dEContent=null;this.isDetached=false;this.eContentValueHex=null;this.setContentType=function(e){if(e.match(/^[0-2][.][0-9.]+$/)){this.dEContentType=new a.DERObjectIdentifier({oid:e})}else{this.dEContentType=new a.DERObjectIdentifier({name:e})}};this.setContentValue=function(e){if(typeof e!="undefined"){if(typeof e.hex=="string"){this.eContentValueHex=e.hex}else{if(typeof e.str=="string"){this.eContentValueHex=utf8tohex(e.str)}}}};this.setContentValueHex=function(e){this.eContentValueHex=e};this.setContentValueStr=function(e){this.eContentValueHex=utf8tohex(e)};this.getEncodedHex=function(){if(typeof this.eContentValueHex!="string"){throw"eContentValue not yet set"}var g=new a.DEROctetString({hex:this.eContentValueHex});this.dEContent=new a.DERTaggedObject({obj:g,tag:"a0",explicit:true});var e=[this.dEContentType];if(!this.isDetached){e.push(this.dEContent)}var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV}};YAHOO.lang.extend(KJUR.asn1.cms.EncapsulatedContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.ContentInfo=function(c){KJUR.asn1.cms.ContentInfo.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dContentType=null;this.dContent=null;this.setContentType=function(e){if(typeof e=="string"){this.dContentType=d.OID.name2obj(e)}};this.getEncodedHex=function(){var f=new a.DERTaggedObject({obj:this.dContent,tag:"a0",explicit:true});var e=new a.DERSequence({array:[this.dContentType,f]});this.hTLV=e.getEncodedHex();return this.hTLV};if(typeof c!="undefined"){if(c.type){this.setContentType(c.type)}if(c.obj&&c.obj instanceof a.ASN1Object){this.dContent=c.obj}}};YAHOO.lang.extend(KJUR.asn1.cms.ContentInfo,KJUR.asn1.ASN1Object);KJUR.asn1.cms.SignedData=function(c){KJUR.asn1.cms.SignedData.superclass.constructor.call(this);var a=KJUR.asn1;var b=KJUR.asn1.cms;var d=KJUR.asn1.x509;this.dCMSVersion=new a.DERInteger({"int":1});this.dDigestAlgs=null;this.digestAlgNameList=[];this.dEncapContentInfo=new b.EncapsulatedContentInfo();this.dCerts=null;this.certificateList=[];this.crlList=[];this.signerInfoList=[new b.SignerInfo()];this.addCertificatesByPEM=function(e){var f=ASN1HEX.pemToHex(e);var g=new a.ASN1Object();g.hTLV=f;this.certificateList.push(g)};this.getEncodedHex=function(){if(typeof this.hTLV=="string"){return this.hTLV}if(this.dDigestAlgs==null){var k=[];for(var j=0;j0){var l=new a.DERSet({array:this.certificateList});this.dCerts=new a.DERTaggedObject({obj:l,tag:"a0",explicit:false})}}if(this.dCerts!=null){e.push(this.dCerts)}var g=new a.DERSet({array:this.signerInfoList});e.push(g);var f=new a.DERSequence({array:e});this.hTLV=f.getEncodedHex();return this.hTLV};this.getContentInfo=function(){this.getEncodedHex();var e=new b.ContentInfo({type:"signed-data",obj:this});return e};this.getContentInfoEncodedHex=function(){var e=this.getContentInfo();var f=e.getEncodedHex();return f};this.getPEM=function(){var e=this.getContentInfoEncodedHex();var f=a.ASN1Util.getPEMStringFromHex(e,"CMS");return f}};YAHOO.lang.extend(KJUR.asn1.cms.SignedData,KJUR.asn1.ASN1Object);KJUR.asn1.cms.CMSUtil=new function(){};KJUR.asn1.cms.CMSUtil.newSignedData=function(a){var h=KJUR.asn1.cms;var g=KJUR.asn1.cades;var f=new h.SignedData();f.dEncapContentInfo.setContentValue(a.content);if(typeof a.certs=="object"){for(var b=0;b0){var e=new KJUR.asn1.DERSequence({array:this.extensionsArray});var d=new KJUR.asn1.DERSet({array:[e]});var c=new KJUR.asn1.DERSequence({array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.9.14"}),d]});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a0",obj:c});this.asn1Array.push(b)}else{var b=new KJUR.asn1.DERTaggedObject({explicit:false,tag:"a0",obj:new KJUR.asn1.DERNull()});this.asn1Array.push(b)}var f=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=f.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.csr.CertificationRequestInfo,KJUR.asn1.ASN1Object);KJUR.asn1.csr.CSRUtil=new function(){};KJUR.asn1.csr.CSRUtil.newCSRPEM=function(g){var d=KJUR.asn1.csr;if(g.subject===undefined){throw"parameter subject undefined"}if(g.sbjpubkey===undefined){throw"parameter sbjpubkey undefined"}if(g.sigalg===undefined){throw"parameter sigalg undefined"}if(g.sbjprvkey===undefined){throw"parameter sbjpubkey undefined"}var b=new d.CertificationRequestInfo();b.setSubjectByParam(g.subject);b.setSubjectPublicKeyByGetKey(g.sbjpubkey);if(g.ext!==undefined&&g.ext.length!==undefined){for(var c=0;c0){var e=new KJUR.asn1.DERSequence({array:this.extensionsArray});var d=new KJUR.asn1.DERSet({array:[e]});var c=new KJUR.asn1.DERSequence({array:[new KJUR.asn1.DERObjectIdentifier({oid:"1.2.840.113549.1.9.14"}),d]});var b=new KJUR.asn1.DERTaggedObject({explicit:true,tag:"a0",obj:c});this.asn1Array.push(b)}else{var b=new KJUR.asn1.DERTaggedObject({explicit:false,tag:"a0",obj:new KJUR.asn1.DERNull()});this.asn1Array.push(b)}var f=new KJUR.asn1.DERSequence({array:this.asn1Array});this.hTLV=f.getEncodedHex();this.isModified=false;return this.hTLV};this._initialize()};YAHOO.lang.extend(KJUR.asn1.csr.CertificationRequestInfo,KJUR.asn1.ASN1Object);KJUR.asn1.csr.CSRUtil=new function(){};KJUR.asn1.csr.CSRUtil.newCSRPEM=function(g){var d=KJUR.asn1.csr;if(g.subject===undefined){throw"parameter subject undefined"}if(g.sbjpubkey===undefined){throw"parameter sbjpubkey undefined"}if(g.sigalg===undefined){throw"parameter sigalg undefined"}if(g.sbjprvkey===undefined){throw"parameter sbjpubkey undefined"}var b=new d.CertificationRequestInfo();b.setSubjectByParam(g.subject);b.setSubjectPublicKeyByGetKey(g.sbjpubkey);if(g.ext!==undefined&&g.ext.length!==undefined){for(var c=0;cd){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()}; +if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECDSA=function(h){var e="secp256r1";var g=null;var b=null;var f=null;var a=new SecureRandom();var d=null;this.type="EC";this.isPrivate=false;this.isPublic=false;function c(s,o,r,n){var j=Math.max(o.bitLength(),n.bitLength());var t=s.add2D(r);var q=s.curve.getInfinity();for(var p=j-1;p>=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}};this.readPKCS5PrvKeyHex=function(l){var n=ASN1HEX;var m=KJUR.crypto.ECDSA.getName;var p=n.getVbyList;if(n.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var i,k,o;try{i=p(l,0,[2,0],"06");k=p(l,0,[1],"04");try{o=p(l,0,[3,0],"03").substr(2)}catch(j){}}catch(j){throw"malformed PKCS#1/5 plain ECC private key"}this.curveName=m(i);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(o);this.setPrivateKeyHex(k);this.isPublic=false};this.readPKCS8PrvKeyHex=function(l){var q=ASN1HEX;var i=KJUR.crypto.ECDSA.getName;var n=q.getVbyList;if(q.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var j,p,m,k;try{j=n(l,0,[1,0],"06");p=n(l,0,[1,1],"06");m=n(l,0,[2,0,1],"04");try{k=n(l,0,[2,0,2,0],"03").substr(2)}catch(o){}}catch(o){throw"malformed PKCS#8 plain ECC private key"}this.curveName=i(p);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(k);this.setPrivateKeyHex(m);this.isPublic=false};this.readPKCS8PubKeyHex=function(l){var n=ASN1HEX;var m=KJUR.crypto.ECDSA.getName;var p=n.getVbyList;if(n.isASN1HEX(l)===false){throw"not ASN.1 hex string"}var k,i,o;try{k=p(l,0,[0,0],"06");i=p(l,0,[0,1],"06");o=p(l,0,[1],"03").substr(2)}catch(j){throw"malformed PKCS#8 ECC public key"}this.curveName=m(i);if(this.curveName===null){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(o)};this.readCertPubKeyHex=function(k,p){if(p!==5){p=6}var m=ASN1HEX;var l=KJUR.crypto.ECDSA.getName;var o=m.getVbyList;if(m.isASN1HEX(k)===false){throw"not ASN.1 hex string"}var i,n;try{i=o(k,0,[0,p,0,1],"06");n=o(k,0,[0,p,1],"03").substr(2)}catch(j){throw"malformed X.509 certificate ECC public key"}this.curveName=l(i);if(this.curveName===null){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(n)};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()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040022"){return"secp384r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}return null}; /*! ecparam-1.0.0.js (c) 2013 Kenji Urushima | kjur.github.com/jsrsasign/license */ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v0||a.compareTo(b)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(t)>0||t.compareTo(b)>0){throw"invalid DSA signature"}var m=t.modInverse(b);var e=k.multiply(m).mod(b);var c=a.multiply(m).mod(b);var n=j.modPow(e,d).multiply(l.modPow(c,d)).mod(d).mod(b);return n.compareTo(a)==0};this.parseASN1Signature=function(a){try{var d=new BigInteger(ASN1HEX.getVbyList(a,0,[0],"02"),16);var c=new BigInteger(ASN1HEX.getVbyList(a,0,[1],"02"),16);return[d,c]}catch(b){throw"malformed ASN.1 DSA signature"}}}; -/*! pkcs5pkey-1.0.7.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.DSA=function(){this.p=null;this.q=null;this.g=null;this.y=null;this.x=null;this.type="DSA";this.isPrivate=false;this.isPublic=false;this.setPrivate=function(d,c,b,e,a){this.isPrivate=true;this.p=d;this.q=c;this.g=b;this.y=e;this.x=a};this.setPrivateHex=function(d,b,f,i,j){var c,a,e,g,h;c=new BigInteger(d,16);a=new BigInteger(b,16);e=new BigInteger(f,16);if(typeof i==="string"&&i.length>1){g=new BigInteger(i,16)}else{g=null}h=new BigInteger(j,16);this.setPrivate(c,a,e,g,h)};this.setPublic=function(c,b,a,d){this.isPublic=true;this.p=c;this.q=b;this.g=a;this.y=d;this.x=null};this.setPublicHex=function(f,e,d,g){var b,a,h,c;b=new BigInteger(f,16);a=new BigInteger(e,16);h=new BigInteger(d,16);c=new BigInteger(g,16);this.setPublic(b,a,h,c)};this.signWithMessageHash=function(d){var c=this.p;var b=this.q;var f=this.g;var i=this.y;var j=this.x;var e=KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE),b.subtract(BigInteger.ONE));var l=d.substr(0,b.bitLength()/4);var h=new BigInteger(l,16);var a=(f.modPow(e,c)).mod(b);var n=(e.modInverse(b).multiply(h.add(j.multiply(a)))).mod(b);var m=KJUR.asn1.ASN1Util.jsonToASN1HEX({seq:[{"int":{bigint:a}},{"int":{bigint:n}}]});return m};this.verifyWithMessageHash=function(h,f){var d=this.p;var b=this.q;var j=this.g;var l=this.y;var i=this.parseASN1Signature(f);var a=i[0];var t=i[1];var o=h.substr(0,b.bitLength()/4);var k=new BigInteger(o,16);if(BigInteger.ZERO.compareTo(a)>0||a.compareTo(b)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(t)>0||t.compareTo(b)>0){throw"invalid DSA signature"}var m=t.modInverse(b);var e=k.multiply(m).mod(b);var c=a.multiply(m).mod(b);var n=j.modPow(e,d).multiply(l.modPow(c,d)).mod(d).mod(b);return n.compareTo(a)==0};this.parseASN1Signature=function(a){try{var d=new BigInteger(ASN1HEX.getVbyList(a,0,[0],"02"),16);var c=new BigInteger(ASN1HEX.getVbyList(a,0,[1],"02"),16);return[d,c]}catch(b){throw"malformed ASN.1 DSA signature"}};this.readPKCS5PrvKeyHex=function(c){var b,a,f,g,i;var j=ASN1HEX;var d=j.getVbyList;if(j.isASN1HEX(c)===false){throw"not ASN.1 hex string"}try{b=d(c,0,[1],"02");a=d(c,0,[2],"02");f=d(c,0,[3],"02");g=d(c,0,[4],"02");i=d(c,0,[5],"02")}catch(e){console.log("EXCEPTION:"+e);throw"malformed PKCS#1/5 plain DSA private key"}this.setPrivateHex(b,a,f,g,i)};this.readPKCS8PrvKeyHex=function(d){var f,c,b,g;var e=ASN1HEX;var i=e.getVbyList;if(e.isASN1HEX(d)===false){throw"not ASN.1 hex string"}try{f=i(d,0,[1,1,0],"02");c=i(d,0,[1,1,1],"02");b=i(d,0,[1,1,2],"02");g=i(d,0,[2,0],"02")}catch(a){console.log("EXCEPTION:"+a);throw"malformed PKCS#8 plain DSA private key"}this.setPrivateHex(f,c,b,null,g)};this.readPKCS8PubKeyHex=function(d){var f,c,b,g;var e=ASN1HEX;var i=e.getVbyList;if(e.isASN1HEX(d)===false){throw"not ASN.1 hex string"}try{f=i(d,0,[0,1,0],"02");c=i(d,0,[0,1,1],"02");b=i(d,0,[0,1,2],"02");g=i(d,0,[1,0],"02")}catch(a){console.log("EXCEPTION:"+a);throw"malformed PKCS#8 DSA public key"}this.setPublicHex(f,c,b,g)};this.readCertPubKeyHex=function(c,f){if(f!==5){f=6}var b,a,g,i;var j=ASN1HEX;var d=j.getVbyList;if(j.isASN1HEX(c)===false){throw"not ASN.1 hex string"}try{b=d(c,0,[0,f,0,1,0],"02");a=d(c,0,[0,f,0,1,1],"02");g=d(c,0,[0,f,0,1,2],"02");i=d(c,0,[0,f,1,0],"02")}catch(e){console.log("EXCEPTION:"+e);throw"malformed X.509 certificate DSA public key"}this.setPublicHex(b,a,g,i)}}; +/*! pkcs5pkey-1.1.0.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -var PKCS5PKEY=function(){var c=function(n,p,o){return i(CryptoJS.AES,n,p,o)};var d=function(n,p,o){return i(CryptoJS.TripleDES,n,p,o)};var i=function(q,v,s,o){var p=CryptoJS.enc.Hex.parse(v);var u=CryptoJS.enc.Hex.parse(s);var n=CryptoJS.enc.Hex.parse(o);var r={};r.key=u;r.iv=n;r.ciphertext=p;var t=q.decrypt(r,u,{iv:n});return CryptoJS.enc.Hex.stringify(t)};var j=function(n,p,o){return e(CryptoJS.AES,n,p,o)};var m=function(n,p,o){return e(CryptoJS.TripleDES,n,p,o)};var e=function(s,x,v,p){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(v);var o=CryptoJS.enc.Hex.parse(p);var n={};var u=s.encrypt(r,w,{iv:o});var q=CryptoJS.enc.Hex.parse(u.toString());var t=CryptoJS.enc.Base64.stringify(q);return t};var g={"AES-256-CBC":{proc:c,eproc:j,keylen:32,ivlen:16},"AES-192-CBC":{proc:c,eproc:j,keylen:24,ivlen:16},"AES-128-CBC":{proc:c,eproc:j,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:d,eproc:m,keylen:24,ivlen:8}};var b=function(n){return g[n]["proc"]};var k=function(n){var p=CryptoJS.lib.WordArray.random(n);var o=CryptoJS.enc.Hex.stringify(p);return o};var l=function(t){var u={};var o=t.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(o){u.cipher=o[1];u.ivsalt=o[2]}var n=t.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(n){u.type=n[1]}var r=-1;var v=0;if(t.indexOf("\r\n\r\n")!=-1){r=t.indexOf("\r\n\r\n");v=2}if(t.indexOf("\n\n")!=-1){r=t.indexOf("\n\n");v=1}var q=t.indexOf("-----END");if(r!=-1&&q!=-1){var p=t.substring(r+v*2,q-v);p=p.replace(/\s+/g,"");u.data=p}return u};var h=function(o,w,n){var t=n.substring(0,16);var r=CryptoJS.enc.Hex.parse(t);var p=CryptoJS.enc.Utf8.parse(w);var s=g[o]["keylen"]+g[o]["ivlen"];var v="";var u=null;for(;;){var q=CryptoJS.algo.MD5.create();if(u!=null){q.update(u)}q.update(p);q.update(r);u=q.finalize();v=v+CryptoJS.enc.Hex.stringify(u);if(v.length>=s*2){break}}var x={};x.keyhex=v.substr(0,g[o]["keylen"]*2);x.ivhex=v.substr(g[o]["keylen"]*2,g[o]["ivlen"]*2);return x};var a=function(n,t,p,u){var q=CryptoJS.enc.Base64.parse(n);var o=CryptoJS.enc.Hex.stringify(q);var s=g[t]["proc"];var r=s(o,p,u);return r};var f=function(n,q,o,s){var p=g[q]["eproc"];var r=p(n,o,s);return r};return{version:"1.0.5",getHexFromPEM:function(o,r){var p=o;if(p.indexOf("BEGIN "+r)==-1){throw"can't find PEM header: "+r}p=p.replace("-----BEGIN "+r+"-----","");p=p.replace("-----END "+r+"-----","");var q=p.replace(/\s+/g,"");var n=b64tohex(q);return n},getDecryptedKeyHexByKeyIV:function(o,r,q,p){var n=b(r);return n(o,q,p)},parsePKCS5PEM:function(n){return l(n)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(o,n,p){return h(o,n,p)},decryptKeyB64:function(n,p,o,q){return a(n,p,o,q)},getDecryptedKeyHex:function(w,v){var o=l(w);var r=o.type;var p=o.cipher;var n=o.ivsalt;var q=o.data;var u=h(p,v,n);var t=u.keyhex;var s=a(q,p,t,n);return s},getRSAKeyFromEncryptedPKCS5PEM:function(p,o){var q=this.getDecryptedKeyHex(p,o);var n=new RSAKey();n.readPrivateKeyFromASN1HexString(q);return n},getEncryptedPKCS5PEMFromPrvKeyHex:function(q,x,r,p){if(typeof r=="undefined"||r==null){r="AES-256-CBC"}if(typeof g[r]=="undefined"){throw"PKCS5PKEY unsupported algorithm: "+r}if(typeof p=="undefined"||p==null){var t=g[r]["ivlen"];var s=k(t);p=s.toUpperCase()}var w=h(r,x,p);var v=w.keyhex;var u=f(q,r,v,p);var o=u.replace(/(.{64})/g,"$1\r\n");var n="-----BEGIN RSA PRIVATE KEY-----\r\n";n+="Proc-Type: 4,ENCRYPTED\r\n";n+="DEK-Info: "+r+","+p+"\r\n";n+="\r\n";n+=o;n+="\r\n-----END RSA PRIVATE KEY-----\r\n";return n},getEncryptedPKCS5PEMFromRSAKey:function(C,D,o,s){var A=new KJUR.asn1.DERInteger({"int":0});var v=new KJUR.asn1.DERInteger({bigint:C.n});var z=new KJUR.asn1.DERInteger({"int":C.e});var B=new KJUR.asn1.DERInteger({bigint:C.d});var t=new KJUR.asn1.DERInteger({bigint:C.p});var r=new KJUR.asn1.DERInteger({bigint:C.q});var y=new KJUR.asn1.DERInteger({bigint:C.dmp1});var u=new KJUR.asn1.DERInteger({bigint:C.dmq1});var x=new KJUR.asn1.DERInteger({bigint:C.coeff});var E=new KJUR.asn1.DERSequence({array:[A,v,z,B,t,r,y,u,x]});var w=E.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex(w,D,o,s)},newEncryptedPKCS5PEM:function(n,o,r,s){if(typeof o=="undefined"||o==null){o=1024}if(typeof r=="undefined"||r==null){r="10001"}var p=new RSAKey();p.generate(o,r);var q=null;if(typeof s=="undefined"||s==null){q=this.getEncryptedPKCS5PEMFromRSAKey(pkey,n)}else{q=this.getEncryptedPKCS5PEMFromRSAKey(pkey,n,s)}return q},getRSAKeyFromPlainPKCS8PEM:function(p){if(p.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var o=this.getHexFromPEM(p,"PRIVATE KEY");var n=this.getRSAKeyFromPlainPKCS8Hex(o);return n},getRSAKeyFromPlainPKCS8Hex:function(q){var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=3){throw"outer DERSequence shall have 3 elements: "+p.length}var o=ASN1HEX.getHexOfTLV_AtObj(q,p[1]);if(o!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmIdentifier is not rsaEnc: "+o}var r=ASN1HEX.getHexOfTLV_AtObj(q,p[2]);var s=ASN1HEX.getHexOfV_AtObj(r,0);var n=new RSAKey();n.readPrivateKeyFromASN1HexString(s);return n},parseHexOfEncryptedPKCS8:function(u){var q={};var p=ASN1HEX.getPosArrayOfChildren_AtObj(u,0);if(p.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+p.length}q.ciphertext=ASN1HEX.getHexOfV_AtObj(u,p[1]);var w=ASN1HEX.getPosArrayOfChildren_AtObj(u,p[0]);if(w.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+w.length}if(ASN1HEX.getHexOfV_AtObj(u,w[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(u,w[1]);if(w.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+n.length}var o=ASN1HEX.getPosArrayOfChildren_AtObj(u,n[1]);if(o.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+o.length}if(ASN1HEX.getHexOfV_AtObj(u,o[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}q.encryptionSchemeAlg="TripleDES";q.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(u,o[1]);var r=ASN1HEX.getPosArrayOfChildren_AtObj(u,n[0]);if(r.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+r.length}if(ASN1HEX.getHexOfV_AtObj(u,r[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var v=ASN1HEX.getPosArrayOfChildren_AtObj(u,r[1]);if(v.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+v.length}q.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(u,v[0]);var s=ASN1HEX.getHexOfV_AtObj(u,v[1]);try{q.pbkdf2Iter=parseInt(s,16)}catch(t){throw"malformed format pbkdf2Iter: "+s}return q},getPBKDF2KeyHexFromParam:function(s,n){var r=CryptoJS.enc.Hex.parse(s.pbkdf2Salt);var o=s.pbkdf2Iter;var q=CryptoJS.PBKDF2(n,r,{keySize:192/32,iterations:o});var p=CryptoJS.enc.Hex.stringify(q);return p},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(v,w){var p=this.getHexFromPEM(v,"ENCRYPTED PRIVATE KEY");var n=this.parseHexOfEncryptedPKCS8(p);var s=PKCS5PKEY.getPBKDF2KeyHexFromParam(n,w);var t={};t.ciphertext=CryptoJS.enc.Hex.parse(n.ciphertext);var r=CryptoJS.enc.Hex.parse(s);var q=CryptoJS.enc.Hex.parse(n.encryptionSchemeIV);var u=CryptoJS.TripleDES.decrypt(t,r,{iv:q});var o=CryptoJS.enc.Hex.stringify(u);return o},getRSAKeyFromEncryptedPKCS8PEM:function(q,p){var o=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(q,p);var n=this.getRSAKeyFromPlainPKCS8Hex(o);return n},getKeyFromEncryptedPKCS8PEM:function(q,o){var n=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(q,o);var p=this.getKeyFromPlainPrivatePKCS8Hex(n);return p},parsePlainPrivatePKCS8Hex:function(q){var o={};o.algparam=null;if(q.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(q.substr(p[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(q,p[1]);if(n.length!=2){throw"malformed PKCS8 private key(code:004)"}if(q.substr(n[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}o.algoid=ASN1HEX.getHexOfV_AtObj(q,n[0]);if(q.substr(n[1],2)=="06"){o.algparam=ASN1HEX.getHexOfV_AtObj(q,n[1])}if(q.substr(p[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}o.keyidx=ASN1HEX.getStartPosOfV_AtObj(q,p[2]);return o},getKeyFromPlainPrivatePKCS8PEM:function(o){var n=this.getHexFromPEM(o,"PRIVATE KEY");var p=this.getKeyFromPlainPrivatePKCS8Hex(n);return p},getKeyFromPlainPrivatePKCS8Hex:function(n){var p=this.parsePlainPrivatePKCS8Hex(n);if(p.algoid=="2a864886f70d010101"){this.parsePrivateRawRSAKeyHexAtObj(n,p);var o=p.key;var q=new RSAKey();q.setPrivateEx(o.n,o.e,o.d,o.p,o.q,o.dp,o.dq,o.co);return q}else{if(p.algoid=="2a8648ce3d0201"){this.parsePrivateRawECKeyHexAtObj(n,p);if(KJUR.crypto.OID.oidhex2name[p.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+p.algparam}var r=KJUR.crypto.OID.oidhex2name[p.algparam];var q=new KJUR.crypto.ECDSA({curve:r,prv:p.key});return q}else{throw"unsupported private key algorithm"}}},getRSAKeyFromPublicPKCS8PEM:function(o){var p=this.getHexFromPEM(o,"PUBLIC KEY");var n=this.getRSAKeyFromPublicPKCS8Hex(p);return n},getKeyFromPublicPKCS8PEM:function(o){var p=this.getHexFromPEM(o,"PUBLIC KEY");var n=this.getKeyFromPublicPKCS8Hex(p);return n},getKeyFromPublicPKCS8Hex:function(o){var n=this.parsePublicPKCS8Hex(o);if(n.algoid=="2a864886f70d010101"){var r=this.parsePublicRawRSAKeyHex(n.key);var p=new RSAKey();p.setPublic(r.n,r.e);return p}else{if(n.algoid=="2a8648ce3d0201"){if(KJUR.crypto.OID.oidhex2name[n.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+n.algparam}var q=KJUR.crypto.OID.oidhex2name[n.algparam];var p=new KJUR.crypto.ECDSA({curve:q,pub:n.key});return p}else{throw"unsupported public key algorithm"}}},parsePublicRawRSAKeyHex:function(p){var n={};if(p.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,0);if(o.length!=2){throw"malformed RSA key(code:002)"}if(p.substr(o[0],2)!="02"){throw"malformed RSA key(code:003)"}n.n=ASN1HEX.getHexOfV_AtObj(p,o[0]);if(p.substr(o[1],2)!="02"){throw"malformed RSA key(code:004)"}n.e=ASN1HEX.getHexOfV_AtObj(p,o[1]);return n},parsePrivateRawRSAKeyHexAtObj:function(o,q){var p=q.keyidx;if(o.substr(p,2)!="30"){throw"malformed RSA private key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(o,p);if(n.length!=9){throw"malformed RSA private key(code:002)"}q.key={};q.key.n=ASN1HEX.getHexOfV_AtObj(o,n[1]);q.key.e=ASN1HEX.getHexOfV_AtObj(o,n[2]);q.key.d=ASN1HEX.getHexOfV_AtObj(o,n[3]);q.key.p=ASN1HEX.getHexOfV_AtObj(o,n[4]);q.key.q=ASN1HEX.getHexOfV_AtObj(o,n[5]);q.key.dp=ASN1HEX.getHexOfV_AtObj(o,n[6]);q.key.dq=ASN1HEX.getHexOfV_AtObj(o,n[7]);q.key.co=ASN1HEX.getHexOfV_AtObj(o,n[8])},parsePrivateRawECKeyHexAtObj:function(o,q){var p=q.keyidx;if(o.substr(p,2)!="30"){throw"malformed ECC private key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(o,p);if(n.length!=3){throw"malformed ECC private key(code:002)"}if(o.substr(n[1],2)!="04"){throw"malformed ECC private key(code:003)"}q.key=ASN1HEX.getHexOfV_AtObj(o,n[1])},parsePublicPKCS8Hex:function(q){var o={};o.algparam=null;var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=2){throw"outer DERSequence shall have 2 elements: "+p.length}var r=p[0];if(q.substr(r,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var n=ASN1HEX.getPosArrayOfChildren_AtObj(q,r);if(n.length!=2){throw"malformed PKCS8 public key(code:002)"}if(q.substr(n[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}o.algoid=ASN1HEX.getHexOfV_AtObj(q,n[0]);if(q.substr(n[1],2)=="06"){o.algparam=ASN1HEX.getHexOfV_AtObj(q,n[1])}if(q.substr(p[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}o.key=ASN1HEX.getHexOfV_AtObj(q,p[1]).substr(2);return o},getRSAKeyFromPublicPKCS8Hex:function(r){var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"outer DERSequence shall have 2 elements: "+q.length}var p=ASN1HEX.getHexOfTLV_AtObj(r,q[0]);if(p!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmId is not rsaEncryption"}if(r.substr(q[1],2)!="03"){throw"PKCS8 Public Key is not BITSTRING encapslated."}var t=ASN1HEX.getStartPosOfV_AtObj(r,q[1])+2;if(r.substr(t,2)!="30"){throw"PKCS8 Public Key is not SEQUENCE."}var n=ASN1HEX.getPosArrayOfChildren_AtObj(r,t);if(n.length!=2){throw"inner DERSequence shall have 2 elements: "+n.length}if(r.substr(n[0],2)!="02"){throw"N is not ASN.1 INTEGER"}if(r.substr(n[1],2)!="02"){throw"E is not ASN.1 INTEGER"}var u=ASN1HEX.getHexOfV_AtObj(r,n[0]);var s=ASN1HEX.getHexOfV_AtObj(r,n[1]);var o=new RSAKey();o.setPublic(u,s);return o},}}(); -/*! keyutil-1.0.14.js (c) 2013-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +var PKCS5PKEY=function(){var c=function(o,q,p){return j(CryptoJS.AES,o,q,p)};var d=function(o,q,p){return j(CryptoJS.TripleDES,o,q,p)};var j=function(r,w,t,p){var q=CryptoJS.enc.Hex.parse(w);var v=CryptoJS.enc.Hex.parse(t);var o=CryptoJS.enc.Hex.parse(p);var s={};s.key=v;s.iv=o;s.ciphertext=q;var u=r.decrypt(s,v,{iv:o});return CryptoJS.enc.Hex.stringify(u)};var k=function(o,q,p){return e(CryptoJS.AES,o,q,p)};var n=function(o,q,p){return e(CryptoJS.TripleDES,o,q,p)};var e=function(t,y,w,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(w);var p=CryptoJS.enc.Hex.parse(q);var o={};var v=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(v.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var g={"AES-256-CBC":{proc:c,eproc:k,keylen:32,ivlen:16},"AES-192-CBC":{proc:c,eproc:k,keylen:24,ivlen:16},"AES-128-CBC":{proc:c,eproc:k,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:d,eproc:n,keylen:24,ivlen:8}};var b=function(o){return g[o]["proc"]};var l=function(o){var q=CryptoJS.lib.WordArray.random(o);var p=CryptoJS.enc.Hex.stringify(q);return p};var m=function(u){var v={};var p=u.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(p){v.cipher=p[1];v.ivsalt=p[2]}var o=u.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(o){v.type=o[1]}var t=-1;var w=0;if(u.indexOf("\r\n\r\n")!=-1){t=u.indexOf("\r\n\r\n");w=2}if(u.indexOf("\n\n")!=-1){t=u.indexOf("\n\n");w=1}var r=u.indexOf("-----END");if(t!=-1&&r!=-1){var q=u.substring(t+w*2,r-w);q=q.replace(/\s+/g,"");v.data=q}return v};var i=function(p,x,o){var u=o.substring(0,16);var s=CryptoJS.enc.Hex.parse(u);var q=CryptoJS.enc.Utf8.parse(x);var t=g[p]["keylen"]+g[p]["ivlen"];var w="";var v=null;for(;;){var r=CryptoJS.algo.MD5.create();if(v!=null){r.update(v)}r.update(q);r.update(s);v=r.finalize();w=w+CryptoJS.enc.Hex.stringify(v);if(w.length>=t*2){break}}var y={};y.keyhex=w.substr(0,g[p]["keylen"]*2);y.ivhex=w.substr(g[p]["keylen"]*2,g[p]["ivlen"]*2);return y};var a=function(o,u,q,v){var r=CryptoJS.enc.Base64.parse(o);var p=CryptoJS.enc.Hex.stringify(r);var t=g[u]["proc"];var s=t(p,q,v);return s};var f=function(o,r,p,t){var q=g[r]["eproc"];var s=q(o,p,t);return s};return{version:"1.0.5",getHexFromPEM:function(o,p){return ASN1HEX.pemToHex(o,p)},getDecryptedKeyHexByKeyIV:function(p,s,r,q){var o=b(s);return o(p,r,q)},parsePKCS5PEM:function(o){return m(o)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(p,o,q){return i(p,o,q)},decryptKeyB64:function(o,q,p,r){return a(o,q,p,r)},getDecryptedKeyHex:function(x,w){var p=m(x);var s=p.type;var q=p.cipher;var o=p.ivsalt;var r=p.data;var v=i(q,w,o);var u=v.keyhex;var t=a(r,q,u,o);return t},getRSAKeyFromEncryptedPKCS5PEM:function(q,p){var r=this.getDecryptedKeyHex(q,p);var o=new RSAKey();o.readPrivateKeyFromASN1HexString(r);return o},getEncryptedPKCS5PEMFromPrvKeyHex:function(r,y,s,q){if(typeof s=="undefined"||s==null){s="AES-256-CBC"}if(typeof g[s]=="undefined"){throw"PKCS5PKEY unsupported algorithm: "+s}if(typeof q=="undefined"||q==null){var u=g[s]["ivlen"];var t=l(u);q=t.toUpperCase()}var x=i(s,y,q);var w=x.keyhex;var v=f(r,s,w,q);var p=v.replace(/(.{64})/g,"$1\r\n");var o="-----BEGIN RSA PRIVATE KEY-----\r\n";o+="Proc-Type: 4,ENCRYPTED\r\n";o+="DEK-Info: "+s+","+q+"\r\n";o+="\r\n";o+=p;o+="\r\n-----END RSA PRIVATE KEY-----\r\n";return o},getEncryptedPKCS5PEMFromRSAKey:function(C,D,o,s){var A=new KJUR.asn1.DERInteger({"int":0});var v=new KJUR.asn1.DERInteger({bigint:C.n});var z=new KJUR.asn1.DERInteger({"int":C.e});var B=new KJUR.asn1.DERInteger({bigint:C.d});var t=new KJUR.asn1.DERInteger({bigint:C.p});var r=new KJUR.asn1.DERInteger({bigint:C.q});var y=new KJUR.asn1.DERInteger({bigint:C.dmp1});var u=new KJUR.asn1.DERInteger({bigint:C.dmq1});var x=new KJUR.asn1.DERInteger({bigint:C.coeff});var E=new KJUR.asn1.DERSequence({array:[A,v,z,B,t,r,y,u,x]});var w=E.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex(w,D,o,s)},newEncryptedPKCS5PEM:function(o,p,s,t){if(typeof p=="undefined"||p==null){p=1024}if(typeof s=="undefined"||s==null){s="10001"}var q=new RSAKey();q.generate(p,s);var r=null;if(typeof t=="undefined"||t==null){r=this.getEncryptedPKCS5PEMFromRSAKey(pkey,o)}else{r=this.getEncryptedPKCS5PEMFromRSAKey(pkey,o,t)}return r},getRSAKeyFromPlainPKCS8PEM:function(q){if(q.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var p=ASN1HEX.pemToHex(q,"PRIVATE KEY");var o=this.getRSAKeyFromPlainPKCS8Hex(p);return o},getRSAKeyFromPlainPKCS8Hex:function(p){var o=new RSAKey();o.readPKCS8PrvKeyHex(p);return o},parseHexOfEncryptedPKCS8:function(v){var r={};var q=ASN1HEX.getPosArrayOfChildren_AtObj(v,0);if(q.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+q.length}r.ciphertext=ASN1HEX.getHexOfV_AtObj(v,q[1]);var x=ASN1HEX.getPosArrayOfChildren_AtObj(v,q[0]);if(x.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+x.length}if(ASN1HEX.getHexOfV_AtObj(v,x[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(v,x[1]);if(x.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+o.length}var p=ASN1HEX.getPosArrayOfChildren_AtObj(v,o[1]);if(p.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+p.length}if(ASN1HEX.getHexOfV_AtObj(v,p[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}r.encryptionSchemeAlg="TripleDES";r.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(v,p[1]);var s=ASN1HEX.getPosArrayOfChildren_AtObj(v,o[0]);if(s.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+s.length}if(ASN1HEX.getHexOfV_AtObj(v,s[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var w=ASN1HEX.getPosArrayOfChildren_AtObj(v,s[1]);if(w.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+w.length}r.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(v,w[0]);var t=ASN1HEX.getHexOfV_AtObj(v,w[1]);try{r.pbkdf2Iter=parseInt(t,16)}catch(u){throw"malformed format pbkdf2Iter: "+t}return r},getPBKDF2KeyHexFromParam:function(t,o){var s=CryptoJS.enc.Hex.parse(t.pbkdf2Salt);var p=t.pbkdf2Iter;var r=CryptoJS.PBKDF2(o,s,{keySize:192/32,iterations:p});var q=CryptoJS.enc.Hex.stringify(r);return q},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(w,x){var q=ASN1HEX.pemToHex(w,"ENCRYPTED PRIVATE KEY");var o=this.parseHexOfEncryptedPKCS8(q);var t=PKCS5PKEY.getPBKDF2KeyHexFromParam(o,x);var u={};u.ciphertext=CryptoJS.enc.Hex.parse(o.ciphertext);var s=CryptoJS.enc.Hex.parse(t);var r=CryptoJS.enc.Hex.parse(o.encryptionSchemeIV);var v=CryptoJS.TripleDES.decrypt(u,s,{iv:r});var p=CryptoJS.enc.Hex.stringify(v);return p},getRSAKeyFromEncryptedPKCS8PEM:function(r,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(r,q);var o=this.getRSAKeyFromPlainPKCS8Hex(p);return o},getKeyFromEncryptedPKCS8PEM:function(r,p){var o=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(r,p);var q=this.getKeyFromPlainPrivatePKCS8Hex(o);return q},parsePlainPrivatePKCS8Hex:function(r){var p={};p.algparam=null;if(r.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(r.substr(q[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(r,q[1]);if(o.length!=2){throw"malformed PKCS8 private key(code:004)"}if(r.substr(o[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}p.algoid=ASN1HEX.getHexOfV_AtObj(r,o[0]);if(r.substr(o[1],2)=="06"){p.algparam=ASN1HEX.getHexOfV_AtObj(r,o[1])}if(r.substr(q[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}p.keyidx=ASN1HEX.getStartPosOfV_AtObj(r,q[2]);return p},getKeyFromPlainPrivatePKCS8PEM:function(p){var o=ASN1HEX.pemToHex(p,"PRIVATE KEY");var q=this.getKeyFromPlainPrivatePKCS8Hex(o);return q},getKeyFromPlainPrivatePKCS8Hex:function(o){var p=this.parsePlainPrivatePKCS8Hex(o);var q;if(p.algoid=="2a864886f70d010101"){q=new RSAKey()}else{if(p.algoid=="2a8648ce380401"){q=new KJUR.crypto.DSA()}else{if(p.algoid=="2a8648ce3d0201"){q=new KJUR.crypto.ECDSA()}else{throw"unsupported private key algorithm"}}}q.readPKCS8PrvKeyHex(o);return q},getRSAKeyFromPublicPKCS8PEM:function(p){var q=ASN1HEX.pemToHex(p,"PUBLIC KEY");var o=this.getRSAKeyFromPublicPKCS8Hex(q);return o},getKeyFromPublicPKCS8PEM:function(p){var q=ASN1HEX.pemToHex(p,"PUBLIC KEY");var o=this.getKeyFromPublicPKCS8Hex(q);return o},getKeyFromPublicPKCS8Hex:function(o){var p;var q=ASN1HEX.getVbyList(h,0,[0,0],"06");if(q==="2a864886f70d010101"){p=new RSAKey()}else{if(q==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(q==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw"unsupported PKCS#8 public key hex"}}}p.readPKCS8PubKeyHex(h);return p},parsePublicRawRSAKeyHex:function(q){var o={};if(q.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,0);if(p.length!=2){throw"malformed RSA key(code:002)"}if(q.substr(p[0],2)!="02"){throw"malformed RSA key(code:003)"}o.n=ASN1HEX.getHexOfV_AtObj(q,p[0]);if(q.substr(p[1],2)!="02"){throw"malformed RSA key(code:004)"}o.e=ASN1HEX.getHexOfV_AtObj(q,p[1]);return o},parsePrivateRawRSAKeyHexAtObj:function(p,r){var q=r.keyidx;if(p.substr(q,2)!="30"){throw"malformed RSA private key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,q);if(o.length!=9){throw"malformed RSA private key(code:002)"}r.key={};r.key.n=ASN1HEX.getHexOfV_AtObj(p,o[1]);r.key.e=ASN1HEX.getHexOfV_AtObj(p,o[2]);r.key.d=ASN1HEX.getHexOfV_AtObj(p,o[3]);r.key.p=ASN1HEX.getHexOfV_AtObj(p,o[4]);r.key.q=ASN1HEX.getHexOfV_AtObj(p,o[5]);r.key.dp=ASN1HEX.getHexOfV_AtObj(p,o[6]);r.key.dq=ASN1HEX.getHexOfV_AtObj(p,o[7]);r.key.co=ASN1HEX.getHexOfV_AtObj(p,o[8])},parsePrivateRawECKeyHexAtObj:function(p,r){var q=r.keyidx;if(p.substr(q,2)!="30"){throw"malformed ECC private key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(p,q);if(o.length!=3){throw"malformed ECC private key(code:002)"}if(p.substr(o[1],2)!="04"){throw"malformed ECC private key(code:003)"}r.key=ASN1HEX.getHexOfV_AtObj(p,o[1])},parsePublicPKCS8Hex:function(r){var p={};p.algparam=null;var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"outer DERSequence shall have 2 elements: "+q.length}var s=q[0];if(r.substr(s,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var o=ASN1HEX.getPosArrayOfChildren_AtObj(r,s);if(o.length!=2){throw"malformed PKCS8 public key(code:002)"}if(r.substr(o[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}p.algoid=ASN1HEX.getHexOfV_AtObj(r,o[0]);if(r.substr(o[1],2)=="06"){p.algparam=ASN1HEX.getHexOfV_AtObj(r,o[1])}if(r.substr(q[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}p.key=ASN1HEX.getHexOfV_AtObj(r,q[1]).substr(2);return p},getRSAKeyFromPublicPKCS8Hex:function(o){var p=new RSAKey();p.readPKCS8PubKeyHex(o);return p},}}(); +/*! keyutil-1.0.15.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",getHexFromPEM:function(q,u){var r=q;if(r.indexOf("-----BEGIN ")==-1){throw"can't find PEM header: "+u}if(typeof u=="string"&&u!=""){r=r.replace("-----BEGIN "+u+"-----","");r=r.replace("-----END "+u+"-----","")}else{r=r.replace(/-----BEGIN [^-]+-----/,"");r=r.replace(/-----END [^-]+-----/,"")}var t=r.replace(/\s+/g,"");var p=b64tohex(t);return p},getDecryptedKeyHexByKeyIV:function(q,t,s,r){var p=c(t);return p(q,s,r)},parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getRSAKeyFromEncryptedPKCS5PEM:function(r,q){var s=this.getDecryptedKeyHex(r,q);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(s);return p},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw"KEYUTIL unsupported algorithm: "+t}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},getEncryptedPKCS5PEMFromRSAKey:function(D,E,r,t){var B=new KJUR.asn1.DERInteger({"int":0});var w=new KJUR.asn1.DERInteger({bigint:D.n});var A=new KJUR.asn1.DERInteger({"int":D.e});var C=new KJUR.asn1.DERInteger({bigint:D.d});var u=new KJUR.asn1.DERInteger({bigint:D.p});var s=new KJUR.asn1.DERInteger({bigint:D.q});var z=new KJUR.asn1.DERInteger({bigint:D.dmp1});var v=new KJUR.asn1.DERInteger({bigint:D.dmq1});var y=new KJUR.asn1.DERInteger({bigint:D.coeff});var F=new KJUR.asn1.DERSequence({array:[B,w,A,C,u,s,z,v,y]});var x=F.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,E,r,t)},newEncryptedPKCS5PEM:function(p,q,t,u){if(typeof q=="undefined"||q==null){q=1024}if(typeof t=="undefined"||t==null){t="10001"}var r=new RSAKey();r.generate(q,t);var s=null;if(typeof u=="undefined"||u==null){s=this.getEncryptedPKCS5PEMFromRSAKey(r,p)}else{s=this.getEncryptedPKCS5PEMFromRSAKey(r,p,u)}return s},getRSAKeyFromPlainPKCS8PEM:function(r){if(r.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var q=this.getHexFromPEM(r,"PRIVATE KEY");var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getRSAKeyFromPlainPKCS8Hex:function(s){var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"outer DERSequence shall have 3 elements: "+r.length}var q=ASN1HEX.getHexOfTLV_AtObj(s,r[1]);if(q!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmIdentifier is not rsaEnc: "+q}var q=ASN1HEX.getHexOfTLV_AtObj(s,r[1]);var t=ASN1HEX.getHexOfTLV_AtObj(s,r[2]);var u=ASN1HEX.getHexOfV_AtObj(t,0);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(u);return p},parseHexOfEncryptedPKCS8:function(w){var s={};var r=ASN1HEX.getPosArrayOfChildren_AtObj(w,0);if(r.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+r.length}s.ciphertext=ASN1HEX.getHexOfV_AtObj(w,r[1]);var y=ASN1HEX.getPosArrayOfChildren_AtObj(w,r[0]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+y.length}if(ASN1HEX.getHexOfV_AtObj(w,y[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(w,y[1]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+p.length}var q=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[1]);if(q.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length}if(ASN1HEX.getHexOfV_AtObj(w,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}s.encryptionSchemeAlg="TripleDES";s.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(w,q[1]);var t=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[0]);if(t.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+t.length}if(ASN1HEX.getHexOfV_AtObj(w,t[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var x=ASN1HEX.getPosArrayOfChildren_AtObj(w,t[1]);if(x.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length}s.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(w,x[0]);var u=ASN1HEX.getHexOfV_AtObj(w,x[1]);try{s.pbkdf2Iter=parseInt(u,16)}catch(v){throw"malformed format pbkdf2Iter: "+u}return s},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=this.getHexFromPEM(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getRSAKeyFromEncryptedPKCS8PEM:function(s,r){var q=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,r);var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(s.substr(r[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,r[1]);if(p.length!=2){throw"malformed PKCS8 private key(code:004)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}if(s.substr(r[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}q.keyidx=ASN1HEX.getStartPosOfV_AtObj(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=this.getHexFromPEM(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var w=this.parsePlainPrivatePKCS8Hex(p);if(w.algoid=="2a864886f70d010101"){this.parsePrivateRawRSAKeyHexAtObj(p,w);var u=w.key;var z=new RSAKey();z.setPrivateEx(u.n,u.e,u.d,u.p,u.q,u.dp,u.dq,u.co);return z}else{if(w.algoid=="2a8648ce3d0201"){this.parsePrivateRawECKeyHexAtObj(p,w);if(KJUR.crypto.OID.oidhex2name[w.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+w.algparam}var v=KJUR.crypto.OID.oidhex2name[w.algparam];var z=new KJUR.crypto.ECDSA({curve:v});z.setPublicKeyHex(w.pubkey);z.setPrivateKeyHex(w.key);z.isPublic=false;return z}else{if(w.algoid=="2a8648ce380401"){var t=ASN1HEX.getVbyList(p,0,[1,1,0],"02");var s=ASN1HEX.getVbyList(p,0,[1,1,1],"02");var y=ASN1HEX.getVbyList(p,0,[1,1,2],"02");var B=ASN1HEX.getVbyList(p,0,[2,0],"02");var r=new BigInteger(t,16);var q=new BigInteger(s,16);var x=new BigInteger(y,16);var A=new BigInteger(B,16);var z=new KJUR.crypto.DSA();z.setPrivate(r,q,x,null,A);return z}else{throw"unsupported private key algorithm"}}}},getRSAKeyFromPublicPKCS8PEM:function(q){var r=this.getHexFromPEM(q,"PUBLIC KEY");var p=this.getRSAKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8PEM:function(q){var r=this.getHexFromPEM(q,"PUBLIC KEY");var p=this.getKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8Hex:function(q){var p=this.parsePublicPKCS8Hex(q);if(p.algoid=="2a864886f70d010101"){var u=this.parsePublicRawRSAKeyHex(p.key);var r=new RSAKey();r.setPublic(u.n,u.e);return r}else{if(p.algoid=="2a8648ce3d0201"){if(KJUR.crypto.OID.oidhex2name[p.algparam]===undefined){throw"KJUR.crypto.OID.oidhex2name undefined: "+p.algparam}var s=KJUR.crypto.OID.oidhex2name[p.algparam];var r=new KJUR.crypto.ECDSA({curve:s,pub:p.key});return r}else{if(p.algoid=="2a8648ce380401"){var t=p.algparam;var v=ASN1HEX.getHexOfV_AtObj(p.key,0);var r=new KJUR.crypto.DSA();r.setPublic(new BigInteger(t.p,16),new BigInteger(t.q,16),new BigInteger(t.g,16),new BigInteger(v,16));return r}else{throw"unsupported public key algorithm"}}}},parsePublicRawRSAKeyHex:function(r){var p={};if(r.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"malformed RSA key(code:002)"}if(r.substr(q[0],2)!="02"){throw"malformed RSA key(code:003)"}p.n=ASN1HEX.getHexOfV_AtObj(r,q[0]);if(r.substr(q[1],2)!="02"){throw"malformed RSA key(code:004)"}p.e=ASN1HEX.getHexOfV_AtObj(r,q[1]);return p},parsePrivateRawRSAKeyHexAtObj:function(q,s){var r=s.keyidx;if(q.substr(r,2)!="30"){throw"malformed RSA private key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(q,r);if(p.length!=9){throw"malformed RSA private key(code:002)"}s.key={};s.key.n=ASN1HEX.getHexOfV_AtObj(q,p[1]);s.key.e=ASN1HEX.getHexOfV_AtObj(q,p[2]);s.key.d=ASN1HEX.getHexOfV_AtObj(q,p[3]);s.key.p=ASN1HEX.getHexOfV_AtObj(q,p[4]);s.key.q=ASN1HEX.getHexOfV_AtObj(q,p[5]);s.key.dp=ASN1HEX.getHexOfV_AtObj(q,p[6]);s.key.dq=ASN1HEX.getHexOfV_AtObj(q,p[7]);s.key.co=ASN1HEX.getHexOfV_AtObj(q,p[8])},parsePrivateRawECKeyHexAtObj:function(p,t){var q=t.keyidx;var r=ASN1HEX.getVbyList(p,q,[1],"04");var s=ASN1HEX.getVbyList(p,q,[2,0],"03").substr(2);t.key=r;t.pubkey=s},parsePublicPKCS8Hex:function(s){var q={};q.algparam=null;var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=2){throw"outer DERSequence shall have 2 elements: "+r.length}var t=r[0];if(s.substr(t,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,t);if(p.length!=2){throw"malformed PKCS8 public key(code:002)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}else{if(s.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=ASN1HEX.getVbyList(s,p[1],[0],"02");q.algparam.q=ASN1HEX.getVbyList(s,p[1],[1],"02");q.algparam.g=ASN1HEX.getVbyList(s,p[1],[2],"02")}}if(s.substr(r[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}q.key=ASN1HEX.getHexOfV_AtObj(s,r[1]).substr(2);return q},getRSAKeyFromPublicPKCS8Hex:function(t){var s=ASN1HEX.getPosArrayOfChildren_AtObj(t,0);if(s.length!=2){throw"outer DERSequence shall have 2 elements: "+s.length}var r=ASN1HEX.getHexOfTLV_AtObj(t,s[0]);if(r!="300d06092a864886f70d0101010500"){throw"PKCS8 AlgorithmId is not rsaEncryption"}if(t.substr(s[1],2)!="03"){throw"PKCS8 Public Key is not BITSTRING encapslated."}var v=ASN1HEX.getStartPosOfV_AtObj(t,s[1])+2;if(t.substr(v,2)!="30"){throw"PKCS8 Public Key is not SEQUENCE."}var p=ASN1HEX.getPosArrayOfChildren_AtObj(t,v);if(p.length!=2){throw"inner DERSequence shall have 2 elements: "+p.length}if(t.substr(p[0],2)!="02"){throw"N is not ASN.1 INTEGER"}if(t.substr(p[1],2)!="02"){throw"E is not ASN.1 INTEGER"}var w=ASN1HEX.getHexOfV_AtObj(t,p[0]);var u=ASN1HEX.getHexOfV_AtObj(t,p[1]);var q=new RSAKey();q.setPublic(w,u);return q},}}();KEYUTIL.getKey=function(f,e,h){if(typeof RSAKey!="undefined"&&f instanceof RSAKey){return f}if(typeof KJUR.crypto.ECDSA!="undefined"&&f instanceof KJUR.crypto.ECDSA){return f}if(typeof KJUR.crypto.DSA!="undefined"&&f instanceof KJUR.crypto.DSA){return f}if(f.curve!==undefined&&f.xy!==undefined&&f.d===undefined){return new KJUR.crypto.ECDSA({pub:f.xy,curve:f.curve})}if(f.curve!==undefined&&f.d!==undefined){return new KJUR.crypto.ECDSA({prv:f.d,curve:f.curve})}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d===undefined){var w=new RSAKey();w.setPublic(f.n,f.e);return w}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p!==undefined&&f.q!==undefined&&f.dp!==undefined&&f.dq!==undefined&&f.co!==undefined&&f.qi===undefined){var w=new RSAKey();w.setPrivateEx(f.n,f.e,f.d,f.p,f.q,f.dp,f.dq,f.co);return w}if(f.kty===undefined&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p===undefined){var w=new RSAKey();w.setPrivate(f.n,f.e,f.d);return w}if(f.p!==undefined&&f.q!==undefined&&f.g!==undefined&&f.y!==undefined&&f.x===undefined){var w=new KJUR.crypto.DSA();w.setPublic(f.p,f.q,f.g,f.y);return w}if(f.p!==undefined&&f.q!==undefined&&f.g!==undefined&&f.y!==undefined&&f.x!==undefined){var w=new KJUR.crypto.DSA();w.setPrivate(f.p,f.q,f.g,f.y,f.x);return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d===undefined){var w=new RSAKey();w.setPublic(b64utohex(f.n),b64utohex(f.e));return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined&&f.p!==undefined&&f.q!==undefined&&f.dp!==undefined&&f.dq!==undefined&&f.qi!==undefined){var w=new RSAKey();w.setPrivateEx(b64utohex(f.n),b64utohex(f.e),b64utohex(f.d),b64utohex(f.p),b64utohex(f.q),b64utohex(f.dp),b64utohex(f.dq),b64utohex(f.qi));return w}if(f.kty==="RSA"&&f.n!==undefined&&f.e!==undefined&&f.d!==undefined){var w=new RSAKey();w.setPrivate(b64utohex(f.n),b64utohex(f.e),b64utohex(f.d));return w}if(f.kty==="EC"&&f.crv!==undefined&&f.x!==undefined&&f.y!==undefined&&f.d===undefined){var d=new KJUR.crypto.ECDSA({curve:f.crv});var l=d.ecparams.keylen/4;var r=("0000000000"+b64utohex(f.x)).slice(-l);var n=("0000000000"+b64utohex(f.y)).slice(-l);var m="04"+r+n;d.setPublicKeyHex(m);return d}if(f.kty==="EC"&&f.crv!==undefined&&f.x!==undefined&&f.y!==undefined&&f.d!==undefined){var d=new KJUR.crypto.ECDSA({curve:f.crv});var l=d.ecparams.keylen/4;var r=("0000000000"+b64utohex(f.x)).slice(-l);var n=("0000000000"+b64utohex(f.y)).slice(-l);var m="04"+r+n;var a=("0000000000"+b64utohex(f.d)).slice(-l);d.setPublicKeyHex(m);d.setPrivateKeyHex(a);return d}if(f.indexOf("-END CERTIFICATE-",0)!=-1||f.indexOf("-END X509 CERTIFICATE-",0)!=-1||f.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(f)}if(h==="pkcs8pub"){return KEYUTIL.getKeyFromPublicPKCS8Hex(f)}if(f.indexOf("-END PUBLIC KEY-")!=-1){return KEYUTIL.getKeyFromPublicPKCS8PEM(f)}if(h==="pkcs5prv"){var w=new RSAKey();w.readPrivateKeyFromASN1HexString(f);return w}if(h==="pkcs5prv"){var w=new RSAKey();w.readPrivateKeyFromASN1HexString(f);return w}if(f.indexOf("-END RSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")==-1){var i=KEYUTIL.getHexFromPEM(f,"RSA PRIVATE KEY");return KEYUTIL.getKey(i,null,"pkcs5prv")}if(f.indexOf("-END DSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")==-1){var u=this.getHexFromPEM(f,"DSA PRIVATE KEY");var t=ASN1HEX.getVbyList(u,0,[1],"02");var s=ASN1HEX.getVbyList(u,0,[2],"02");var v=ASN1HEX.getVbyList(u,0,[3],"02");var j=ASN1HEX.getVbyList(u,0,[4],"02");var k=ASN1HEX.getVbyList(u,0,[5],"02");var w=new KJUR.crypto.DSA();w.setPrivate(new BigInteger(t,16),new BigInteger(s,16),new BigInteger(v,16),new BigInteger(j,16),new BigInteger(k,16));return w}if(f.indexOf("-END PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(f)}if(f.indexOf("-END RSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(f,e)}if(f.indexOf("-END EC PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){var u=KEYUTIL.getDecryptedKeyHex(f,e);var w=ASN1HEX.getVbyList(u,0,[1],"04");var c=ASN1HEX.getVbyList(u,0,[2,0],"06");var o=ASN1HEX.getVbyList(u,0,[3,0],"03").substr(2);var b="";if(KJUR.crypto.OID.oidhex2name[c]!==undefined){b=KJUR.crypto.OID.oidhex2name[c]}else{throw"undefined OID(hex) in KJUR.crypto.OID: "+c}var d=new KJUR.crypto.ECDSA({name:b});d.setPublicKeyHex(o);d.setPrivateKeyHex(w);d.isPublic=false;return d}if(f.indexOf("-END DSA PRIVATE KEY-")!=-1&&f.indexOf("4,ENCRYPTED")!=-1){var u=KEYUTIL.getDecryptedKeyHex(f,e);var t=ASN1HEX.getVbyList(u,0,[1],"02");var s=ASN1HEX.getVbyList(u,0,[2],"02");var v=ASN1HEX.getVbyList(u,0,[3],"02");var j=ASN1HEX.getVbyList(u,0,[4],"02");var k=ASN1HEX.getVbyList(u,0,[5],"02");var w=new KJUR.crypto.DSA();w.setPrivate(new BigInteger(t,16),new BigInteger(s,16),new BigInteger(v,16),new BigInteger(j,16),new BigInteger(k,16));return w}if(f.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromEncryptedPKCS8PEM(f,e)}throw"not supported argument"};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw"unknown algorithm: "+a}}};KEYUTIL.getPEM=function(a,r,o,g,j){var v=KJUR.asn1;var u=KJUR.crypto;function p(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return w}function q(w){var s=KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:w.prvKeyHex}},{tag:["a0",true,{oid:{name:w.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+w.pubKeyHex}}]}]});return s}function n(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return w}if(((typeof RSAKey!="undefined"&&a instanceof RSAKey)||(typeof u.DSA!="undefined"&&a instanceof u.DSA)||(typeof u.ECDSA!="undefined"&&a instanceof u.ECDSA))&&a.isPublic==true&&(r===undefined||r=="PKCS8PUB")){var t=new KJUR.asn1.x509.SubjectPublicKeyInfo(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"PUBLIC KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o===undefined||o==null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"RSA PRIVATE KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o===undefined||o==null)&&a.isPrivate==true){var f=new KJUR.asn1.DERObjectIdentifier({name:a.curveName});var l=f.getEncodedHex();var e=q(a);var k=e.getEncodedHex();var i="";i+=v.ASN1Util.getPEMStringFromHex(l,"EC PARAMETERS");i+=v.ASN1Util.getPEMStringFromHex(k,"EC PRIVATE KEY");return i}if(r=="PKCS1PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o===undefined||o==null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"DSA PRIVATE KEY")}if(r=="PKCS5PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=q(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",m,o,g)}var h=function(w,s){var y=b(w,s);var x=new KJUR.asn1.ASN1Util.newObject({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:y.pbkdf2Salt}},{"int":y.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:y.encryptionSchemeIV}}]}]}]},{octstr:{hex:y.ciphertext}}]});return x.getEncodedHex()};var b=function(D,E){var x=100;var C=CryptoJS.lib.WordArray.random(8);var B="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var y=CryptoJS.PBKDF2(E,C,{keySize:192/32,iterations:x});var z=CryptoJS.enc.Hex.parse(D);var A=CryptoJS.TripleDES.encrypt(z,y,{iv:s})+"";var w={};w.ciphertext=A;w.pbkdf2Salt=CryptoJS.enc.Hex.stringify(C);w.pbkdf2Iter=x;w.encryptionSchemeAlg=B;w.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return w};if(r=="PKCS8PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&a.isPrivate==true){var d=p(a);var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&a.isPrivate==true){var d=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:a.prvKeyHex}},{tag:["a1",true,{bitstr:{hex:"00"+a.pubKeyHex}}]}]});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:a.curveName}}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&a.isPrivate==true){var d=new KJUR.asn1.DERInteger({bigint:a.x});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:a.p}},{"int":{bigint:a.q}},{"int":{bigint:a.g}}]}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}throw"unsupported object nor format"};KEYUTIL.getKeyFromCSRPEM=function(b){var a=KEYUTIL.getHexFromPEM(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(c){var b={};var e=c;if(e.substr(0,2)!="30"){throw"malformed CSR(code:001)"}var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,0);if(d.length<1){throw"malformed CSR(code:002)"}if(e.substr(d[0],2)!="30"){throw"malformed CSR(code:003)"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(e,d[0]);if(a.length<3){throw"malformed CSR(code:004)"}b.p8pubkeyhex=ASN1HEX.getHexOfTLV_AtObj(e,a[2]);return b};KEYUTIL.getJWKFromKey=function(d){var b={};if(d instanceof RSAKey&&d.isPrivate){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));b.d=hextob64u(d.d.toString(16));b.p=hextob64u(d.p.toString(16));b.q=hextob64u(d.q.toString(16));b.dp=hextob64u(d.dmp1.toString(16));b.dq=hextob64u(d.dmq1.toString(16));b.qi=hextob64u(d.coeff.toString(16));return b}else{if(d instanceof RSAKey&&d.isPublic){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPrivate){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);b.d=hextob64u(d.prvKeyHex);return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPublic){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);return b}}}}throw"not supported key object"}; -/*! rsapem-1.1.js (c) 2012 Kenji Urushima | kjur.github.com/jsrsasign/license +var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",getHexFromPEM:function(p,q){return ASN1HEX.pemToHex(p,q)},getDecryptedKeyHexByKeyIV:function(q,t,s,r){var p=c(t);return p(q,s,r)},parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getRSAKeyFromEncryptedPKCS5PEM:function(r,q){var s=this.getDecryptedKeyHex(r,q);var p=new RSAKey();p.readPrivateKeyFromASN1HexString(s);return p},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw"KEYUTIL unsupported algorithm: "+t}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},getEncryptedPKCS5PEMFromRSAKey:function(D,E,r,t){var B=new KJUR.asn1.DERInteger({"int":0});var w=new KJUR.asn1.DERInteger({bigint:D.n});var A=new KJUR.asn1.DERInteger({"int":D.e});var C=new KJUR.asn1.DERInteger({bigint:D.d});var u=new KJUR.asn1.DERInteger({bigint:D.p});var s=new KJUR.asn1.DERInteger({bigint:D.q});var z=new KJUR.asn1.DERInteger({bigint:D.dmp1});var v=new KJUR.asn1.DERInteger({bigint:D.dmq1});var y=new KJUR.asn1.DERInteger({bigint:D.coeff});var F=new KJUR.asn1.DERSequence({array:[B,w,A,C,u,s,z,v,y]});var x=F.getEncodedHex();return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",x,E,r,t)},newEncryptedPKCS5PEM:function(p,q,t,u){if(typeof q=="undefined"||q==null){q=1024}if(typeof t=="undefined"||t==null){t="10001"}var r=new RSAKey();r.generate(q,t);var s=null;if(typeof u=="undefined"||u==null){s=this.getEncryptedPKCS5PEMFromRSAKey(r,p)}else{s=this.getEncryptedPKCS5PEMFromRSAKey(r,p,u)}return s},getRSAKeyFromPlainPKCS8PEM:function(r){if(r.match(/ENCRYPTED/)){throw"pem shall be not ENCRYPTED"}var q=ASN1HEX.pemToHex(r,"PRIVATE KEY");var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getRSAKeyFromPlainPKCS8Hex:function(q){var p=new RSAKey();p.readPKCS8PrvKeyHex(q);return p},parseHexOfEncryptedPKCS8:function(w){var s={};var r=ASN1HEX.getPosArrayOfChildren_AtObj(w,0);if(r.length!=2){throw"malformed format: SEQUENCE(0).items != 2: "+r.length}s.ciphertext=ASN1HEX.getHexOfV_AtObj(w,r[1]);var y=ASN1HEX.getPosArrayOfChildren_AtObj(w,r[0]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0).items != 2: "+y.length}if(ASN1HEX.getHexOfV_AtObj(w,y[0])!="2a864886f70d01050d"){throw"this only supports pkcs5PBES2"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(w,y[1]);if(y.length!=2){throw"malformed format: SEQUENCE(0.0.1).items != 2: "+p.length}var q=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[1]);if(q.length!=2){throw"malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length}if(ASN1HEX.getHexOfV_AtObj(w,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}s.encryptionSchemeAlg="TripleDES";s.encryptionSchemeIV=ASN1HEX.getHexOfV_AtObj(w,q[1]);var t=ASN1HEX.getPosArrayOfChildren_AtObj(w,p[0]);if(t.length!=2){throw"malformed format: SEQUENCE(0.0.1.0).items != 2: "+t.length}if(ASN1HEX.getHexOfV_AtObj(w,t[0])!="2a864886f70d01050c"){throw"this only supports pkcs5PBKDF2"}var x=ASN1HEX.getPosArrayOfChildren_AtObj(w,t[1]);if(x.length<2){throw"malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length}s.pbkdf2Salt=ASN1HEX.getHexOfV_AtObj(w,x[0]);var u=ASN1HEX.getHexOfV_AtObj(w,x[1]);try{s.pbkdf2Iter=parseInt(u,16)}catch(v){throw"malformed format pbkdf2Iter: "+u}return s},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=ASN1HEX.pemToHex(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getRSAKeyFromEncryptedPKCS8PEM:function(s,r){var q=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,r);var p=this.getRSAKeyFromPlainPKCS8Hex(q);return p},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this.getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw"malformed plain PKCS8 private key(code:001)"}var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=3){throw"malformed plain PKCS8 private key(code:002)"}if(s.substr(r[1],2)!="30"){throw"malformed PKCS8 private key(code:003)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,r[1]);if(p.length!=2){throw"malformed PKCS8 private key(code:004)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 private key(code:005)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}if(s.substr(r[2],2)!="04"){throw"malformed PKCS8 private key(code:006)"}q.keyidx=ASN1HEX.getStartPosOfV_AtObj(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=ASN1HEX.pemToHex(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var q=this.parsePlainPrivatePKCS8Hex(p);var r;if(q.algoid=="2a864886f70d010101"){r=new RSAKey()}else{if(q.algoid=="2a8648ce380401"){r=new KJUR.crypto.DSA()}else{if(q.algoid=="2a8648ce3d0201"){r=new KJUR.crypto.ECDSA()}else{throw"unsupported private key algorithm"}}}r.readPKCS8PrvKeyHex(p);return r},getRSAKeyFromPublicPKCS8PEM:function(q){var r=ASN1HEX.pemToHex(q,"PUBLIC KEY");var p=this.getRSAKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8PEM:function(q){var r=ASN1HEX.pemToHex(q,"PUBLIC KEY");var p=this.getKeyFromPublicPKCS8Hex(r);return p},getKeyFromPublicPKCS8Hex:function(q){var p;var r=ASN1HEX.getVbyList(q,0,[0,0],"06");if(r==="2a864886f70d010101"){p=new RSAKey()}else{if(r==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(r==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw"unsupported PKCS#8 public key hex"}}}p.readPKCS8PubKeyHex(q);return p},parsePublicRawRSAKeyHex:function(r){var p={};if(r.substr(0,2)!="30"){throw"malformed RSA key(code:001)"}var q=ASN1HEX.getPosArrayOfChildren_AtObj(r,0);if(q.length!=2){throw"malformed RSA key(code:002)"}if(r.substr(q[0],2)!="02"){throw"malformed RSA key(code:003)"}p.n=ASN1HEX.getHexOfV_AtObj(r,q[0]);if(r.substr(q[1],2)!="02"){throw"malformed RSA key(code:004)"}p.e=ASN1HEX.getHexOfV_AtObj(r,q[1]);return p},parsePrivateRawRSAKeyHexAtObj:function(q,u){var t=ASN1HEX;var r=t.getHexOfV_AtObj;var s=t.getDecendantIndexByNthList(q,0,[2,0]);var p=t.getPosArrayOfChildren_AtObj(q,s);if(p.length!==9){throw"malformed PKCS#8 plain RSA private key"}u.key={};u.key.n=r(q,p[1]);u.key.e=r(q,p[2]);u.key.d=r(q,p[3]);u.key.p=r(q,p[4]);u.key.q=r(q,p[5]);u.key.dp=r(q,p[6]);u.key.dq=r(q,p[7]);u.key.co=r(q,p[8])},parsePrivateRawECKeyHexAtObj:function(p,t){var s=ASN1HEX;var q=t.keyidx;var r=new KJUR.crypto.ECDSA();r.readPKCS8PrvKeyHex(p);t.key=r.prvKeyHex;t.pubkey=r.pubKeyHex},parsePublicPKCS8Hex:function(s){var q={};q.algparam=null;var r=ASN1HEX.getPosArrayOfChildren_AtObj(s,0);if(r.length!=2){throw"outer DERSequence shall have 2 elements: "+r.length}var t=r[0];if(s.substr(t,2)!="30"){throw"malformed PKCS8 public key(code:001)"}var p=ASN1HEX.getPosArrayOfChildren_AtObj(s,t);if(p.length!=2){throw"malformed PKCS8 public key(code:002)"}if(s.substr(p[0],2)!="06"){throw"malformed PKCS8 public key(code:003)"}q.algoid=ASN1HEX.getHexOfV_AtObj(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=ASN1HEX.getHexOfV_AtObj(s,p[1])}else{if(s.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=ASN1HEX.getVbyList(s,p[1],[0],"02");q.algparam.q=ASN1HEX.getVbyList(s,p[1],[1],"02");q.algparam.g=ASN1HEX.getVbyList(s,p[1],[2],"02")}}if(s.substr(r[1],2)!="03"){throw"malformed PKCS8 public key(code:004)"}q.key=ASN1HEX.getHexOfV_AtObj(s,r[1]).substr(2);return q},getRSAKeyFromPublicPKCS8Hex:function(p){var q=new RSAKey();q.readPKCS8PubKeyHex(p);return q},}}();KEYUTIL.getKey=function(i,f,j){if(typeof RSAKey!="undefined"&&i instanceof RSAKey){return i}if(typeof KJUR.crypto.ECDSA!="undefined"&&i instanceof KJUR.crypto.ECDSA){return i}if(typeof KJUR.crypto.DSA!="undefined"&&i instanceof KJUR.crypto.DSA){return i}if(i.curve!==undefined&&i.xy!==undefined&&i.d===undefined){return new KJUR.crypto.ECDSA({pub:i.xy,curve:i.curve})}if(i.curve!==undefined&&i.d!==undefined){return new KJUR.crypto.ECDSA({prv:i.d,curve:i.curve})}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d===undefined){var D=new RSAKey();D.setPublic(i.n,i.e);return D}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p!==undefined&&i.q!==undefined&&i.dp!==undefined&&i.dq!==undefined&&i.co!==undefined&&i.qi===undefined){var D=new RSAKey();D.setPrivateEx(i.n,i.e,i.d,i.p,i.q,i.dp,i.dq,i.co);return D}if(i.kty===undefined&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p===undefined){var D=new RSAKey();D.setPrivate(i.n,i.e,i.d);return D}if(i.p!==undefined&&i.q!==undefined&&i.g!==undefined&&i.y!==undefined&&i.x===undefined){var D=new KJUR.crypto.DSA();D.setPublic(i.p,i.q,i.g,i.y);return D}if(i.p!==undefined&&i.q!==undefined&&i.g!==undefined&&i.y!==undefined&&i.x!==undefined){var D=new KJUR.crypto.DSA();D.setPrivate(i.p,i.q,i.g,i.y,i.x);return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d===undefined){var D=new RSAKey();D.setPublic(b64utohex(i.n),b64utohex(i.e));return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined&&i.p!==undefined&&i.q!==undefined&&i.dp!==undefined&&i.dq!==undefined&&i.qi!==undefined){var D=new RSAKey();D.setPrivateEx(b64utohex(i.n),b64utohex(i.e),b64utohex(i.d),b64utohex(i.p),b64utohex(i.q),b64utohex(i.dp),b64utohex(i.dq),b64utohex(i.qi));return D}if(i.kty==="RSA"&&i.n!==undefined&&i.e!==undefined&&i.d!==undefined){var D=new RSAKey();D.setPrivate(b64utohex(i.n),b64utohex(i.e),b64utohex(i.d));return D}if(i.kty==="EC"&&i.crv!==undefined&&i.x!==undefined&&i.y!==undefined&&i.d===undefined){var e=new KJUR.crypto.ECDSA({curve:i.crv});var n=e.ecparams.keylen/4;var t=("0000000000"+b64utohex(i.x)).slice(-n);var r=("0000000000"+b64utohex(i.y)).slice(-n);var o="04"+t+r;e.setPublicKeyHex(o);return e}if(i.kty==="EC"&&i.crv!==undefined&&i.x!==undefined&&i.y!==undefined&&i.d!==undefined){var e=new KJUR.crypto.ECDSA({curve:i.crv});var n=e.ecparams.keylen/4;var t=("0000000000"+b64utohex(i.x)).slice(-n);var r=("0000000000"+b64utohex(i.y)).slice(-n);var o="04"+t+r;var b=("0000000000"+b64utohex(i.d)).slice(-n);e.setPublicKeyHex(o);e.setPrivateKeyHex(b);return e}if(j==="pkcs5prv"){var A=i,w=ASN1HEX,C,D;C=w.getPosArrayOfChildren_AtObj(A,0);if(C.length===9){D=new RSAKey();D.readPrivateKeyFromASN1HexString(i)}else{if(C.length===6){D=new KJUR.crypto.DSA();D.readPKCS5PrvKeyHex(A)}else{if(C.length>2&&A.substr(C[1],2)==="04"){D=new KJUR.crypto.ECDSA();D.readPKCS5PrvKeyHex(A)}else{throw"unsupported PKCS#1/5 hexadecimal key"}}}return D}if(j==="pkcs8prv"){var D=KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(i);return D}if(j==="pkcs8pub"){return KEYUTIL.getKeyFromPublicPKCS8Hex(i)}if(j==="x509pub"){return X509.getPublicKeyFromCertHex(i)}if(i.indexOf("-END CERTIFICATE-",0)!=-1||i.indexOf("-END X509 CERTIFICATE-",0)!=-1||i.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(i)}if(i.indexOf("-END PUBLIC KEY-")!=-1){return KEYUTIL.getKeyFromPublicPKCS8PEM(i)}if(i.indexOf("-END RSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")==-1){var k=ASN1HEX.pemToHex(i,"RSA PRIVATE KEY");return KEYUTIL.getKey(k,null,"pkcs5prv")}if(i.indexOf("-END DSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")==-1){var z=ASN1HEX.pemToHex(i,"DSA PRIVATE KEY");var v=ASN1HEX.getVbyList(z,0,[1],"02");var u=ASN1HEX.getVbyList(z,0,[2],"02");var B=ASN1HEX.getVbyList(z,0,[3],"02");var l=ASN1HEX.getVbyList(z,0,[4],"02");var m=ASN1HEX.getVbyList(z,0,[5],"02");var D=new KJUR.crypto.DSA();D.setPrivate(new BigInteger(v,16),new BigInteger(u,16),new BigInteger(B,16),new BigInteger(l,16),new BigInteger(m,16));return D}if(i.indexOf("-END PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromPlainPrivatePKCS8PEM(i)}if(i.indexOf("-END RSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){return KEYUTIL.getRSAKeyFromEncryptedPKCS5PEM(i,f)}if(i.indexOf("-END EC PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){var z=KEYUTIL.getDecryptedKeyHex(i,f);var D=ASN1HEX.getVbyList(z,0,[1],"04");var d=ASN1HEX.getVbyList(z,0,[2,0],"06");var s=ASN1HEX.getVbyList(z,0,[3,0],"03").substr(2);var c="";if(KJUR.crypto.OID.oidhex2name[d]!==undefined){c=KJUR.crypto.OID.oidhex2name[d]}else{throw"undefined OID(hex) in KJUR.crypto.OID: "+d}var e=new KJUR.crypto.ECDSA({curve:c});e.setPublicKeyHex(s);e.setPrivateKeyHex(D);e.isPublic=false;return e}if(i.indexOf("-END DSA PRIVATE KEY-")!=-1&&i.indexOf("4,ENCRYPTED")!=-1){var z=KEYUTIL.getDecryptedKeyHex(i,f);var v=ASN1HEX.getVbyList(z,0,[1],"02");var u=ASN1HEX.getVbyList(z,0,[2],"02");var B=ASN1HEX.getVbyList(z,0,[3],"02");var l=ASN1HEX.getVbyList(z,0,[4],"02");var m=ASN1HEX.getVbyList(z,0,[5],"02");var D=new KJUR.crypto.DSA();D.setPrivate(new BigInteger(v,16),new BigInteger(u,16),new BigInteger(B,16),new BigInteger(l,16),new BigInteger(m,16));return D}if(i.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return KEYUTIL.getKeyFromEncryptedPKCS8PEM(i,f)}throw"not supported argument"};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw"unknown algorithm: "+a}}};KEYUTIL.getPEM=function(a,r,o,g,j){var v=KJUR.asn1;var u=KJUR.crypto;function p(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return w}function q(w){var s=KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:w.prvKeyHex}},{tag:["a0",true,{oid:{name:w.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+w.pubKeyHex}}]}]});return s}function n(s){var w=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return w}if(((typeof RSAKey!="undefined"&&a instanceof RSAKey)||(typeof u.DSA!="undefined"&&a instanceof u.DSA)||(typeof u.ECDSA!="undefined"&&a instanceof u.ECDSA))&&a.isPublic==true&&(r===undefined||r=="PKCS8PUB")){var t=new KJUR.asn1.x509.SubjectPublicKeyInfo(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"PUBLIC KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o===undefined||o==null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"RSA PRIVATE KEY")}if(r=="PKCS1PRV"&&typeof RSAKey!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o===undefined||o==null)&&a.isPrivate==true){var f=new KJUR.asn1.DERObjectIdentifier({name:a.curveName});var l=f.getEncodedHex();var e=q(a);var k=e.getEncodedHex();var i="";i+=v.ASN1Util.getPEMStringFromHex(l,"EC PARAMETERS");i+=v.ASN1Util.getPEMStringFromHex(k,"EC PRIVATE KEY");return i}if(r=="PKCS1PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o===undefined||o==null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();return v.ASN1Util.getPEMStringFromHex(m,"DSA PRIVATE KEY")}if(r=="PKCS5PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=p(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=q(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",m,o,g)}if(r=="PKCS5PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&(o!==undefined&&o!=null)&&a.isPrivate==true){var t=n(a);var m=t.getEncodedHex();if(g===undefined){g="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",m,o,g)}var h=function(w,s){var y=b(w,s);var x=new KJUR.asn1.ASN1Util.newObject({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:y.pbkdf2Salt}},{"int":y.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:y.encryptionSchemeIV}}]}]}]},{octstr:{hex:y.ciphertext}}]});return x.getEncodedHex()};var b=function(D,E){var x=100;var C=CryptoJS.lib.WordArray.random(8);var B="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var y=CryptoJS.PBKDF2(E,C,{keySize:192/32,iterations:x});var z=CryptoJS.enc.Hex.parse(D);var A=CryptoJS.TripleDES.encrypt(z,y,{iv:s})+"";var w={};w.ciphertext=A;w.pbkdf2Salt=CryptoJS.enc.Hex.stringify(C);w.pbkdf2Iter=x;w.encryptionSchemeAlg=B;w.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return w};if(r=="PKCS8PRV"&&typeof RSAKey!="undefined"&&a instanceof RSAKey&&a.isPrivate==true){var d=p(a);var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.ECDSA!="undefined"&&a instanceof KJUR.crypto.ECDSA&&a.isPrivate==true){var d=new KJUR.asn1.ASN1Util.newObject({seq:[{"int":1},{octstr:{hex:a.prvKeyHex}},{tag:["a1",true,{bitstr:{hex:"00"+a.pubKeyHex}}]}]});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:a.curveName}}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}if(r=="PKCS8PRV"&&typeof KJUR.crypto.DSA!="undefined"&&a instanceof KJUR.crypto.DSA&&a.isPrivate==true){var d=new KJUR.asn1.DERInteger({bigint:a.x});var c=d.getEncodedHex();var t=KJUR.asn1.ASN1Util.newObject({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:a.p}},{"int":{bigint:a.q}},{"int":{bigint:a.g}}]}]},{octstr:{hex:c}}]});var m=t.getEncodedHex();if(o===undefined||o==null){return v.ASN1Util.getPEMStringFromHex(m,"PRIVATE KEY")}else{var k=h(m,o);return v.ASN1Util.getPEMStringFromHex(k,"ENCRYPTED PRIVATE KEY")}}throw"unsupported object nor format"};KEYUTIL.getKeyFromCSRPEM=function(b){var a=ASN1HEX.pemToHex(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(c){var b={};var e=c;if(e.substr(0,2)!="30"){throw"malformed CSR(code:001)"}var d=ASN1HEX.getPosArrayOfChildren_AtObj(e,0);if(d.length<1){throw"malformed CSR(code:002)"}if(e.substr(d[0],2)!="30"){throw"malformed CSR(code:003)"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(e,d[0]);if(a.length<3){throw"malformed CSR(code:004)"}b.p8pubkeyhex=ASN1HEX.getHexOfTLV_AtObj(e,a[2]);return b};KEYUTIL.getJWKFromKey=function(d){var b={};if(d instanceof RSAKey&&d.isPrivate){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));b.d=hextob64u(d.d.toString(16));b.p=hextob64u(d.p.toString(16));b.q=hextob64u(d.q.toString(16));b.dp=hextob64u(d.dmp1.toString(16));b.dq=hextob64u(d.dmq1.toString(16));b.qi=hextob64u(d.coeff.toString(16));return b}else{if(d instanceof RSAKey&&d.isPublic){b.kty="RSA";b.n=hextob64u(d.n.toString(16));b.e=hextob64u(d.e.toString(16));return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPrivate){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);b.d=hextob64u(d.prvKeyHex);return b}else{if(d instanceof KJUR.crypto.ECDSA&&d.isPublic){var a=d.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"){throw"unsupported curve name for JWT: "+a}var c=d.getPublicKeyXYHex();b.kty="EC";b.crv=a;b.x=hextob64u(c.x);b.y=hextob64u(c.y);return b}}}}throw"not supported key object"}; +/*! rsapem-1.2.0.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ -function _rsapem_pemToBase64(b){var a=b;a=a.replace("-----BEGIN RSA PRIVATE KEY-----","");a=a.replace("-----END RSA PRIVATE KEY-----","");a=a.replace(/[ \n]+/g,"");return a}function _rsapem_getPosArrayOfChildrenFromHex(d){var j=new Array();var k=ASN1HEX.getStartPosOfV_AtObj(d,0);var f=ASN1HEX.getPosOfNextSibling_AtObj(d,k);var h=ASN1HEX.getPosOfNextSibling_AtObj(d,f);var b=ASN1HEX.getPosOfNextSibling_AtObj(d,h);var l=ASN1HEX.getPosOfNextSibling_AtObj(d,b);var e=ASN1HEX.getPosOfNextSibling_AtObj(d,l);var g=ASN1HEX.getPosOfNextSibling_AtObj(d,e);var c=ASN1HEX.getPosOfNextSibling_AtObj(d,g);var i=ASN1HEX.getPosOfNextSibling_AtObj(d,c);j.push(k,f,h,b,l,e,g,c,i);return j}function _rsapem_getHexValueArrayOfChildrenFromHex(i){var o=_rsapem_getPosArrayOfChildrenFromHex(i);var r=ASN1HEX.getHexOfV_AtObj(i,o[0]);var f=ASN1HEX.getHexOfV_AtObj(i,o[1]);var j=ASN1HEX.getHexOfV_AtObj(i,o[2]);var k=ASN1HEX.getHexOfV_AtObj(i,o[3]);var c=ASN1HEX.getHexOfV_AtObj(i,o[4]);var b=ASN1HEX.getHexOfV_AtObj(i,o[5]);var h=ASN1HEX.getHexOfV_AtObj(i,o[6]);var g=ASN1HEX.getHexOfV_AtObj(i,o[7]);var l=ASN1HEX.getHexOfV_AtObj(i,o[8]);var m=new Array();m.push(r,f,j,k,c,b,h,g,l);return m}function _rsapem_readPrivateKeyFromASN1HexString(c){var b=_rsapem_getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])}function _rsapem_readPrivateKeyFromPEMString(e){var c=_rsapem_pemToBase64(e);var d=b64tohex(c);var b=_rsapem_getHexValueArrayOfChildrenFromHex(d);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])}RSAKey.prototype.readPrivateKeyFromPEMString=_rsapem_readPrivateKeyFromPEMString;RSAKey.prototype.readPrivateKeyFromASN1HexString=_rsapem_readPrivateKeyFromASN1HexString; +RSAKey.pemToBase64=function(b){var a=b;a=a.replace("-----BEGIN RSA PRIVATE KEY-----","");a=a.replace("-----END RSA PRIVATE KEY-----","");a=a.replace(/[ \n]+/g,"");return a};RSAKey.getPosArrayOfChildrenFromHex=function(g){var j=new Array();var i=ASN1HEX.getStartPosOfV_AtObj(g,0);var b=ASN1HEX.getPosOfNextSibling_AtObj(g,i);var e=ASN1HEX.getPosOfNextSibling_AtObj(g,b);var f=ASN1HEX.getPosOfNextSibling_AtObj(g,e);var l=ASN1HEX.getPosOfNextSibling_AtObj(g,f);var k=ASN1HEX.getPosOfNextSibling_AtObj(g,l);var d=ASN1HEX.getPosOfNextSibling_AtObj(g,k);var c=ASN1HEX.getPosOfNextSibling_AtObj(g,d);var h=ASN1HEX.getPosOfNextSibling_AtObj(g,c);j.push(i,b,e,f,l,k,d,c,h);return j};RSAKey.getHexValueArrayOfChildrenFromHex=function(f){var l=RSAKey.getPosArrayOfChildrenFromHex(f);var e=ASN1HEX.getHexOfV_AtObj(f,l[0]);var j=ASN1HEX.getHexOfV_AtObj(f,l[1]);var b=ASN1HEX.getHexOfV_AtObj(f,l[2]);var c=ASN1HEX.getHexOfV_AtObj(f,l[3]);var h=ASN1HEX.getHexOfV_AtObj(f,l[4]);var g=ASN1HEX.getHexOfV_AtObj(f,l[5]);var m=ASN1HEX.getHexOfV_AtObj(f,l[6]);var k=ASN1HEX.getHexOfV_AtObj(f,l[7]);var d=ASN1HEX.getHexOfV_AtObj(f,l[8]);var i=new Array();i.push(e,j,b,c,h,g,m,k,d);return i};RSAKey.prototype.readPrivateKeyFromPEMString=function(e){var c=RSAKey.pemToBase64(e);var d=b64tohex(c);var b=RSAKey.getHexValueArrayOfChildrenFromHex(d);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPrivateKeyFromASN1HexString=function(a){this.readPKCS5PrvKeyHex(a)};RSAKey.prototype.readPKCS5PrvKeyHex=function(c){var b=RSAKey.getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPKCS8PrvKeyHex=function(e){var c,j,l,b,a,f,d,k;var m=ASN1HEX;var g=m.getVbyList;if(m.isASN1HEX(e)===false){throw"not ASN.1 hex string"}try{c=g(e,0,[2,0,1],"02");j=g(e,0,[2,0,2],"02");l=g(e,0,[2,0,3],"02");b=g(e,0,[2,0,4],"02");a=g(e,0,[2,0,5],"02");f=g(e,0,[2,0,6],"02");d=g(e,0,[2,0,7],"02");k=g(e,0,[2,0,8],"02")}catch(i){throw"malformed PKCS#8 plain RSA private key"}this.setPrivateEx(c,j,l,b,a,f,d,k)};RSAKey.prototype.readPKCS5PubKeyHex=function(b){if(ASN1HEX.isASN1HEX(b)===false){throw"keyHex is not ASN.1 hex string"}var a=ASN1HEX.getPosArrayOfChildren_AtObj(b,0);if(a.length!==2||b.substr(a[0],2)!=="02"||b.substr(a[1],2)!=="02"){throw"wrong hex for PKCS#5 public key"}var d=ASN1HEX.getHexOfV_AtObj(b,a[0]);var c=ASN1HEX.getHexOfV_AtObj(b,a[1]);this.setPublic(d,c)};RSAKey.prototype.readPKCS8PubKeyHex=function(b){if(ASN1HEX.isASN1HEX(b)===false){throw"not ASN.1 hex string"}if(ASN1HEX.getDecendantHexTLVByNthList(b,0,[0,0])!=="06092a864886f70d010101"){throw"not PKCS8 RSA public key"}var a=ASN1HEX.getDecendantHexTLVByNthList(b,0,[1,0]);this.readPKCS5PubKeyHex(a)};RSAKey.prototype.readCertPubKeyHex=function(b,c){if(c!==5){c=6}if(ASN1HEX.isASN1HEX(b)===false){throw"not ASN.1 hex string"}var a=ASN1HEX.getDecendantHexTLVByNthList(b,0,[0,c]);this.readPKCS8PubKeyHex(a)}; /*! rsasign-1.2.7.js (c) 2012 Kenji Urushima | kjur.github.com/jsrsasign/license */ var _RE_HEXDECONLY=new RegExp("");_RE_HEXDECONLY.compile("[^0-9a-f]","gi");function _rsasign_getHexPaddedDigestInfoForString(d,e,a){var b=function(f){return KJUR.crypto.Util.hashString(f,a)};var c=b(d);return KJUR.crypto.Util.getPaddedDigestInfoHex(c,a,e)}function _zeroPaddingOfSignature(e,d){var c="";var a=d/4-e.length;for(var b=0;b>24,(d&16711680)>>16,(d&65280)>>8,d&255]))));d+=1}return b}function _rsasign_signStringPSS(e,a,d){var c=function(f){return KJUR.crypto.Util.hashHex(f,a)};var b=c(rstrtohex(e));if(d===undefined){d=-1}return this.signWithMessageHashPSS(b,a,d)}function _rsasign_signWithMessageHashPSS(l,a,k){var b=hextorstr(l);var g=b.length;var m=this.n.bitLength()-1;var c=Math.ceil(m/8);var d;var o=function(i){return KJUR.crypto.Util.hashHex(i,a)};if(k===-1||k===undefined){k=g}else{if(k===-2){k=c-g-2}else{if(k<-2){throw"invalid salt length"}}}if(c<(g+k+2)){throw"data too long"}var f="";if(k>0){f=new Array(k);new SecureRandom().nextBytes(f);f=String.fromCharCode.apply(String,f)}var n=hextorstr(o(rstrtohex("\x00\x00\x00\x00\x00\x00\x00\x00"+b+f)));var j=[];for(d=0;d>(8*c-m))&255;q[0]&=~p;for(d=0;dthis.n.bitLength()){return 0}var i=this.doPublic(b);var e=i.toString(16).replace(/^1f+00/,"");var g=_rsasign_getAlgNameAndHashFromHexDisgestInfo(e);if(g.length==0){return false}var d=g[0];var h=g[1];var a=function(k){return KJUR.crypto.Util.hashString(k,d)};var c=a(f);return(h==c)}function _rsasign_verifyWithMessageHash(e,a){a=a.replace(_RE_HEXDECONLY,"");a=a.replace(/[ \n]+/g,"");var b=parseBigInt(a,16);if(b.bitLength()>this.n.bitLength()){return 0}var h=this.doPublic(b);var g=h.toString(16).replace(/^1f+00/,"");var c=_rsasign_getAlgNameAndHashFromHexDisgestInfo(g);if(c.length==0){return false}var d=c[0];var f=c[1];return(f==e)}function _rsasign_verifyStringPSS(c,b,a,f){var e=function(g){return KJUR.crypto.Util.hashHex(g,a)};var d=e(rstrtohex(c));if(f===undefined){f=-1}return this.verifyWithMessageHashPSS(d,b,a,f)}function _rsasign_verifyWithMessageHashPSS(f,s,l,c){var k=new BigInteger(s,16);if(k.bitLength()>this.n.bitLength()){return false}var r=function(i){return KJUR.crypto.Util.hashHex(i,l)};var j=hextorstr(f);var h=j.length;var g=this.n.bitLength()-1;var m=Math.ceil(g/8);var q;if(c===-1||c===undefined){c=h}else{if(c===-2){c=m-h-2}else{if(c<-2){throw"invalid salt length"}}}if(m<(h+c+2)){throw"data too long"}var a=this.doPublic(k).toByteArray();for(q=0;q>(8*m-g))&255;if((d.charCodeAt(0)&p)!==0){throw"bits beyond keysize not zero"}var n=pss_mgf1_str(e,d.length,r);var o=[];for(q=0;q0){var c=":"+j.join(":")+":";if(c.indexOf(":"+h+":")==-1){throw"algorithm '"+h+"' not accepted in the list"}}if(h!="none"&&t===null){throw"key shall be specified to verify."}if(typeof t=="string"&&t.indexOf("-----BEGIN ")!=-1){t=KEYUTIL.getKey(t)}if(s=="RS"||s=="PS"){if(!(t instanceof RSAKey)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(s=="ES"){if(!(t instanceof KJUR.crypto.ECDSA)){throw"key shall be a ECDSA obj for ES* algs"}}if(h=="none"){}var n=null;if(m.jwsalg2sigalg[i.alg]===undefined){throw"unsupported alg name: "+h}else{n=m.jwsalg2sigalg[h]}if(n=="none"){throw"not supported"}else{if(n.substr(0,4)=="Hmac"){var k=null;if(t===undefined){throw"hexadecimal key shall be specified for HMAC"}var g=new KJUR.crypto.Mac({alg:n,pass:t});g.updateString(b);k=g.doFinal();return r==k}else{if(n.indexOf("withECDSA")!=-1){var f=null;try{f=KJUR.crypto.ECDSA.concatSigToASN1Sig(r)}catch(o){return false}var e=new KJUR.crypto.Signature({alg:n});e.init(t);e.updateString(b);return e.verify(f)}else{var e=new KJUR.crypto.Signature({alg:n});e.init(t);e.updateString(b);return e.verify(r)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(d,j,l){var h=KJUR.jws.JWS;var i=d.split(".");var c=i[0];var g=i[1];var m=c+"."+g;var k=b64utohex(i[2]);var f=h.readSafeJSONString(b64utoutf8(c));var e=h.readSafeJSONString(b64utoutf8(g));if(f.alg===undefined){return false}if(l.alg===undefined){throw"acceptField.alg shall be specified"}if(!h.inArray(f.alg,l.alg)){return false}if(e.iss!==undefined&&typeof l.iss==="object"){if(!h.inArray(e.iss,l.iss)){return false}}if(e.sub!==undefined&&typeof l.sub==="object"){if(!h.inArray(e.sub,l.sub)){return false}}if(e.aud!==undefined&&typeof l.aud==="object"){if(typeof e.aud=="string"){if(!h.inArray(e.aud,l.aud)){return false}}else{if(typeof e.aud=="object"){if(!h.includedArray(e.aud,l.aud)){return false}}}}var b=KJUR.jws.IntDate.getNow();if(l.verifyAt!==undefined&&typeof l.verifyAt==="number"){b=l.verifyAt}if(l.gracePeriod===undefined||typeof l.gracePeriod!=="number"){l.gracePeriod=0}if(e.exp!==undefined&&typeof e.exp=="number"){if(e.exp+l.gracePeriodMIT License */ -function _rsapem_pemToBase64(sPEMPrivateKey) { - var s = sPEMPrivateKey; - s = s.replace("-----BEGIN RSA PRIVATE KEY-----", ""); - s = s.replace("-----END RSA PRIVATE KEY-----", ""); - s = s.replace(/[ \n]+/g, ""); - return s; -} - -function _rsapem_getPosArrayOfChildrenFromHex(hPrivateKey) { - var a = new Array(); - var v1 = ASN1HEX.getStartPosOfV_AtObj(hPrivateKey, 0); - var n1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, v1); - var e1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, n1); - var d1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, e1); - var p1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, d1); - var q1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, p1); - var dp1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, q1); - var dq1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, dp1); - var co1 = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, dq1); - a.push(v1, n1, e1, d1, p1, q1, dp1, dq1, co1); - return a; -} - -function _rsapem_getHexValueArrayOfChildrenFromHex(hPrivateKey) { - var posArray = _rsapem_getPosArrayOfChildrenFromHex(hPrivateKey); - var v = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[0]); - var n = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[1]); - var e = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[2]); - var d = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[3]); - var p = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[4]); - var q = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[5]); - var dp = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[6]); - var dq = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[7]); - var co = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[8]); - var a = new Array(); - a.push(v, n, e, d, p, q, dp, dq, co); - return a; -} /** - * read RSA private key from a ASN.1 hexadecimal string + * static method to extract Base64 string from PKCS#5 PEM RSA private key.
    + * @name pemToBase64 + * @memberOf RSAKey + * @function + * @param {String} sPEMPrivateKey PEM PKCS#1/5 s private key string + * @return {String} Base64 string of private key + * @description + * removing PEM header, PEM footer and space characters including + * new lines from PEM formatted RSA private key string. + * @example + * RSAKey.pemToBase64("----BEGIN PRIVATE KEY-...") → "MIICW..." + */ +RSAKey.pemToBase64 = function(sPEMPrivateKey) { + var s = sPEMPrivateKey; + s = s.replace("-----BEGIN RSA PRIVATE KEY-----", ""); + s = s.replace("-----END RSA PRIVATE KEY-----", ""); + s = s.replace(/[ \n]+/g, ""); + return s; +}; + +/** + * static method to get array of field positions from hexadecimal PKCS#5 RSA private key.
    + * @name getPosArrayOfChildrenFromHex + * @memberOf RSAKey + * @function + * @param {String} sPEMPrivateKey PEM PKCS#1/5 s private key string + * @return {Array} array of field positions + * @example + * RSAKey.getPosArrayOfChildrenFromHex("3082...") → [8, 32, ...] + */ +RSAKey.getPosArrayOfChildrenFromHex = function(hPrivateKey) { + var a = new Array(); + var idx_v = ASN1HEX.getStartPosOfV_AtObj(hPrivateKey, 0); + var idx_n = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_v); + var idx_e = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_n); + var idx_d = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_e); + var idx_p = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_d); + var idx_q = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_p); + var idx_dp = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_q); + var idx_dq = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_dp); + var idx_co = ASN1HEX.getPosOfNextSibling_AtObj(hPrivateKey, idx_dq); + a.push(idx_v, idx_n, idx_e, idx_d, idx_p, idx_q, idx_dp, idx_dq, idx_co); + return a; +}; + +/** + * static method to get array of hex field values from hexadecimal PKCS#5 RSA private key.
    + * @name getHexValueArrayOfChildrenFromHex + * @memberOf RSAKey + * @function + * @param {String} sPEMPrivateKey PEM PKCS#1/5 s private key string + * @return {Array} array of field hex value + * @example + * RSAKey.getHexValueArrayOfChildrenFromHex("3082...") → ["00", "3b42...", ...] + */ +RSAKey.getHexValueArrayOfChildrenFromHex = function(hPrivateKey) { + var posArray = RSAKey.getPosArrayOfChildrenFromHex(hPrivateKey); + var h_v = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[0]); + var h_n = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[1]); + var h_e = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[2]); + var h_d = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[3]); + var h_p = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[4]); + var h_q = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[5]); + var h_dp = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[6]); + var h_dq = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[7]); + var h_co = ASN1HEX.getHexOfV_AtObj(hPrivateKey, posArray[8]); + var a = new Array(); + a.push(h_v, h_n, h_e, h_d, h_p, h_q, h_dp, h_dq, h_co); + return a; +}; + +/** + * read PKCS#1 private key from a string
    + * @name readPrivateKeyFromPEMString + * @memberOf RSAKey# + * @function + * @param {String} keyPEM string of PKCS#1 private key. + */ +RSAKey.prototype.readPrivateKeyFromPEMString = function(keyPEM) { + var keyB64 = RSAKey.pemToBase64(keyPEM); + var keyHex = b64tohex(keyB64) // depends base64.js + var a = RSAKey.getHexValueArrayOfChildrenFromHex(keyHex); + this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]); +}; + +/** + * (DEPRECATED) read RSA private key from a ASN.1 hexadecimal string
    * @name readPrivateKeyFromASN1HexString * @memberOf RSAKey# * @function * @param {String} keyHex ASN.1 hexadecimal string of PKCS#1 private key. - * @since 1.1.1 + * @since rsapem 1.1.1 + * @deprecated since jsrsasign 7.1.0 rsapem 1.2.0, please use {@link RSAKey.readPKCS5PrvKeyHex} instead. */ -function _rsapem_readPrivateKeyFromASN1HexString(keyHex) { - var a = _rsapem_getHexValueArrayOfChildrenFromHex(keyHex); - this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]); -} +RSAKey.prototype.readPrivateKeyFromASN1HexString = function(keyHex) { + this.readPKCS5PrvKeyHex(keyHex); +}; /** - * read PKCS#1 private key from a string - * @name readPrivateKeyFromPEMString + * read an ASN.1 hexadecimal string of PKCS#1/5 plain RSA private key
    + * @name readPKCS5PrvKeyHex * @memberOf RSAKey# * @function - * @param {String} keyPEM string of PKCS#1 private key. + * @param {String} h hexadecimal string of PKCS#1/5 plain RSA private key + * @since jsrsasign 7.1.0 rsapem 1.2.0 + * @see {@link RSAKey.readPrivateKeyFromASN1HexString} former method + */ +RSAKey.prototype.readPKCS5PrvKeyHex = function(h) { + var a = RSAKey.getHexValueArrayOfChildrenFromHex(h); + this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]); +}; + +/** + * read an ASN.1 hexadecimal string of PKCS#8 plain RSA private key
    + * @name readPKCS8PrvKeyHex + * @memberOf RSAKey# + * @function + * @param {String} h hexadecimal string of PKCS#8 plain RSA private key + * @since jsrsasign 7.1.0 rsapem 1.2.0 + */ +RSAKey.prototype.readPKCS8PrvKeyHex = function(h) { + var hN, hE, hD, hP, hQ, hDP, hDQ, hCO; + var _ASN1HEX = ASN1HEX; + var _getVbyList = _ASN1HEX.getVbyList; + + if (_ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + try { + hN = _getVbyList(h, 0, [2, 0, 1], "02"); + hE = _getVbyList(h, 0, [2, 0, 2], "02"); + hD = _getVbyList(h, 0, [2, 0, 3], "02"); + hP = _getVbyList(h, 0, [2, 0, 4], "02"); + hQ = _getVbyList(h, 0, [2, 0, 5], "02"); + hDP = _getVbyList(h, 0, [2, 0, 6], "02"); + hDQ = _getVbyList(h, 0, [2, 0, 7], "02"); + hCO = _getVbyList(h, 0, [2, 0, 8], "02"); + } catch(ex) { + throw "malformed PKCS#8 plain RSA private key"; + } + + this.setPrivateEx(hN, hE, hD, hP, hQ, hDP, hDQ, hCO); +}; + +/** + * read an ASN.1 hexadecimal string of PKCS#5 RSA public key
    + * @name readPKCS5PubKeyHex + * @memberOf RSAKey# + * @function + * @param {String} h hexadecimal string of PKCS#5 public key + * @since jsrsasign 7.1.0 rsapem 1.2.0 + */ +RSAKey.prototype.readPKCS5PubKeyHex = function(h) { + if (ASN1HEX.isASN1HEX(h) === false) + throw "keyHex is not ASN.1 hex string"; + var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(h, 0); + if (aIdx.length !== 2 || + h.substr(aIdx[0], 2) !== "02" || + h.substr(aIdx[1], 2) !== "02") + throw "wrong hex for PKCS#5 public key"; + var hN = ASN1HEX.getHexOfV_AtObj(h, aIdx[0]); + var hE = ASN1HEX.getHexOfV_AtObj(h, aIdx[1]); + this.setPublic(hN, hE); +}; + +/** + * read an ASN.1 hexadecimal string of PKCS#8 RSA public key
    + * @name readPKCS8PubKeyHex + * @memberOf RSAKey# + * @function + * @param {String} h hexadecimal string of PKCS#8 public key + * @since jsrsasign 7.1.0 rsapem 1.2.0 + */ +RSAKey.prototype.readPKCS8PubKeyHex = function(h) { + if (ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + // 06092a864886f70d010101: OBJECT IDENTIFIER rsaEncryption (1 2 840 113549 1 1 1) + if (ASN1HEX.getDecendantHexTLVByNthList(h, 0, [0, 0]) !== "06092a864886f70d010101") + throw "not PKCS8 RSA public key"; + + var p5hex = ASN1HEX.getDecendantHexTLVByNthList(h, 0, [1, 0]); + this.readPKCS5PubKeyHex(p5hex); +}; + +/** + * read an ASN.1 hexadecimal string of X.509 RSA public key certificate
    + * @name readCertPubKeyHex + * @memberOf RSAKey# + * @function + * @param {String} h hexadecimal string of X.509 RSA public key certificate + * @param {Integer} nthPKI nth index of publicKeyInfo. (DEFAULT: 6 for X509v3) + * @since jsrsasign 7.1.0 rsapem 1.2.0 */ -function _rsapem_readPrivateKeyFromPEMString(keyPEM) { - var keyB64 = _rsapem_pemToBase64(keyPEM); - var keyHex = b64tohex(keyB64) // depends base64.js - var a = _rsapem_getHexValueArrayOfChildrenFromHex(keyHex); - this.setPrivateEx(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]); -} - -RSAKey.prototype.readPrivateKeyFromPEMString = _rsapem_readPrivateKeyFromPEMString; -RSAKey.prototype.readPrivateKeyFromASN1HexString = _rsapem_readPrivateKeyFromASN1HexString; +RSAKey.prototype.readCertPubKeyHex = function(h, nthPKI) { + if (nthPKI !== 5) nthPKI = 6; + if (ASN1HEX.isASN1HEX(h) === false) + throw "not ASN.1 hex string"; + + var p8hex = ASN1HEX.getDecendantHexTLVByNthList(h, 0, [0, nthPKI]); + this.readPKCS8PubKeyHex(p8hex); +}; diff --git a/sample-rsasign.html b/sample-rsasign.html index ef9d45cc..e570838d 100644 --- a/sample-rsasign.html +++ b/sample-rsasign.html @@ -1,27 +1,7 @@ Sample Application for RSA signing in JavaScript - - - - - - - - - - - - - - - - - - - - - + + - +

    QUnit for Cryptographic Provider Class 'crypto.js'

    diff --git a/test/qunit-do-dsa.html b/test/qunit-do-dsa.html index 1cf4ed4d..e6314e43 100755 --- a/test/qunit-do-dsa.html +++ b/test/qunit-do-dsa.html @@ -54,6 +54,10 @@ var g = new BigInteger("711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e", 16); var y = new BigInteger("8cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b", 16); var x = new BigInteger("73b3538660ceac98a3bf48e53f88b4e124657c21", 16); +var D1PRVP5HEX = "308201bb020100028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b021473b3538660ceac98a3bf48e53f88b4e124657c21"; // d1.prv.p5p.der +var D1PRVP8HEX = "3082014a0201003082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e0416021473b3538660ceac98a3bf48e53f88b4e124657c21"; // d1.prv.p8p.der +var D1PUBP8HEX = "308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b"; // d1.pub.p8.der +var D1CERTHEX = "308202c430820282a003020102020900fd8cc68e37232612300b0609608648016503040302301a310b3009060355040613025553310b3009060355040a0c024431301e170d3133313030323135303434345a170d3233303933303135303434345a301a310b3009060355040613025553310b3009060355040a0c024431308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523ba350304e301d0603551d0e04160414b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a301f0603551d23041830168014b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a300c0603551d13040530030101ff300b0609608648016503040302032f00302c02147ff6dde28ad40095342cdbf2e5e2621ed30db85d021422c71bc20564bd68beecf2f631cd0e3f3c649430"; // d1.self.cer.der /* // This works only on FF. Fail on Chrome. @@ -124,6 +128,54 @@ ok(dsa2.verifyWithMessageHash(sHashHex, hSigVal), ""); }); +test("readPKCS5PrvKeyHex d1", function() { + var key = new KJUR.crypto.DSA(); + key.readPKCS5PrvKeyHex(D1PRVP5HEX); + equal(key.isPublic, false, "isPublic"); + equal(key.isPrivate, true, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(y.compareTo(key.y), 0, "Y"); + equal(x.compareTo(key.x), 0, "X"); +}); + +test("readPKCS8PrvKeyHex d1", function() { + var key = new KJUR.crypto.DSA(); + key.readPKCS8PrvKeyHex(D1PRVP8HEX); + equal(key.isPublic, false, "isPublic"); + equal(key.isPrivate, true, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(key.y, null, "Y"); + equal(x.compareTo(key.x), 0, "X"); +}); + +test("readPKCS8PubKeyHex d1", function() { + var key = new KJUR.crypto.DSA(); + key.readPKCS8PubKeyHex(D1PUBP8HEX); + equal(key.isPublic, true, "isPublic"); + equal(key.isPrivate, false, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(y.compareTo(key.y), 0, "Y"); + equal(key.x, null, "X"); +}); + +test("readCertPubKeyHex d1", function() { + var key = new KJUR.crypto.DSA(); + key.readCertPubKeyHex(D1CERTHEX); + equal(key.isPublic, true, "isPublic"); + equal(key.isPrivate, false, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(y.compareTo(key.y), 0, "Y"); + equal(key.x, null, "X"); +}); + }); --> diff --git a/test/qunit-do-ecdsamod-unsupport.html b/test/qunit-do-ecdsamod-unsupport.html new file mode 100755 index 00000000..43596153 --- /dev/null +++ b/test/qunit-do-ecdsamod-unsupport.html @@ -0,0 +1,99 @@ + + + + +QUnit 'ecdsamod.js' unsupported curve test (all fails) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    test markup
    + +NOTE: +

    +Currently this library works for only secp256r1, secp256k1 and secp384r1 EC curves +besides some other curves are pre-defined. +

    + +

    +INDEX | +ECC related QUnit test pages: +crypto.js | +crypto.js Signature class for ECDSA | +ecdsa-modified.js | +ecdsa-modified unsupported curve | +ecparam.js | +

    + + + diff --git a/test/qunit-do-ecdsamod.html b/test/qunit-do-ecdsamod.html index 78b0430b..8422e36f 100755 --- a/test/qunit-do-ecdsamod.html +++ b/test/qunit-do-ecdsamod.html @@ -45,6 +45,12 @@ var hashAAB256Hex = KJUR.crypto.Util.sha256("aab"); // SHA256 hash value of string "aab" var ECK1PUBHEX = "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"; // k1.pub.pem +var ECK1PRVRAWHEX = "11b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3"; +var ECK1PRVP5HEX = "3077020101042011b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3a00a06082a8648ce3d030107a14403420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"; // k1.prv.p5p.der +var ECK1PRVP8HEX = "308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b020101042011b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3a14403420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"; // k1.prv.p8p.der +var ECK1PUBP8HEX = "3059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"; // k1.pub.der +var ECK1CERTHEX = "3082017c30820121a003020102020900a6f110b42f4940cd300a06082a8648ce3d040302301a310b3009060355040613025553310b3009060355040a0c024b31301e170d3133303731343032313731375a170d3233303731323032313731375a301a310b3009060355040613025553310b3009060355040a0c024b313059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425a350304e301d0603551d0e04160414c847be327cccff638870757496e2be366c44a8fc301f0603551d23041830168014c847be327cccff638870757496e2be366c44a8fc300c0603551d13040530030101ff300a06082a8648ce3d0403020349003046022100df01c4bf58a06b3fa241824b10569a788ddab80b9dd8bb817936468c82d8401e022100d19175600fd50756f65ead8a0950c1da89b384f47bcf8d62ff917006f7558c27"; // k1.self.cer.der + test("default(secp256r1) sign and verify aaa", function() { // signing a message var prv = "11b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3"; @@ -102,24 +108,6 @@ equal(result2, true, "ecdsa sign"); }); -test("KNOWN ISSUE: k2.sig.aaa.1 secp192k1 sha256", function() { - // signature validation - var pub = "04874ca64f193b1080847bf3950366ed6bc05c884185574e21ac17dbd2e63a93d9bfff14a8e251da592bc4677de25458c0"; // k2.pub.pem - var ec2 = new KJUR.crypto.ECDSA({"curve": "secp192k1", "pub": pub}); - var sigHex = "3036021900e3503fd1f491de61f8bf9cb2777f0f203bb28c27f0a5cff9021900e789fc4af8c382ff2cfc97a94f562be1b56841693334e20b"; // k2.sig.aaa.1 - var result2 = ec2.verifyWithMessageHash(hashAAA256Hex, sigHex); - equal(result2, true, "ecdsa sign"); -}); - -test("KNOWN ISSUE: k3.sig.aaa.1 secp224r1 sha256", function() { - // signature validation - var pub = "04e34009a6c4dc3ddb0d39e1abac085cd4705e1d39a526d4843398432a093af22eb42891390266eb192cb9221725cd44d0c211317afb97349d"; // k3.pub.pem - var ec2 = new KJUR.crypto.ECDSA({"curve": "secp224r1", "pub": pub}); - var sigHex = "303e021d00e68ea9a165c343432f91df99136f66a3f5f2958a9644b6101880bf40021d008eb7cab62691b6998cbe78b0c5f21a28a84d83a8fda6bf7a69d85363"; // k3.sig.aaa.1 - var result2 = ec2.verifyWithMessageHash(hashAAA256Hex, sigHex); - equal(result2, true, "ecdsa sign"); -}); - test("k4.sig.aaa.1 secp256k1 sha256", function() { // signature validation var pub = "0422353f380062b2bde67712091386faa369ec5ef1a244d06c459fe3de1fb0a5d8ad23a3878be75e375546f14ca6e42755fee04bd78c0343ac8038f5a218e1fbc5"; // k4.pub.pem @@ -129,15 +117,6 @@ equal(result2, true, "ecdsa sign"); }); -test("KNOWN ISSUE: k5.sig.aaa.1 secp521r1 sha256", function() { - // signature validation - var pub = "0400d29a52344c35119ff5bea19ae090f802d05ff9ea31adcc31524d012875ea791344b02af06b58de3c3d26f1ba413d25d5cf9b6b287b5c9cf410bf2a6ea7ad02619d00de221502a15480f064d9d04c0bd40713e587ca72fc3009d338947454d63617b62e08a42fe9820153dcdf88445992e8cf204d8cefc4264c0d49d81e298307ed698f"; // k5.pub.der - var ec2 = new KJUR.crypto.ECDSA({"curve": "secp521r1", "pub": pub}); - var sigHex = "3081880242014ee923bd994ea00f7f20a6d7634a718b38e485ca9ebf0e2a794151fcba86cde56ef22c488245a05e8f158fedb8bfe775d039e3e6663fa104de732116a788627f5d0242010420e96c6ae4c2630575213f33bfc1e7795be6dd4a35ac69250c5a9f65ec62f6a3f5fe4ac66c8c1471afdeb3f0784e2645f0f606859761d4930c39fd8ba11ca4e0"; // k5.sig.aaa.1 - var result2 = ec2.verifyWithMessageHash(hashAAA256Hex, sigHex); - equal(result2, true, "ecdsa sign"); -}); - test("k6.sig.aaa.1 secp384r1 sha256", function() { // signature validation var pub = "04543526abdfc47394a3f2645b0d48651a9f3a4d46d8740be322915107f050250c730ca40b37e1dc85e082b4bb181b8847bd6d0fa278bae5eb1c05474c9a4e2beec28c970be49c1949f09e96979a277a514830e32a5b9de1ec68ab99f492dd300a"; @@ -195,6 +174,45 @@ equal(ec1.getShortNISTPCurveName(), null, "secp256k1 - null"); }); +test("readPKCS5PrvKeyHex k1", function() { + var ec1 = new KJUR.crypto.ECDSA(); + ec1.readPKCS5PrvKeyHex(ECK1PRVP5HEX); + equal(ec1.isPublic, false, "isPublic"); + equal(ec1.isPrivate, true, "isPrivate"); + equal(ec1.curveName, "secp256r1", "curveName"); + equal(ec1.pubKeyHex, ECK1PUBHEX, "pubKeyHex"); + equal(ec1.prvKeyHex, ECK1PRVRAWHEX, "prvKeyHex"); +}); + +test("readPKCS8PrvKeyHex k1", function() { + var ec1 = new KJUR.crypto.ECDSA(); + ec1.readPKCS8PrvKeyHex(ECK1PRVP8HEX); + equal(ec1.isPublic, false, "isPublic"); + equal(ec1.isPrivate, true, "isPrivate"); + equal(ec1.curveName, "secp256r1", "curveName"); + equal(ec1.pubKeyHex, ECK1PUBHEX, "pubKeyHex"); + equal(ec1.prvKeyHex, ECK1PRVRAWHEX, "prvKeyHex"); +}); + +test("readPKCS8PubKeyHex k1", function() { + var ec1 = new KJUR.crypto.ECDSA(); + ec1.readPKCS8PubKeyHex(ECK1PUBP8HEX); + equal(ec1.isPublic, true, "isPublic"); + equal(ec1.isPrivate, false, "isPrivate"); + equal(ec1.curveName, "secp256r1", "curveName"); + equal(ec1.pubKeyHex, ECK1PUBHEX, "pubKeyHex"); +}); + +test("readCertPubKeyHex k1", function() { + //equal(ASN1HEX.getVbyList(ECK1CERTHEX, 0, [0, 6]), "00", "00"); + var ec1 = new KJUR.crypto.ECDSA(); + ec1.readCertPubKeyHex(ECK1CERTHEX); + equal(ec1.isPublic, true, "isPublic"); + equal(ec1.isPrivate, false, "isPrivate"); + equal(ec1.curveName, "secp256r1", "curveName"); + equal(ec1.pubKeyHex, ECK1PUBHEX, "pubKeyHex"); +}); + }); @@ -215,8 +233,10 @@ crypto.js | crypto.js Signature class for ECDSA | ecdsa-modified.js | +ecdsa-modified unsupported curve | ecparam.js |

    + diff --git a/test/qunit-do-keyutil-dsa.html b/test/qunit-do-keyutil-dsa.html index a1692016..68e5b68d 100755 --- a/test/qunit-do-keyutil-dsa.html +++ b/test/qunit-do-keyutil-dsa.html @@ -134,6 +134,14 @@ "-----END DSA PRIVATE KEY-----\n"; var d1PrvP5EPass = "passwd"; +var D1PRVP5HEX = "308201bb020100028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b021473b3538660ceac98a3bf48e53f88b4e124657c21"; + +var D1PRVP8HEX = "3082014a0201003082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e0416021473b3538660ceac98a3bf48e53f88b4e124657c21"; // d1.prv.p8p.der + +var D1PUBP8HEX = "308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b"; // d1.pub.p8.der + +var D1CERTHEX = "308202c430820282a003020102020900fd8cc68e37232612300b0609608648016503040302301a310b3009060355040613025553310b3009060355040a0c024431301e170d3133313030323135303434345a170d3233303933303135303434345a301a310b3009060355040613025553310b3009060355040a0c024431308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523ba350304e301d0603551d0e04160414b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a301f0603551d23041830168014b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a300c0603551d13040530030101ff300b0609608648016503040302032f00302c02147ff6dde28ad40095342cdbf2e5e2621ed30db85d021422c71bc20564bd68beecf2f631cd0e3f3c649430"; // d1.self.cer.der + // ======= TEST =================================================================================== test("KEYUTIL.getKeyFromPublicPKCS8PEM d1(DSA 1024bit)", function() { @@ -180,6 +188,59 @@ equal(x.compareTo(key.x), 0, "x"); }); +test("KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(D1PRVP8HEX) d1.prv.p8p.der", function() { + var key = KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(D1PRVP8HEX); + equal(key.isPublic, false, "isPublic"); + equal(key.isPrivate, true, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(key.y, null, "Y"); + equal(x.compareTo(key.x), 0, "X"); +}); + +test("KEYUTIL.getKey(D1PRVP5HEX, null, pkcs5prv) d1.prv.p5p.der", function() { + var key = KEYUTIL.getKey(D1PRVP5HEX, null, "pkcs5prv"); + equal(key.isPublic, false, "isPublic"); + equal(key.isPrivate, true, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(y.compareTo(key.y), 0, "Y not null"); + equal(x.compareTo(key.x), 0, "X"); +}); + +test("KEYUTIL.getKey(D1PRVP8HEX, null, pkcs8prv) d1.prv.p8p.der", function() { + var key = KEYUTIL.getKey(D1PRVP8HEX, null, "pkcs8prv"); + equal(key.isPublic, false, "isPublic"); + equal(key.isPrivate, true, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(key.y, null, "Y null"); + equal(x.compareTo(key.x), 0, "X"); +}); + +test("KEYUTIL.getKey(D1PUBP8HEX, null, pkcs8pub) d1.pub.p8.der", function() { + var key = KEYUTIL.getKey(D1PUBP8HEX, null, "pkcs8pub"); + equal(key.isPublic, true, "isPublic"); + equal(key.isPrivate, false, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(y.compareTo(key.y), 0, "Y not null"); +}); + +test("KEYUTIL.getKey(D1CERTHEX, null, x509pub) d1.self.cer.der", function() { + var key = KEYUTIL.getKey(D1CERTHEX, null, "x509pub"); + equal(key.isPublic, true, "isPublic"); + equal(key.isPrivate, false, "isPrivate"); + equal(p.compareTo(key.p), 0, "P"); + equal(q.compareTo(key.q), 0, "Q"); + equal(g.compareTo(key.g), 0, "G"); + equal(y.compareTo(key.y), 0, "Y not null"); +}); + }); --> @@ -188,8 +249,12 @@
    test markup
    -QUnit for +TOP | +TEST INDEX | keyutil | +keyutil-rsa | +keyutil-dsa | +keyutil-ec | keyutil-eprv | keyutil-pub | diff --git a/test/qunit-do-keyutil-ec.html b/test/qunit-do-keyutil-ec.html new file mode 100755 index 00000000..5dfd9a69 --- /dev/null +++ b/test/qunit-do-keyutil-ec.html @@ -0,0 +1,135 @@ + + + +QUnit for KEYUTIL ECC plain private key reader 'keyutil.js' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    test markup
    +TOP | +TEST INDEX | +keyutil | +keyutil-rsa | +keyutil-dsa | +keyutil-ec | +keyutil-eprv | +keyutil-pub | + + + diff --git a/test/qunit-do-keyutil-eprv.html b/test/qunit-do-keyutil-eprv.html index 6cd54ce4..8f39c7bb 100755 --- a/test/qunit-do-keyutil-eprv.html +++ b/test/qunit-do-keyutil-eprv.html @@ -129,7 +129,6 @@ test("parsePrivateRawRSAKeyHexAtObj z1(RSA)", function() { var r = KEYUTIL.parsePlainPrivatePKCS8Hex(z1PrvP8pHex); KEYUTIL.parsePrivateRawRSAKeyHexAtObj(z1PrvP8pHex, r); - expect(8); equal(r.key.n, "00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd59", "n"); equal(r.key.e, "010001", "e"); equal(r.key.d, "78bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d", "d"); diff --git a/test/qunit-do-keyutil-rsa.html b/test/qunit-do-keyutil-rsa.html new file mode 100755 index 00000000..5ff32ee2 --- /dev/null +++ b/test/qunit-do-keyutil-rsa.html @@ -0,0 +1,198 @@ + + + +QUnit for KEYUTIL RSA plain private key reader 'keyutil.js' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    test markup
    +TOP | +TEST INDEX | +keyutil | +keyutil-rsa | +keyutil-dsa | +keyutil-ec | +keyutil-eprv | +keyutil-pub | + + + diff --git a/test/qunit-do-keyutil.html b/test/qunit-do-keyutil.html index 3ad4a9a4..035963c7 100755 --- a/test/qunit-do-keyutil.html +++ b/test/qunit-do-keyutil.html @@ -342,8 +342,12 @@
    test markup
    -QUnit for +TOP | +TEST INDEX | keyutil | +keyutil-rsa | +keyutil-dsa | +keyutil-ec | keyutil-eprv | keyutil-pub | diff --git a/test/qunit-do-rsapem.html b/test/qunit-do-rsapem.html index 7fec6a6e..1b9c0e72 100755 --- a/test/qunit-do-rsapem.html +++ b/test/qunit-do-rsapem.html @@ -2,7 +2,7 @@ "http://www.w3.org/TR/html4/loose.dtd"> -QUnit for RSAKey key-reading add-on 'rsa-pem.js' +QUnit for RSAKey key-reading add-on 'rsapem.js' @@ -42,21 +42,21 @@ var sk10dechex = '30820139020100024100b1e5aa7d6827b8c69037b269907bd8f4a7a1e6b798776e3be519fbda2966260dd56f6f3389d489a276a0a1e1b19e51328bc2d6a623f24be6b2e6718f3b292d5b02030100010240763582206ac15a4ab7320b5f921e797fb894205706fcf546df6970acfaad61c2db1fb6f9e335a1867c0f7c40a2ad39aa92b9312459bbf90d5eab831793c69321022100e584720c8f676623e94e7fb8616e667d66cd379559ffe36acd9068495e68adc5022100c66c72386fbdeded99c5963422d7380c19100757a4dcec581bd645d3d924409f0220101798337f3e7dafd8e4d319a763293673a5c1d6ebe7801775f0410f9bd9f50d02201bff2b329959a41b9549d2c2b273c97db37f9679a05267aa9aeae5d959570b23022043ea618b8f31af3aa762171cf2b5e9d563c5041a99a2217b6c692f807e18f81a'; -test("_rsapem_pemToBase64", function() { - var sResult = _rsapem_pemToBase64(sKey1PEM); +test("pemToBase64", function() { + var sResult = RSAKey.pemToBase64(sKey1PEM); equal(sResult, sKey1B64, "testing pem-base64 conversion."); }); -test("_rsapem_getPosArrayOfChildrenFromHex", function() { +test("getPosArrayOfChildrenFromHex", function() { var hPrivateKey = b64tohex(sKey1B64); - var a = _rsapem_getPosArrayOfChildrenFromHex(hPrivateKey); + var a = RSAKey.getPosArrayOfChildrenFromHex(hPrivateKey); equal(a.join("/"), "8/14/278/288/550/684/818/950/1082", "check child element position of sKey1B64"); }); -test("_rsapem_getHexValueArrayOfChildrenFromHex", function() { +test("getHexValueArrayOfChildrenFromHex", function() { var hPrivateKey = b64tohex(sKey1B64); - var a = _rsapem_getHexValueArrayOfChildrenFromHex(hPrivateKey); + var a = RSAKey.getHexValueArrayOfChildrenFromHex(hPrivateKey); equal(a.join("/"), "00/00d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a0021/010001/03dfeadd993a89bd86151a4a0cb3bf3b628c9c07d1f9be1727accc19ea19ecb6e98b7316d0d6b093d72455a5f46551aac5b4885f90afa7fca31c7a70c3e41b505af0fe00a32e28988ccf44f02dee005e40289d2be0604f978bbc2b86e96d7792c5207ad3fc0f40589000955c039c61655cea36e177123b8a747b30f9d93e74f1/00ee6d7fe55461600ffc58b9c873e7a61ced51d7fb9f015243527b04b3c0945b72e7aa9275d15b08fded25eaa6761f2aa66aefc767105d74496b2bfcd30a8beed7/00e0f56a0effce6406d6af8b325d936ffcca65e2be6cbb360c3140fd53c076248467ae198664fccbc76dcdf49e21109f9787cb5229573cd233a4aef1a54aff81c7/6933ad8c0dd84d5fa053b1ddcdae77b029d2c3ff0560bae073a34e26d6215fdc6a75ebdbca7d65914d333ebf263d883f17ce26e8c5e2c66da2b92cfc1d9a32cf/462da9698679ff9076970ae8aa729d64124c18a1695039fb31be618928287319ef324bfa3634fae97b22de261a909208f6af0231ad6a66f4ff72282675b021ef/40d5f2a22cee18496d8926815f1e07dbd11d5cd6160c9f524b97f4ef40516c022576a461deb70dbe963a04a26a15aa5d6b50e375c9dc64408c8b34ff18cadcd7", "check child element of sKey1B64"); }); @@ -89,13 +89,43 @@ equal(k.coeff.toString(16), "43ea618b8f31af3aa762171cf2b5e9d563c5041a99a2217b6c692f807e18f81a", "check (coeff) of Key1"); }); +test("RSAKey.readPKCS5PubKeyHex z1024.cer.pubkey.der", function() { + var k = new RSAKey(); + k.readPKCS5PubKeyHex("30818902818100d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a00210203010001"); + equal(k.n.toString(16), "d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a0021", "n"); + equal(k.e.toString(16), "10001", "e"); +}); + +test("RSAKey.readPKCS8PubKeyHex z1024.cer.pubkey.der", function() { + var k = new RSAKey(); + k.readPKCS8PubKeyHex("30819f300d06092a864886f70d010101050003818d0030818902818100d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a00210203010001"); + equal(k.n.toString(16), "d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a0021", "n"); + equal(k.e.toString(16), "10001", "e"); +}); + +test("RSAKey.readCertPubKeyHex z1024.cer.pubkey.der", function() { + var k = new RSAKey(); + k.readCertPubKeyHex("308201bd30820126020900f9e5f373734585ed300d06092a864886f70d01010505003023310b3009060355040613024a5031143012060355040a130b30302d544553542d525341301e170d3130303532383032303835315a170d3230303532353032303835315a3023310b3009060355040613024a5031143012060355040a130b30302d544553542d52534130819f300d06092a864886f70d010101050003818d0030818902818100d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a00210203010001300d06092a864886f70d010105050003818100119ea65c516adc0cdf6aa587982cb50118e56ae6006bc6665059cb9b47a683d76454127adda12a01186da24e9b0d00f3489c622e908417a1b86ff36ffccfcc2f284ff8ea0e4e611331e80055032aef5721a1527238513906d41ae8cfe508710ec9ae5051fa111761c5f448d1178e0adce2bebb78af4d28f7cf08eda6e758e57a"); + equal(k.n.toString(16), "d184617b5f8034655944839f785a63835555088a23d0b34e1a2e6bdf83c49ba2b1ecb398105eed1a21d513ea76f9ad3879843db27e91765885ba33ccf45b1461c227205f08bcd07d5a2cf7fa9443cf2ef376f448503630699059002546d2f2eba124478ac34704e3d83cd1e041178042a922fa3c541b3fdfeb072c5dc44a0021", "n"); + equal(k.e.toString(16), "10001", "e"); +}); + }); --> + -
    -
    test markup
    +

    QUnit for Cryptographic Provider Class 'crypto.js'

    +

    +

    +
      +

      +TOP | +TEST INDEX | +crypto.js | +

      + diff --git a/test/qunit-do-x509-ext.html b/test/qunit-do-x509-ext.html index f7af5eaf..9b2a9b58 100755 --- a/test/qunit-do-x509-ext.html +++ b/test/qunit-do-x509-ext.html @@ -92,10 +92,10 @@ "HRMEBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQDfAcS/WKBrP6JBgksQVpp4jdq4\n" + "C53Yu4F5NkaMgthAHgIhANGRdWAP1QdW9l6tiglQwdqJs4T0e8+NYv+RcAb3VYwn\n" + "-----END CERTIFICATE-----\n"; -var k1CertHex = X509.pemToHex(k1CertPEM); +var k1CertHex = ASN1HEX.pemToHex(k1CertPEM); test("getV3ExtInfoListOfCertHex test1", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); var a = X509.getV3ExtInfoListOfCertHex(hCert); equal(a.length, 9, "num ext=9"); equal(a[0].posTLV, 1484, "AKID TLV index"); @@ -124,7 +124,7 @@ }); test("getPosOfTLV_V3ExtValue test1", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); equal(X509.getPosOfTLV_V3ExtValue(hCert, "keyUsage"), 1714, "by keyUsage"); equal(X509.getPosOfTLV_V3ExtValue(hCert, "2.5.29.15"), 1714, "by 2.5.29.15(=keyUsage)"); equal(X509.getPosOfTLV_V3ExtValue(hCert, "policyConstraints"), -1, @@ -134,7 +134,7 @@ }); test("getHexOfV_V3ExtValue test1", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); equal(X509.getHexOfV_V3ExtValue(hCert, "keyUsage"), "05a0", "by keyUsage"); equal(X509.getHexOfV_V3ExtValue(hCert, "2.5.29.15"), "05a0", "by 2.5.29.15(=keyUsage)"); equal(X509.getHexOfV_V3ExtValue(hCert, "policyConstraints"), null, @@ -144,7 +144,7 @@ }); test("getHexOfTLV_V3ExtValue test1", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); equal(X509.getHexOfTLV_V3ExtValue(hCert, "keyUsage"), "030205a0", "by keyUsage"); equal(X509.getHexOfTLV_V3ExtValue(hCert, "2.5.29.15"), "030205a0", "by 2.5.29.15(=keyUsage)"); equal(X509.getHexOfTLV_V3ExtValue(hCert, "policyConstraints"), null, @@ -154,17 +154,17 @@ }); test("getExtKeyUsageBin", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); equal(X509.getExtKeyUsageBin(hCert), "101", "101"); }); test("getExtKeyUsageString", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); equal(X509.getExtKeyUsageString(hCert), "digitalSignature,keyEncipherment", "digitalSignature,keyEncipherment"); }); test("getExtAIAInfo", function() { - var hCert = X509.pemToHex(certGithubPEM); + var hCert = ASN1HEX.pemToHex(certGithubPEM); var info = X509.getExtAIAInfo(hCert); equal(info.ocsp.length, 1, "number item of ocsp = 1"); equal(info.ocsp[0], "http://ocsp.digicert.com", "ocsp=http://ocsp.digicert.com"); diff --git a/test/qunit-do-x509.html b/test/qunit-do-x509.html index 736e22e4..67fea7b1 100755 --- a/test/qunit-do-x509.html +++ b/test/qunit-do-x509.html @@ -110,7 +110,7 @@ "HRMEBTADAQH/MAoGCCqGSM49BAMCA0kAMEYCIQDfAcS/WKBrP6JBgksQVpp4jdq4\n" + "C53Yu4F5NkaMgthAHgIhANGRdWAP1QdW9l6tiglQwdqJs4T0e8+NYv+RcAb3VYwn\n" + "-----END CERTIFICATE-----\n"; -var k1CertHex = X509.pemToHex(k1CertPEM); +var k1CertHex = ASN1HEX.pemToHex(k1CertPEM); test("pemToBase64", function() { var sResult = X509.pemToBase64(sCer1PEM); @@ -118,7 +118,7 @@ }); test("pemToHex", function() { - var sResult = X509.pemToHex(sCer1PEM); + var sResult = ASN1HEX.pemToHex(sCer1PEM); equal(sResult, hCer1, "testing pem-hex conversion."); }); @@ -151,7 +151,7 @@ test("getPublicKeyHexArrayFromCertPEM sCer2PEM", function() { expect(8); equal(X509.pemToBase64(sCer2PEM), sCer2B64, "check pem to base64."); - equal(X509.pemToHex(sCer2PEM), hCer2, "check pem to hex."); + equal(ASN1HEX.pemToHex(sCer2PEM), hCer2, "check pem to hex."); var pTbsCert = X509.getHexTbsCertificateFromCert(hCer2); equal(pTbsCert, 8, "check tbsCert position."); equal(X509.getSubjectPublicKeyInfoPosFromCertHex(hCer2), 280, diff --git a/tool_asn1dumper.html b/tool_asn1dumper.html index eea252a5..c4eaf860 100755 --- a/tool_asn1dumper.html +++ b/tool_asn1dumper.html @@ -54,7 +54,7 @@ try { var s = f1.s_in.value; if (s.indexOf("-----BEGIN") != -1) { - s = X509.pemToHex(s); + s = ASN1HEX.pemToHex(s); } else { s = s.replace(/^\s+/, ''); s = s.replace(/\s+$/, ''); diff --git a/tool_httpscfg.html b/tool_httpscfg.html index bbe36cd9..85c0a562 100755 --- a/tool_httpscfg.html +++ b/tool_httpscfg.html @@ -16,6 +16,7 @@ * 各種ガイドラインでの暗号スイートの定義 ********************************************/ var OPENSSL_CIPHERSUITE = { + "kjur201511": "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DES-CBC3-SHA", "cryptrec1": "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256", "cryptrec2": "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-CAMELLIA128-SHA:DHE-RSA-AES128-SHA:AES128-GCM-SHA256:AES128-SHA256:CAMELLIA128-SHA:AES128-SHA:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-CAMELLIA256-SHA:DHE-RSA-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:CAMELLIA256-SHA:AES256-SHA:ECDH-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES256-GCM-SHA384", "cryptrec3": "DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-CAMELLIA128-SHA:DHE-RSA-AES128-SHA:AES128-GCM-SHA256:AES128-SHA256:CAMELLIA128-SHA:AES128-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-CAMELLIA256-SHA:DHE-RSA-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:CAMELLIA256-SHA:AES256-SHA:RC4-SHA:EDH-RSA-DES-CBC3-SHA:DES-CBC3-SHA", @@ -166,7 +167,6 @@ var serverapp = f1.serverapp.value; var cert1 = f1.cert1.value; var cert2 = f1.cert2.value; - var cert3 = f1.cert3.value; //alert(1); var cfg = CFG_TEMPLATE[f1.serverapp.value]; @@ -175,14 +175,15 @@ cfg = _updateOrder(cfg, guidename, serverapp); cfg = _updateCompression(cfg, guidename, serverapp); - cfg = _updatePinning(cfg, [cert1, cert2, cert3], serverapp); + cfg = _updatePinning(cfg, [cert1, cert2], serverapp); f1.resultcfg.value = cfg; } function _updateCompression(cfg, guidename, serverapp) { // 注:nginx は新しいもので対応、設定は不要 - if (guidename.indexOf("cryptrec") != -1 || + if (guidename.indexOf("kjur") != -1 || + guidename.indexOf("cryptrec") != -1 || guidename.indexOf("mozilla") != -1 || guidename.indexOf("bullet") != -1) { if (serverapp.indexOf("apache") != -1) { @@ -198,10 +199,12 @@ function _updateOrder(cfg, guidename, serverapp) { var s = "# -- cipherorder not specified for this guide --"; + if (serverapp.indexOf("kjur") != -1) s = "SSLHonorCipherOrder On"; if (serverapp.indexOf("apache") != -1) s = "SSLHonorCipherOrder On"; if (serverapp == "nginx") s = "ssl_prefer_server_ciphers on;"; if (serverapp == "lighttpd") s = "ssl.honor-cipher-order = \"enable\""; - if (guidename.indexOf("cryptrec") == -1 && + if (guidename.indexOf("kjur") == -1 && + guidename.indexOf("cryptrec") == -1 && guidename.indexOf("mozilla") == -1 && guidename.indexOf("bullet") == -1) { cfg = cfg.replace("%%%CIPHERORDER%%%", "#" + s); @@ -257,10 +260,15 @@ } function _getPublicKeyInfoHexOfCertPEM(sCertPEM) { - var hCert = X509.pemToHex(sCertPEM); + if (sCertPEM.indexOf("-----BEGIN PUBLIC KEY") != -1) { + var hPubkey = ASN1HEX.pemToHex(sCertPEM); + return hPubkey; + } else { + var hCert = ASN1HEX.pemToHex(sCertPEM); var pos = X509.getPublicKeyInfoPosOfCertHEX(hCert); var publicKeyInfoHex = ASN1HEX.getHexOfTLV_AtObj(hCert, pos); return publicKeyInfoHex; + } }; var LIGHTTPD_NOT_SSL2 = "ssl.use-sslv2 = \"disable\""; @@ -270,6 +278,7 @@ function _getProtocolValue(guideName, serverType) { if (serverType == "apache24" || serverType == "apache22") { + if (guideName == "kjur201511") return "all -SSLv2 -SSLv3"; if (guideName == "cryptrec1") return "TLSv1.2"; if (guideName == "cryptrec2") return "all -SSLv2 -SSLv3"; if (guideName == "cryptrec3") return "all -SSLv2"; @@ -280,6 +289,7 @@ return "all"; // デフォルト } if (serverType == "nginx") { + if (guideName == "kjur201511") return "TLSv1.2 TLSv1.1 TLSv1"; if (guideName == "cryptrec1") return "TLSv1.2"; if (guideName == "cryptrec2") return "TLSv1.2 TLSv1.1 TLSv1"; if (guideName == "cryptrec3") return "TLSv1.2 TLSv1.1 TLSv1 SSLv3"; @@ -290,6 +300,7 @@ return "TLSv1.2 TLSv1.1 TLSv1 SSLv3"; // デフォルト } if (serverType == "lighttpd") { + if (guideName == "kjur201511") return LIGHTTPD_NOT_SSL; if (guideName == "cryptrec1") return LIGHTTPD_TLS12; if (guideName == "cryptrec2") return LIGHTTPD_NOT_SSL; if (guideName == "cryptrec3") return LIGHTTPD_NOT_SSL2; @@ -309,7 +320,7 @@
      -

      HTTPS設定ファイル生成ツール0.5(ベータ版)

      +

      HTTPS設定ファイル生成ツール0.6(ベータ版)

      各種ガイドラインに応じたApache、nginx、lighttpdなど主要なサーバーのHTTPS設定を自動生成します

      TOP | @@ -328,6 +339,7 @@

      簡易設定情報

      ガイドラインの種類:

      -a) SSLサーバー証明書PEM
      +a) Pinにマッチさせる証明書のPEM(SSLサーバー証明書や中間CA証明書等)

      -b) 中間CA証明書1(SSLサーバーに近い順)
      +b) Pinにマッチさせないバックアップの証明書もしくはPKCS#8公開鍵のPEM

      -c) 中間CA証明書2(SSLサーバーに近い順、ルートに近い方)
      -

      @@ -477,7 +487,8 @@

      補足説明

      ニュース

        -
      • 2015.06.21 - 0.5ベータ版 Bulletproof SSL and TLSへの対応
      • +
      • 2015.06.21 - 0.5ベータ版 Bulletproof SSL and TLSへの対応。SSL/TLSガイドで記載された +Certificate Pinningの記載誤り(Backup Pin)への対応
      • 2015.05.16 - 0.4ベータ版 lighttpdに対応
      • 2015.05.15 - 0.3ベータ版 nginxのMozillaのガイドのprotocol値の誤りの修正
      • 2015.05.14 - 0.2ベータ版 nginx設定、TLS圧縮オフに対応  diff --git a/x509-1.1.js b/x509-1.1.js index 5c07e605..34a80cbc 100644 --- a/x509-1.1.js +++ b/x509-1.1.js @@ -1,9 +1,9 @@ -/*! x509-1.1.10.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license +/*! x509-1.1.11.js (c) 2012-2017 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * x509.js - X509 class to read subject public key from certificate. * - * Copyright (c) 2010-2016 Kenji Urushima (kenji.urushima@gmail.com) + * Copyright (c) 2010-2017 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license @@ -16,7 +16,7 @@ * @fileOverview * @name x509-1.1.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version x509 1.1.10 (2016-Nov-19) + * @version x509 1.1.11 (2017-Jan-21) * @since jsrsasign 1.x.x * @license MIT License */ @@ -81,7 +81,7 @@ *
      • reading PEM certificate - {@link X509#readCertPEM}
      • *
      • get all certificate information - {@link X509#getInfo}
      • *
      • get Base64 from PEM certificate - {@link X509.pemToBase64}
      • - *
      • get hexadecimal string from PEM certificate - {@link X509.pemToHex}
      • + *
      • get hexadecimal string from PEM certificate - {@link X509.pemToHex} (DEPRECATED)
      • *
      * * @@ -241,7 +241,7 @@ function X509() { * x.readCertPEM(sCertPEM); // read certificate */ this.readCertPEM = function(sCertPEM) { - var hCert = X509.pemToHex(sCertPEM); + var hCert = ASN1HEX.pemToHex(sCertPEM); var a = X509.getPublicKeyHexArrayFromCertHex(hCert); var rsa = new RSAKey(); rsa.setPublic(a[0], a[1]); @@ -252,7 +252,7 @@ function X509() { }; this.readCertPEMWithoutRSAInit = function(sCertPEM) { - var hCert = X509.pemToHex(sCertPEM); + var hCert = ASN1HEX.pemToHex(sCertPEM); var a = X509.getPublicKeyHexArrayFromCertHex(hCert); if (typeof this.subjectPublicKeyRSA.setPublic === "function") { this.subjectPublicKeyRSA.setPublic(a[0], a[1]); @@ -401,13 +401,14 @@ X509.pemToBase64 = function(sCertPEM) { * @function * @param {String} sCertPEM PEM formatted RSA/ECDSA/DSA X.509 certificate * @return {String} hexadecimal string of PEM certificate + * @deprecated from x509 1.1.11 jsrsasign 7.0.1. please move to {@link ASN1HEX.pemToHex} + * @description + * CAUTION: now X509.pemToHex deprecated and is planed to remove in jsrsasign 8.0.0. * @example * hex = X509.pemToHex(certPEM); */ X509.pemToHex = function(sCertPEM) { - var b64Cert = X509.pemToBase64(sCertPEM); - var hCert = b64tohex(b64Cert); - return hCert; + return ASN1HEX.pemToHex(sCertPEM); }; /** @@ -480,7 +481,7 @@ X509.getHexTbsCertificateFromCert = function(hCert) { }; X509.getPublicKeyHexArrayFromCertPEM = function(sCertPEM) { - var hCert = X509.pemToHex(sCertPEM); + var hCert = ASN1HEX.pemToHex(sCertPEM); var a = X509.getPublicKeyHexArrayFromCertHex(hCert); return a; }; @@ -582,7 +583,41 @@ X509.hex2attrTypeValue = function(hex, idx) { }; /** - * get RSAKey/ECDSA public key object from PEM certificate string + * get RSA/DSA/ECDSA public key object from X.509 certificate hexadecimal string
      + * @name getPublicKeyFromCertHex + * @memberOf X509 + * @function + * @param {String} h hexadecimal string of X.509 certificate for RSA/ECDSA/DSA public key + * @return returns RSAKey/KJUR.crypto.{ECDSA,DSA} object of public key + * @since jsrasign 7.1.0 x509 1.1.11 + */ +X509.getPublicKeyFromCertHex = function(h) { + var key, hKEYOID, hItem1; + var nthPKI = 6; // for publicKeyInfo index is 6 for v3 or 5 for v1 + var _ASN1HEX = ASN1HEX; + var _getVbyList = _ASN1HEX.getVbyList; + + hItem1 = _ASN1HEX.getDecendantHexTLVByNthList(h, 0, [0, 0]); + if (hItem1 !== "a003020102") { // tbsCert first item is version(=v3) + nthPKI = 5; + } + + hKEYOID = _getVbyList(h, 0, [0, nthPKI, 0, 0], "06"); + if (hKEYOID === "2a864886f70d010101") { // RSA + key = new RSAKey(); + } else if (hKEYOID === "2a8648ce380401") { // DSA + key = new KJUR.crypto.DSA(); + } else if (hKEYOID === "2a8648ce3d0201") { // CC + key = new KJUR.crypto.ECDSA(); + } else { + throw "unsupported public key in X.509 cert"; + } + key.readCertPubKeyHex(h, nthPKI); + return key; +}; + +/** + * get RSA/DSA/ECDSA public key object from PEM certificate string * @name getPublicKeyFromCertPEM * @memberOf X509 * @function @@ -593,33 +628,9 @@ X509.hex2attrTypeValue = function(hex, idx) { * NOTE: DSA is also supported since x509 1.1.2. */ X509.getPublicKeyFromCertPEM = function(sCertPEM) { - var info = X509.getPublicKeyInfoPropOfCertPEM(sCertPEM); - - if (info.algoid == "2a864886f70d010101") { // RSA - var aRSA = KEYUTIL.parsePublicRawRSAKeyHex(info.keyhex); - var key = new RSAKey(); - key.setPublic(aRSA.n, aRSA.e); - return key; - } else if (info.algoid == "2a8648ce3d0201") { // ECC - var curveName = KJUR.crypto.OID.oidhex2name[info.algparam]; - var key = new KJUR.crypto.ECDSA({'curve': curveName, 'info': info.keyhex}); - key.setPublicKeyHex(info.keyhex); - return key; - } else if (info.algoid == "2a8648ce380401") { // DSA 1.2.840.10040.4.1 - var p = ASN1HEX.getVbyList(info.algparam, 0, [0], "02"); - var q = ASN1HEX.getVbyList(info.algparam, 0, [1], "02"); - var g = ASN1HEX.getVbyList(info.algparam, 0, [2], "02"); - var y = ASN1HEX.getHexOfV_AtObj(info.keyhex, 0); - y = y.substr(2); - var key = new KJUR.crypto.DSA(); - key.setPublic(new BigInteger(p, 16), - new BigInteger(q, 16), - new BigInteger(g, 16), - new BigInteger(y, 16)); - return key; - } else { - throw "unsupported key"; - } + var _ASN1HEX = ASN1HEX; + var h = _ASN1HEX.pemToHex(sCertPEM); + return X509.getPublicKeyFromCertHex(h); }; /** @@ -642,7 +653,7 @@ X509.getPublicKeyFromCertPEM = function(sCertPEM) { X509.getPublicKeyInfoPropOfCertPEM = function(sCertPEM) { var result = {}; result.algparam = null; - var hCert = X509.pemToHex(sCertPEM); + var hCert = ASN1HEX.pemToHex(sCertPEM); // 1. Certificate ASN.1 var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0); @@ -741,7 +752,7 @@ X509.getPublicKeyInfoPosOfCertHEX = function(hCert) { * This is a position of a content of ENCAPSULATED OCTET STRING. * * @example - * hCert = X509.pemToHex(certGithubPEM); + * hCert = ASN1HEX.pemToHex(certGithubPEM); * a = X509.getV3ExtInfoListOfCertHex(hCert); * // Then a will be an array of like following: * [{posTLV: 1952, oid: "2.5.29.35", critical: false, posV: 1968},