summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Cresswell <robert.cresswell@outlook.com>2016-04-21 16:14:47 +0100
committerRob Cresswell <robert.cresswell@outlook.com>2016-04-21 16:19:05 +0100
commit5a62fc037e1a0a2264d4470789229fa01dbe4483 (patch)
treecc5f198be7097fb1ddf55e26f2cd4ca45362aff2
parent633011365a69602aada5f419fc40fd50279e8884 (diff)
downloadxstatic-jsencrypt-5a62fc037e1a0a2264d4470789229fa01dbe4483.tar.gz
Update JSEncrypt to v2.3.0
Change-Id: I2000c1aa6d85e2dace544e79727dd4e504fa30cd
-rw-r--r--xstatic/pkg/jsencrypt/__init__.py4
-rw-r--r--xstatic/pkg/jsencrypt/data/jsencrypt.js533
2 files changed, 293 insertions, 244 deletions
diff --git a/xstatic/pkg/jsencrypt/__init__.py b/xstatic/pkg/jsencrypt/__init__.py
index 5ccbf67..2594006 100644
--- a/xstatic/pkg/jsencrypt/__init__.py
+++ b/xstatic/pkg/jsencrypt/__init__.py
@@ -11,9 +11,9 @@ NAME = __name__.split('.')[-1] # package name (e.g. 'foo' or 'foo_bar')
# please use a all-lowercase valid python
# package name
-VERSION = '2.0.0' # version of the packaged files, please use the upstream
+VERSION = '2.3.0' # version of the packaged files, please use the upstream
# version number
-BUILD = '2' # our package build number, so we can release new builds
+BUILD = '0' # our package build number, so we can release new builds
# with fixes for xstatic stuff.
PACKAGE_VERSION = VERSION + '.' + BUILD # version used for PyPi
diff --git a/xstatic/pkg/jsencrypt/data/jsencrypt.js b/xstatic/pkg/jsencrypt/data/jsencrypt.js
index 6499568..21e6dc1 100644
--- a/xstatic/pkg/jsencrypt/data/jsencrypt.js
+++ b/xstatic/pkg/jsencrypt/data/jsencrypt.js
@@ -1,6 +1,7 @@
+/*! JSEncrypt v2.3.0 | https://npmcdn.com/jsencrypt@2.3.0/LICENSE.txt */
var JSEncryptExports = {};
(function(exports) {
-// Copyright (c) 2005 Tom Wu
+ // Copyright (c) 2005 Tom Wu
// All Rights Reserved.
// See "LICENSE" for details.
@@ -120,7 +121,7 @@ function bnpFromInt(x) {
this.t = 1;
this.s = (x<0)?-1:0;
if(x > 0) this[0] = x;
- else if(x < -1) this[0] = x+DV;
+ else if(x < -1) this[0] = x+this.DV;
else this.t = 0;
}
@@ -559,6 +560,7 @@ BigInteger.prototype.modPowInt = bnModPowInt;
// "constants"
BigInteger.ZERO = nbv(0);
BigInteger.ONE = nbv(1);
+
// Copyright (c) 2005-2009 Tom Wu
// All Rights Reserved.
// See "LICENSE" for details.
@@ -1215,6 +1217,7 @@ BigInteger.prototype.square = bnSquare;
// int hashCode()
// long longValue()
// static BigInteger valueOf(long val)
+
// prng4.js - uses Arcfour as a PRNG
function Arcfour() {
@@ -1260,6 +1263,7 @@ function prng_newstate() {
// Pool size must be a multiple of 4 and greater than 32.
// An array of bytes the size of the pool will be passed to init()
var rng_psize = 256;
+
// Random number generator - requires a PRNG backend, e.g. prng4.js
var rng_state;
var rng_pool;
@@ -1276,28 +1280,32 @@ if(rng_pool == null) {
window.crypto.getRandomValues(z);
for (t = 0; t < z.length; ++t)
rng_pool[rng_pptr++] = z[t] & 255;
- }
-
+ }
+
// Use mouse events for entropy, if we do not have enough entropy by the time
// we need it, entropy will be generated by Math.random.
var onMouseMoveListener = function(ev) {
this.count = this.count || 0;
if (this.count >= 256 || rng_pptr >= rng_psize) {
if (window.removeEventListener)
- window.removeEventListener("mousemove", onMouseMoveListener);
+ window.removeEventListener("mousemove", onMouseMoveListener, false);
else if (window.detachEvent)
window.detachEvent("onmousemove", onMouseMoveListener);
return;
}
- this.count += 1;
- var mouseCoordinates = ev.x + ev.y;
- rng_pool[rng_pptr++] = mouseCoordinates & 255;
+ try {
+ var mouseCoordinates = ev.x + ev.y;
+ rng_pool[rng_pptr++] = mouseCoordinates & 255;
+ this.count += 1;
+ } catch (e) {
+ // Sometimes Firefox will deny permission to access event properties for some reason. Ignore.
+ }
};
if (window.addEventListener)
- window.addEventListener("mousemove", onMouseMoveListener);
+ window.addEventListener("mousemove", onMouseMoveListener, false);
else if (window.attachEvent)
window.attachEvent("onmousemove", onMouseMoveListener);
-
+
}
function rng_get_byte() {
@@ -1325,6 +1333,7 @@ function rng_get_bytes(ba) {
function SecureRandom() {}
SecureRandom.prototype.nextBytes = rng_get_bytes;
+
// Depends on jsbn.js and rng.js
// Version 1.1: support utf-8 encoding in pkcs1pad2
@@ -1437,6 +1446,7 @@ RSAKey.prototype.doPublic = RSADoPublic;
RSAKey.prototype.setPublic = RSASetPublic;
RSAKey.prototype.encrypt = RSAEncrypt;
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
+
// Depends on rsa.js and jsbn2.js
// Version 1.1: support utf-8 decoding in pkcs1unpad2
@@ -1569,6 +1579,7 @@ RSAKey.prototype.setPrivateEx = RSASetPrivateEx;
RSAKey.prototype.generate = RSAGenerate;
RSAKey.prototype.decrypt = RSADecrypt;
//RSAKey.prototype.b64_decrypt = RSAB64Decrypt;
+
// Copyright (c) 2011 Kevin M Burns Jr.
// All Rights Reserved.
// See "LICENSE" for details.
@@ -1720,7 +1731,8 @@ var bnpFromNumberAsync = function (a,b,c,callback) {
};
BigInteger.prototype.fromNumberAsync = bnpFromNumberAsync;
-})();var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+})();
+var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var b64pad="=";
function hex2b64(h) {
@@ -1791,6 +1803,7 @@ function b64toBA(s) {
}
return a;
}
+
/*! asn1-1.0.2.js (c) 2013 Kenji Urushima | kjur.github.com/jsrsasign/license
*/
@@ -3136,7 +3149,8 @@ KJUR.asn1.DERTaggedObject = function(params) {
}
}
};
-JSX.extend(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);// Hex JavaScript decoder
+JSX.extend(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);
+// Hex JavaScript decoder
// Copyright (c) 2008-2013 Lapo Luchini <lapo@lapo.it>
// Permission to use, copy, modify, and/or distribute this software for any
@@ -3200,7 +3214,8 @@ Hex.decode = function(a) {
// export globals
window.Hex = Hex;
-})();// Base64 JavaScript decoder
+})();
+// Base64 JavaScript decoder
// Copyright (c) 2008-2013 Lapo Luchini <lapo@lapo.it>
// Permission to use, copy, modify, and/or distribute this software for any
@@ -3285,7 +3300,8 @@ Base64.unarmor = function (a) {
// export globals
window.Base64 = Base64;
-})();// ASN.1 JavaScript decoder
+})();
+// ASN.1 JavaScript decoder
// Copyright (c) 2008-2013 Lapo Luchini <lapo@lapo.it>
// Permission to use, copy, modify, and/or distribute this software for any
@@ -3819,29 +3835,33 @@ ASN1.test = function () {
// export globals
window.ASN1 = ASN1;
-})();/**
+})();
+/**
* Retrieve the hexadecimal value (as a string) of the current ASN.1 element
* @returns {string}
* @public
*/
-ASN1.prototype.getHexStringValue = function(){
- var hexString = this.toHexString();
- var offset = this.header * 2;
- var length = this.length * 2;
- return hexString.substr(offset,length);
+ASN1.prototype.getHexStringValue = function () {
+ var hexString = this.toHexString();
+ var offset = this.header * 2;
+ var length = this.length * 2;
+ return hexString.substr(offset, length);
};
/**
* Method to parse a pem encoded string containing both a public or private key.
* The method will translate the pem encoded string in a der encoded string and
* will parse private key and public key parameters. This method accepts public key
- * in the rsaencryption pkcs #1 format (oid: 1.2.840.113549.1.1.1).
- * @todo Check how many rsa formats use the same format of pkcs #1. The format is defined as:
+ * in the rsaencryption pkcs #1 format (oid: 1.2.840.113549.1.1.1).
+ *
+ * @todo Check how many rsa formats use the same format of pkcs #1.
+ *
+ * The format is defined as:
* PublicKeyInfo ::= SEQUENCE {
* algorithm AlgorithmIdentifier,
* PublicKey BIT STRING
* }
- * Where AlgorithmIdentifier is:
+ * Where AlgorithmIdentifier is:
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER, the OID of the enc algorithm
* parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)
@@ -3851,67 +3871,76 @@ ASN1.prototype.getHexStringValue = function(){
* modulus INTEGER, -- n
* publicExponent INTEGER -- e
* }
- * it's possible to examine the structure of the keys obtained from openssl using
+ * it's possible to examine the structure of the keys obtained from openssl using
* an asn.1 dumper as the one used here to parse the components: http://lapo.it/asn1js/
* @argument {string} pem the pem encoded string, can include the BEGIN/END header/footer
* @private
*/
-RSAKey.prototype.parseKey = function(pem) {
- try{
- var reHex = /^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/;
- var der = reHex.test(pem) ? Hex.decode(pem) : Base64.unarmor(pem);
- var asn1 = ASN1.decode(der);
- if (asn1.sub.length === 9){
- // the data is a Private key
- //in order
- //Algorithm version, n, e, d, p, q, dmp1, dmq1, coeff
- //Alg version, modulus, public exponent, private exponent, prime 1, prime 2, exponent 1, exponent 2, coefficient
- var modulus = asn1.sub[1].getHexStringValue(); //bigint
- this.n = parseBigInt(modulus, 16);
-
- var public_exponent = asn1.sub[2].getHexStringValue(); //int
- this.e = parseInt(public_exponent, 16);
-
- var private_exponent = asn1.sub[3].getHexStringValue(); //bigint
- this.d = parseBigInt(private_exponent, 16);
-
- var prime1 = asn1.sub[4].getHexStringValue(); //bigint
- this.p = parseBigInt(prime1, 16);
-
- var prime2 = asn1.sub[5].getHexStringValue(); //bigint
- this.q = parseBigInt(prime2, 16);
-
- var exponent1 = asn1.sub[6].getHexStringValue(); //bigint
- this.dmp1 = parseBigInt(exponent1, 16);
-
- var exponent2 = asn1.sub[7].getHexStringValue(); //bigint
- this.dmq1 = parseBigInt(exponent2, 16);
-
- var coefficient = asn1.sub[8].getHexStringValue(); //bigint
- this.coeff = parseBigInt(coefficient, 16);
-
- }else if (asn1.sub.length === 2){
- //Public key
- //The data PROBABLY is a public key
- var bit_string = asn1.sub[1];
- var sequence = bit_string.sub[0];
-
- var modulus = sequence.sub[0].getHexStringValue();
- this.n = parseBigInt(modulus, 16);
- var public_exponent = sequence.sub[1].getHexStringValue();
- this.e = parseInt(public_exponent, 16);
-
- }else{
- return false;
- }
- return true;
- }catch(ex){
- return false;
+RSAKey.prototype.parseKey = function (pem) {
+ try {
+ var modulus = 0;
+ var public_exponent = 0;
+ var reHex = /^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/;
+ var der = reHex.test(pem) ? Hex.decode(pem) : Base64.unarmor(pem);
+ var asn1 = ASN1.decode(der);
+
+ //Fixes a bug with OpenSSL 1.0+ private keys
+ if(asn1.sub.length === 3){
+ asn1 = asn1.sub[2].sub[0];
}
+ if (asn1.sub.length === 9) {
+
+ // Parse the private key.
+ modulus = asn1.sub[1].getHexStringValue(); //bigint
+ this.n = parseBigInt(modulus, 16);
+
+ public_exponent = asn1.sub[2].getHexStringValue(); //int
+ this.e = parseInt(public_exponent, 16);
+
+ var private_exponent = asn1.sub[3].getHexStringValue(); //bigint
+ this.d = parseBigInt(private_exponent, 16);
+
+ var prime1 = asn1.sub[4].getHexStringValue(); //bigint
+ this.p = parseBigInt(prime1, 16);
+
+ var prime2 = asn1.sub[5].getHexStringValue(); //bigint
+ this.q = parseBigInt(prime2, 16);
+
+ var exponent1 = asn1.sub[6].getHexStringValue(); //bigint
+ this.dmp1 = parseBigInt(exponent1, 16);
+
+ var exponent2 = asn1.sub[7].getHexStringValue(); //bigint
+ this.dmq1 = parseBigInt(exponent2, 16);
+
+ var coefficient = asn1.sub[8].getHexStringValue(); //bigint
+ this.coeff = parseBigInt(coefficient, 16);
+
+ }
+ else if (asn1.sub.length === 2) {
+
+ // Parse the public key.
+ var bit_string = asn1.sub[1];
+ var sequence = bit_string.sub[0];
+
+ modulus = sequence.sub[0].getHexStringValue();
+ this.n = parseBigInt(modulus, 16);
+ public_exponent = sequence.sub[1].getHexStringValue();
+ this.e = parseInt(public_exponent, 16);
+
+ }
+ else {
+ return false;
+ }
+ return true;
+ }
+ catch (ex) {
+ return false;
+ }
};
/**
* Translate rsa parameters in a hex encoded string representing the rsa key.
+ *
* The translation follow the ASN.1 notation :
* RSAPrivateKey ::= SEQUENCE {
* version Version,
@@ -3927,24 +3956,22 @@ RSAKey.prototype.parseKey = function(pem) {
* @returns {string} DER Encoded String representing the rsa private key
* @private
*/
-RSAKey.prototype.getPrivateBaseKey = function() {
- //Algorithm version, n, e, d, p, q, dmp1, dmq1, coeff
- //Alg version, modulus, public exponent, private exponent, prime 1, prime 2, exponent 1, exponent 2, coefficient
- var options = {
- 'array' : [
- new KJUR.asn1.DERInteger({'int' : 0}),
- new KJUR.asn1.DERInteger({'bigint' : this.n}),
- new KJUR.asn1.DERInteger({'int' : this.e}),
- new KJUR.asn1.DERInteger({'bigint' : this.d}),
- new KJUR.asn1.DERInteger({'bigint' : this.p}),
- new KJUR.asn1.DERInteger({'bigint' : this.q}),
- new KJUR.asn1.DERInteger({'bigint' : this.dmp1}),
- new KJUR.asn1.DERInteger({'bigint' : this.dmq1}),
- new KJUR.asn1.DERInteger({'bigint' : this.coeff})
- ]
- };
- var seq = new KJUR.asn1.DERSequence(options);
- return seq.getEncodedHex();
+RSAKey.prototype.getPrivateBaseKey = function () {
+ var options = {
+ 'array': [
+ new KJUR.asn1.DERInteger({'int': 0}),
+ new KJUR.asn1.DERInteger({'bigint': this.n}),
+ new KJUR.asn1.DERInteger({'int': this.e}),
+ new KJUR.asn1.DERInteger({'bigint': this.d}),
+ new KJUR.asn1.DERInteger({'bigint': this.p}),
+ new KJUR.asn1.DERInteger({'bigint': this.q}),
+ new KJUR.asn1.DERInteger({'bigint': this.dmp1}),
+ new KJUR.asn1.DERInteger({'bigint': this.dmq1}),
+ new KJUR.asn1.DERInteger({'bigint': this.coeff})
+ ]
+ };
+ var seq = new KJUR.asn1.DERSequence(options);
+ return seq.getEncodedHex();
};
/**
@@ -3952,8 +3979,8 @@ RSAKey.prototype.getPrivateBaseKey = function() {
* @returns {string} pem encoded representation without header and footer
* @public
*/
-RSAKey.prototype.getPrivateBaseKeyB64 = function (){
- return hex2b64(this.getPrivateBaseKey());
+RSAKey.prototype.getPrivateBaseKeyB64 = function () {
+ return hex2b64(this.getPrivateBaseKey());
};
/**
@@ -3963,7 +3990,7 @@ RSAKey.prototype.getPrivateBaseKeyB64 = function (){
* algorithm AlgorithmIdentifier,
* PublicKey BIT STRING
* }
- * Where AlgorithmIdentifier is:
+ * Where AlgorithmIdentifier is:
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER, the OID of the enc algorithm
* parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)
@@ -3976,36 +4003,36 @@ RSAKey.prototype.getPrivateBaseKeyB64 = function (){
* @returns {string} DER Encoded String representing the rsa public key
* @private
*/
-RSAKey.prototype.getPublicBaseKey = function() {
- var options = {
- 'array' : [
- new KJUR.asn1.DERObjectIdentifier({'oid':'1.2.840.113549.1.1.1'}), //RSA Encryption pkcs #1 oid
- new KJUR.asn1.DERNull()
- ]
- };
- var first_sequence = new KJUR.asn1.DERSequence(options);
-
- options = {
- 'array' : [
- new KJUR.asn1.DERInteger({'bigint' : this.n}),
- new KJUR.asn1.DERInteger({'int' : this.e})
- ]
- };
- var second_sequence = new KJUR.asn1.DERSequence(options);
-
- options = {
- 'hex' : '00'+second_sequence.getEncodedHex()
- };
- var bit_string = new KJUR.asn1.DERBitString(options);
-
- options = {
- 'array' : [
- first_sequence,
- bit_string
- ]
- };
- var seq = new KJUR.asn1.DERSequence(options);
- return seq.getEncodedHex();
+RSAKey.prototype.getPublicBaseKey = function () {
+ var options = {
+ 'array': [
+ new KJUR.asn1.DERObjectIdentifier({'oid': '1.2.840.113549.1.1.1'}), //RSA Encryption pkcs #1 oid
+ new KJUR.asn1.DERNull()
+ ]
+ };
+ var first_sequence = new KJUR.asn1.DERSequence(options);
+
+ options = {
+ 'array': [
+ new KJUR.asn1.DERInteger({'bigint': this.n}),
+ new KJUR.asn1.DERInteger({'int': this.e})
+ ]
+ };
+ var second_sequence = new KJUR.asn1.DERSequence(options);
+
+ options = {
+ 'hex': '00' + second_sequence.getEncodedHex()
+ };
+ var bit_string = new KJUR.asn1.DERBitString(options);
+
+ options = {
+ 'array': [
+ first_sequence,
+ bit_string
+ ]
+ };
+ var seq = new KJUR.asn1.DERSequence(options);
+ return seq.getEncodedHex();
};
/**
@@ -4013,8 +4040,8 @@ RSAKey.prototype.getPublicBaseKey = function() {
* @returns {string} pem encoded representation without header and footer
* @public
*/
-RSAKey.prototype.getPublicBaseKeyB64 = function (){
- return hex2b64(this.getPublicBaseKey());
+RSAKey.prototype.getPublicBaseKeyB64 = function () {
+ return hex2b64(this.getPublicBaseKey());
};
/**
@@ -4022,15 +4049,16 @@ RSAKey.prototype.getPublicBaseKeyB64 = function (){
* characters.
* @param {string} str the pem encoded string without header and footer
* @param {Number} [width=64] - the length the string has to be wrapped at
- * @returns {string}
+ * @returns {string}
* @private
*/
-RSAKey.prototype.wordwrap = function(str, width) {
- width = width || 64;
- if (!str)
- return str;
- var regex = '(.{1,' + width + '})( +|$\n?)|(.{1,' + width + '})';
- return str.match(RegExp(regex, 'g')).join('\n');
+RSAKey.prototype.wordwrap = function (str, width) {
+ width = width || 64;
+ if (!str) {
+ return str;
+ }
+ var regex = '(.{1,' + width + '})( +|$\n?)|(.{1,' + width + '})';
+ return str.match(RegExp(regex, 'g')).join('\n');
};
/**
@@ -4038,11 +4066,11 @@ RSAKey.prototype.wordwrap = function(str, width) {
* @returns {string} the pem encoded private key with header/footer
* @public
*/
-RSAKey.prototype.getPrivateKey = function() {
- var key = "-----BEGIN RSA PRIVATE KEY-----\n";
- key += this.wordwrap(this.getPrivateBaseKeyB64()) + "\n";
- key += "-----END RSA PRIVATE KEY-----";
- return key;
+RSAKey.prototype.getPrivateKey = function () {
+ var key = "-----BEGIN RSA PRIVATE KEY-----\n";
+ key += this.wordwrap(this.getPrivateBaseKeyB64()) + "\n";
+ key += "-----END RSA PRIVATE KEY-----";
+ return key;
};
/**
@@ -4050,11 +4078,11 @@ RSAKey.prototype.getPrivateKey = function() {
* @returns {string} the pem encoded public key with header/footer
* @public
*/
-RSAKey.prototype.getPublicKey = function() {
- var key = "-----BEGIN PUBLIC KEY-----\n";
- key += this.wordwrap(this.getPublicBaseKeyB64()) + "\n";
- key += "-----END PUBLIC KEY-----";
- return key;
+RSAKey.prototype.getPublicKey = function () {
+ var key = "-----BEGIN PUBLIC KEY-----\n";
+ key += this.wordwrap(this.getPublicBaseKeyB64()) + "\n";
+ key += "-----END PUBLIC KEY-----";
+ return key;
};
/**
@@ -4068,10 +4096,12 @@ RSAKey.prototype.getPublicKey = function() {
* be a parseable integer number
* @private
*/
-RSAKey.prototype.hasPublicKeyProperty = function(obj){
- obj = obj || {};
- return obj.hasOwnProperty('n') &&
- obj.hasOwnProperty('e');
+RSAKey.prototype.hasPublicKeyProperty = function (obj) {
+ obj = obj || {};
+ return (
+ obj.hasOwnProperty('n') &&
+ obj.hasOwnProperty('e')
+ );
};
/**
@@ -4083,16 +4113,18 @@ RSAKey.prototype.hasPublicKeyProperty = function(obj){
* should be parseable bigint objects, the public exponent should be a parseable integer number
* @private
*/
-RSAKey.prototype.hasPrivateKeyProperty = function(obj){
- obj = obj || {};
- return obj.hasOwnProperty('n') &&
- obj.hasOwnProperty('e') &&
- obj.hasOwnProperty('d') &&
- obj.hasOwnProperty('p') &&
- obj.hasOwnProperty('q') &&
- obj.hasOwnProperty('dmp1') &&
- obj.hasOwnProperty('dmq1') &&
- obj.hasOwnProperty('coeff');
+RSAKey.prototype.hasPrivateKeyProperty = function (obj) {
+ obj = obj || {};
+ return (
+ obj.hasOwnProperty('n') &&
+ obj.hasOwnProperty('e') &&
+ obj.hasOwnProperty('d') &&
+ obj.hasOwnProperty('p') &&
+ obj.hasOwnProperty('q') &&
+ obj.hasOwnProperty('dmp1') &&
+ obj.hasOwnProperty('dmq1') &&
+ obj.hasOwnProperty('coeff')
+ );
};
/**
@@ -4101,18 +4133,18 @@ RSAKey.prototype.hasPrivateKeyProperty = function(obj){
* @param {Object} obj - the object containing rsa parameters
* @private
*/
-RSAKey.prototype.parsePropertiesFrom = function(obj){
- this.n = obj.n;
- this.e = obj.e;
-
- if (obj.hasOwnProperty('d')){
- this.d = obj.d;
- this.p = obj.p;
- this.q = obj.q;
- this.dmp1 = obj.dmp1;
- this.dmq1 = obj.dmq1;
- this.coeff = obj.coeff;
- }
+RSAKey.prototype.parsePropertiesFrom = function (obj) {
+ this.n = obj.n;
+ this.e = obj.e;
+
+ if (obj.hasOwnProperty('d')) {
+ this.d = obj.d;
+ this.p = obj.p;
+ this.q = obj.q;
+ this.dmp1 = obj.dmp1;
+ this.dmq1 = obj.dmq1;
+ this.coeff = obj.coeff;
+ }
};
/**
@@ -4122,19 +4154,23 @@ RSAKey.prototype.parsePropertiesFrom = function(obj){
* the parameters needed to build a RSAKey object.
* @constructor
*/
-var JSEncryptRSAKey = function(key) {
- // Call the super constructor.
- RSAKey.call(this);
- // If a key key was provided.
- if (key) {
- // If this is a string...
- if (typeof key === 'string') {
- this.parseKey(key);
- }else if (this.hasPrivateKeyProperty(key)||this.hasPublicKeyProperty(key)) {
- // Set the values for the key.
- this.parsePropertiesFrom(key);
- }
+var JSEncryptRSAKey = function (key) {
+ // Call the super constructor.
+ RSAKey.call(this);
+ // If a key key was provided.
+ if (key) {
+ // If this is a string...
+ if (typeof key === 'string') {
+ this.parseKey(key);
+ }
+ else if (
+ this.hasPrivateKeyProperty(key) ||
+ this.hasPublicKeyProperty(key)
+ ) {
+ // Set the values for the key.
+ this.parsePropertiesFrom(key);
}
+ }
};
// Derive from RSAKey.
@@ -4145,21 +4181,21 @@ JSEncryptRSAKey.prototype.constructor = JSEncryptRSAKey;
/**
- *
- * @param {Object} [options = {}] - An object to customize JSEncrypt behaviour
+ *
+ * @param {Object} [options = {}] - An object to customize JSEncrypt behaviour
* possible parameters are:
* - default_key_size {number} default: 1024 the key size in bit
* - default_public_exponent {string} default: '010001' the hexadecimal representation of the public exponent
* - log {boolean} default: false whether log warn/error or not
* @constructor
*/
-var JSEncrypt = function(options) {
- options = options || {};
- this.default_key_size = parseInt(options.default_key_size) || 1024;
- this.default_public_exponent = options.default_public_exponent || '010001'; //65537 default openssl public exponent for rsa key type
- this.log = options.log || false;
- // The private and public key.
- this.key = null;
+var JSEncrypt = function (options) {
+ options = options || {};
+ this.default_key_size = parseInt(options.default_key_size) || 1024;
+ this.default_public_exponent = options.default_public_exponent || '010001'; //65537 default openssl public exponent for rsa key type
+ this.log = options.log || false;
+ // The private and public key.
+ this.key = null;
};
/**
@@ -4169,10 +4205,11 @@ var JSEncrypt = function(options) {
* @param {Object|string} key the pem encoded string or an object (with or without header/footer)
* @public
*/
-JSEncrypt.prototype.setKey = function(key){
- if (this.log && this.key)
- console.warn('A key was already set, overriding existing.');
- this.key = new JSEncryptRSAKey(key);
+JSEncrypt.prototype.setKey = function (key) {
+ if (this.log && this.key) {
+ console.warn('A key was already set, overriding existing.');
+ }
+ this.key = new JSEncryptRSAKey(key);
};
/**
@@ -4180,9 +4217,9 @@ JSEncrypt.prototype.setKey = function(key){
* @see setKey
* @public
*/
-JSEncrypt.prototype.setPrivateKey = function(privkey) {
- // Create the key.
- this.setKey(privkey);
+JSEncrypt.prototype.setPrivateKey = function (privkey) {
+ // Create the key.
+ this.setKey(privkey);
};
/**
@@ -4190,9 +4227,9 @@ JSEncrypt.prototype.setPrivateKey = function(privkey) {
* @see setKey
* @public
*/
-JSEncrypt.prototype.setPublicKey = function(pubkey) {
- // Sets the public key.
- this.setKey(pubkey);
+JSEncrypt.prototype.setPublicKey = function (pubkey) {
+ // Sets the public key.
+ this.setKey(pubkey);
};
/**
@@ -4203,13 +4240,14 @@ JSEncrypt.prototype.setPublicKey = function(pubkey) {
* @return {string} the decrypted string
* @public
*/
-JSEncrypt.prototype.decrypt = function(string) {
- // Return the decrypted string.
- try{
- return this.getKey().decrypt(b64tohex(string));
- }catch(ex){
- return false;
- }
+JSEncrypt.prototype.decrypt = function (string) {
+ // Return the decrypted string.
+ try {
+ return this.getKey().decrypt(b64tohex(string));
+ }
+ catch (ex) {
+ return false;
+ }
};
/**
@@ -4220,36 +4258,37 @@ JSEncrypt.prototype.decrypt = function(string) {
* @return {string} the encrypted string encoded in base64
* @public
*/
-JSEncrypt.prototype.encrypt = function(string) {
- // Return the encrypted string.
- try{
- return hex2b64(this.getKey().encrypt(string));
- }catch(ex){
- return false;
- }
+JSEncrypt.prototype.encrypt = function (string) {
+ // Return the encrypted string.
+ try {
+ return hex2b64(this.getKey().encrypt(string));
+ }
+ catch (ex) {
+ return false;
+ }
};
/**
- * Getter for the current JSEncryptRSAKey object. If it doesn't exists a new object
+ * Getter for the current JSEncryptRSAKey object. If it doesn't exists a new object
* will be created and returned
* @param {callback} [cb] the callback to be called if we want the key to be generated
* in an async fashion
* @returns {JSEncryptRSAKey} the JSEncryptRSAKey object
* @public
*/
-JSEncrypt.prototype.getKey = function(cb){
- // Only create new if it does not exist.
- if (!this.key) {
- // Get a new private key.
- this.key = new JSEncryptRSAKey();
- if (cb && {}.toString.call(cb) === '[object Function]'){
- this.key.generateAsync(this.default_key_size, this.default_public_exponent,cb);
- return;
- }
- // Generate the key.
- this.key.generate(this.default_key_size, this.default_public_exponent);
+JSEncrypt.prototype.getKey = function (cb) {
+ // Only create new if it does not exist.
+ if (!this.key) {
+ // Get a new private key.
+ this.key = new JSEncryptRSAKey();
+ if (cb && {}.toString.call(cb) === '[object Function]') {
+ this.key.generateAsync(this.default_key_size, this.default_public_exponent, cb);
+ return;
}
- return this.key;
+ // Generate the key.
+ this.key.generate(this.default_key_size, this.default_public_exponent);
+ }
+ return this.key;
};
/**
@@ -4258,9 +4297,9 @@ JSEncrypt.prototype.getKey = function(cb){
* @returns {string} pem encoded representation of the private key WITH header and footer
* @public
*/
-JSEncrypt.prototype.getPrivateKey = function() {
- // Return the private representation of this key.
- return this.getKey().getPrivateKey();
+JSEncrypt.prototype.getPrivateKey = function () {
+ // Return the private representation of this key.
+ return this.getKey().getPrivateKey();
};
/**
@@ -4269,9 +4308,9 @@ JSEncrypt.prototype.getPrivateKey = function() {
* @returns {string} pem encoded representation of the private key WITHOUT header and footer
* @public
*/
-JSEncrypt.prototype.getPrivateKeyB64 = function() {
- // Return the private representation of this key.
- return this.getKey().getPrivateBaseKeyB64();
+JSEncrypt.prototype.getPrivateKeyB64 = function () {
+ // Return the private representation of this key.
+ return this.getKey().getPrivateBaseKeyB64();
};
@@ -4281,9 +4320,9 @@ JSEncrypt.prototype.getPrivateKeyB64 = function() {
* @returns {string} pem encoded representation of the public key WITH header and footer
* @public
*/
-JSEncrypt.prototype.getPublicKey = function() {
- // Return the private representation of this key.
- return this.getKey().getPublicKey();
+JSEncrypt.prototype.getPublicKey = function () {
+ // Return the private representation of this key.
+ return this.getKey().getPublicKey();
};
/**
@@ -4292,11 +4331,21 @@ JSEncrypt.prototype.getPublicKey = function() {
* @returns {string} pem encoded representation of the public key WITHOUT header and footer
* @public
*/
-JSEncrypt.prototype.getPublicKeyB64 = function() {
- // Return the private representation of this key.
- return this.getKey().getPublicBaseKeyB64();
+JSEncrypt.prototype.getPublicKeyB64 = function () {
+ // Return the private representation of this key.
+ return this.getKey().getPublicBaseKeyB64();
};
+
+JSEncrypt.version = '2.3.0';
exports.JSEncrypt = JSEncrypt;
})(JSEncryptExports);
-var JSEncrypt = JSEncryptExports.JSEncrypt;
+(function (global, factory) {
+ if (typeof exports === 'object' && typeof module !== 'undefined') {
+ module.exports = factory;
+ } else if (typeof define === 'function' && define.amd) {
+ define(factory);
+ } else {
+ global.JSEncrypt = factory;
+ }
+}(this, JSEncryptExports.JSEncrypt)); \ No newline at end of file