Comments (7)
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.
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.
Darn.. I can't just fake it :)
from jsencrypt.
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.
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.
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.
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)
- Decrypted result has wrong encoding HOT 1
- window is not defined in nuxtjs v3 HOT 8
- Suggest to add judgment when string too long
- Front-end performed RSA signature on the HMAC using SHA256, but the length was incorrect, causing the server to fail to verify it. HOT 1
- CVE-2012-5883
- An error occurred when using jsencrypt in a lower version of Chrome
- encryption returning false HOT 3
- Support node.js ? ReferenceError: window is not defined HOT 6
- Problem after upgrade to latest version from 3.2.1 on verify method
- Why is the result of each encryption different from the same content?
- [REQUEST] remove browser dependency ?
- Can the ciphertext length of JSENCRYPT 3.3.2 be controlled
- nest.js jsencrypt does not work with error `window is not defined`
- Content-Security-Policy blocked jsencryt.min.js file version 3.0.0-rc.2
- Need a fix for CVE-2023-46809 HOT 3
- Problem to decrypt in NodeJs with crypto HOT 1
- How should Java verify your generated signature HOT 1
- How to decrypt Blob、ArrayBuffer ?
- yahoo.js文件中的yui代码存在安全漏洞,是否使用最新版本的代码 HOT 4
- @3.3.2 linux public Rollup failed to resolve import HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsencrypt.