Git Product home page Git Product logo

Comments (7)

tiny-tinker avatar tiny-tinker commented on August 16, 2024 1

Hmmm, making those changes resulted in the not defined error:

ReferenceError: "window" is not defined.

So I just added some if statements: (~line 74)

if( typeof window === "undefined" )
  var window = {};
if( typeof navigator === "undefined" )
  var navigator = {}; 

if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
  BigInteger.prototype.am = am2;
  dbits = 30;
}
else if(j_lm && (navigator.appName != "Netscape")) {
  BigInteger.prototype.am = am1;
  dbits = 26;
}
else { // Mozilla/Netscape seems to prefer am3
  BigInteger.prototype.am = am3;
  dbits = 28;
}

I had to make one more change as I was getting:

"../jsencrypt.js", line 3837: uncaught JavaScript runtime exception: ReferenceError: "ASN1" is not defined.

So I added "window" here: (~line 3837)

window.ASN1.prototype.getHexStringValue = function(){
    var hexString = this.toHexString();
    var offset = this.header * 2;
    var length = this.length * 2;
    return hexString.substr(offset,length);
};

This of course resulted in a few other errors. I added "window." to the Base64 and ASN1 objects below: (~line 3867)

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) : window.Base64.unarmor(pem);
        var asn1 = window.ASN1.decode(der);

Finally, I ran this code before I did the load( 'jsencrypt' ) call:

console = { 
   error: function( stuff ) { print( stuff ) },
   warn:  function( stuff ) { print( stuff ) },
   info:  function( stuff ) { print( stuff ) },
   debug: function( stuff ) { print( stuff ) },
   log:   function( stuff ) { print( stuff ) }
}

I haven't tried decrypting yet, the thread keeps running out of memory. I'm pretty sure there is a meomory leak in rhino or something. I'll have to dig into that.

from jsencrypt.

tiny-tinker avatar tiny-tinker commented on August 16, 2024

Oh, well I think i got it working... haven't fully tested yet, but it successfully loads.
I set

var window = {};
var navigator ={};

around line 73.
Then, it looks like the "ASN1.prototype.getHexStringValue" around line 3834 is outside the anonymous function its brothers are in. So, I move the closing }) (); to just after this block.

from jsencrypt.

tiny-tinker avatar tiny-tinker commented on August 16, 2024

Darn.. I can't just fake it :)

from jsencrypt.

travist avatar travist commented on August 16, 2024

We will need to patch the jsbn libraries from Tom Wu to fix this issue. It can probably be done if you just add a check if those variables exist before calling an object within them. Like this...

if(j_lm && navigator && (navigator.appName == "Microsoft Internet Explorer")) {
  BigInteger.prototype.am = am2;
  dbits = 30;
}
else if(j_lm && navigator && (navigator.appName != "Netscape")) {
  BigInteger.prototype.am = am1;
  dbits = 26;
}
else { // Mozilla/Netscape seems to prefer am3
  BigInteger.prototype.am = am3;
  dbits = 28;
}

from jsencrypt.

zoloft avatar zoloft commented on August 16, 2024

Hey @nomadic-squirrel

MadBookPro:~ zoloft$ rhino -opt -1
Rhino 1.7 release 4 2012 06 18
js> load('http://www.envjs.com/dist/env.rhino.1.2.js');
[  Envjs/1.6 (Rhino; U; Mac OS X x86_64 10.9.3; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13  ]
js> load('https://raw.githubusercontent.com/travist/jsencrypt/master/bin/jsencrypt.js');
js> 

I have not tried yet to encrypt/decrypt but my guess is that is working. Please tell me if it does, so that we can close this issue

from jsencrypt.

zoloft avatar zoloft commented on August 16, 2024
Rhino 1.7 release 4 2012 06 18
js> load('http://www.envjs.com/dist/env.rhino.1.2.js');
[  Envjs/1.6 (Rhino; U; Mac OS X x86_64 10.9.3; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13  ]
js> load('https://raw.githubusercontent.com/travist/jsencrypt/master/bin/jsencrypt.js');
js> var encrypt = new JSEncrypt({default_key_size:512});
js> encrypt.getKey();
[object Object]
js> console.log(encrypt.getPrivateKey());
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAIffqt9plHVSYV1r+9R2F/dGwPdkJESOrG+uhgqDeabFVwcFN3SE
QQtBIs5swz9SV+GsltrKunbnTUot+huwUeUCAwEAAQJAJH/UAgH1rHJ9zz/DvXYf
yABMs+hFydjdv36NaWOaGU9AZn8EUQAhHguxGTzcfBTNAfmHfkTXp/EcUmMHn6FE
wQIhAO6viXs1YUmU3N3XRPsXtFA9uzw06BUGQ1x4iTLvg1AxAiEAkbrhuxy19pKp
rEwQEal3mIiNvT24kJOK/51ghVlUA/UCIQC3HMgWU99tOd0v/ASZtZfJr3JDQDuE
Vae7+2UWRJWzIQIgIbwUMx9jVBABbRwygBQt1kaOISefiQBOpfuFc3kJRN0CIGfO
Wa1wi9DmPB0QGQ24Y/+eW4Eb3YRfEwYo+D/BUXuW
-----END RSA PRIVATE KEY-----
js> 

Seems to work, closing this issue

from jsencrypt.

tiny-tinker avatar tiny-tinker commented on August 16, 2024

Hey, sorry, this was on my list to checkout, but I haven't gotten to it yet. If I get a chance, I'll check it out, but I'm fine with closing this issue.
Thanks!!

from jsencrypt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.