Git Product home page Git Product logo

jsencrypt's Introduction

Website

http://travistidwell.com/jsencrypt

Introduction

When browsing the internet looking for a good solution to RSA Javascript encryption, there is a whole slew of libraries that basically take the fantastic work done by Tom Wu @ http://www-cs-students.stanford.edu/~tjw/jsbn/ and then modify that code to do what they want.

What I couldn't find, however, was a simple wrapper around this library that basically uses the library practically untouched, but adds a wrapper to provide parsing of actual Private and Public key-pairs generated with OpenSSL.

This library is the result of these efforts.

How to use this library.

This library should work hand-in-hand with openssl. With that said, here is how to use this library.

  • Within your terminal (Unix based OS) type the following.
openssl genrsa -out rsa_1024_priv.pem 1024
  • This generates a private key, which you can see by doing the following...
cat rsa_1024_priv.pem
  • You can then copy and paste this in the Private Key section of within index.html.
  • Next, you can then get the public key by executing the following command.
openssl rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem
  • You can see the public key by typing...
cat rsa_1024_pub.pem
  • Now copy and paste this in the Public key within the index.html.
  • Now you can then convert to and from encrypted text by doing the following in code.
<!doctype html>
<html>
  <head>
    <title>JavaScript RSA Encryption</title>
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="bin/jsencrypt.min.js"></script>
    <script type="text/javascript">

      // Call this code when the page is done loading.
      $(function() {

        // Run a quick encryption/decryption when they click.
        $('#testme').click(function() {

          // Encrypt with the public key...
          var encrypt = new JSEncrypt();
          encrypt.setPublicKey($('#pubkey').val());
          var encrypted = encrypt.encrypt($('#input').val());

          // Decrypt with the private key...
          var decrypt = new JSEncrypt();
          decrypt.setPrivateKey($('#privkey').val());
          var uncrypted = decrypt.decrypt(encrypted);

          // Now a simple check to see if the round-trip worked.
          if (uncrypted == $('#input').val()) {
            alert('It works!!!');
          }
          else {
            alert('Something went wrong....');
          }
        });
      });
    </script>
  </head>
  <body>
    <label for="privkey">Private Key</label><br/>
    <textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
    <label for="pubkey">Public Key</label><br/>
    <textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
    <label for="input">Text to encrypt:</label><br/>
    <textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/>
    <input id="testme" type="button" value="Test Me!!!" /><br/>
  </body>
</html>
// Sign with the private key...
var sign = new JSEncrypt();
sign.setPrivateKey($('#privkey').val());
var signature = sign.sign($('#input').val(), CryptoJS.SHA256, "sha256");

// Verify with the public key...
var verify = new JSEncrypt();
verify.setPublicKey($('#pubkey').val());
var verified = verify.verify($('#input').val(), signature, CryptoJS.SHA256);

// Now a simple check to see if the round-trip worked.
if (verified) {
  alert('It works!!!');
}
else {
  alert('Something went wrong....');
}
  • Note that you have to provide the hash function. In this example we use one from the CryptoJS library, but you can use whichever you want.
  • Also, unless you use a custom hash function, you should provide the hash type to the sign method. Possible values are: md2, md5, sha1, sha224, sha256, sha384, sha512, ripemd160.

Other Information

This library heavily utilizes the wonderful work of Tom Wu found at http://www-cs-students.stanford.edu/~tjw/jsbn/.

This jsbn library was written using the raw variables to perform encryption. This is great for encryption, but most private keys use a Private Key in the PEM format seen below.

1024 bit RSA Private Key in Base64 Format

-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDHikastc8+I81zCg/qWW8dMr8mqvXQ3qbPAmu0RjxoZVI47tvs
kYlFAXOf0sPrhO2nUuooJngnHV0639iTTEYG1vckNaW2R6U5QTdQ5Rq5u+uV3pMk
7w7Vs4n3urQ6jnqt2rTXbC1DNa/PFeAZatbf7ffBBy0IGO0zc128IshYcwIDAQAB
AoGBALTNl2JxTvq4SDW/3VH0fZkQXWH1MM10oeMbB2qO5beWb11FGaOO77nGKfWc
bYgfp5Ogrql4yhBvLAXnxH8bcqqwORtFhlyV68U1y4R+8WxDNh0aevxH8hRS/1X5
031DJm1JlU0E+vStiktN0tC3ebH5hE+1OxbIHSZ+WOWLYX7JAkEA5uigRgKp8ScG
auUijvdOLZIhHWq7y5Wz+nOHUuDw8P7wOTKU34QJAoWEe771p9Pf/GTA/kr0BQnP
QvWUDxGzJwJBAN05C6krwPeryFKrKtjOGJIniIoY72wRnoNcdEEs3HDRhf48YWFo
riRbZylzzzNFy/gmzT6XJQTfktGqq+FZD9UCQGIJaGrxHJgfmpDuAhMzGsUsYtTr
iRox0D1Iqa7dhE693t5aBG010OF6MLqdZA1CXrn5SRtuVVaCSLZEL/2J5UcCQQDA
d3MXucNnN4NPuS/L9HMYJWD7lPoosaORcgyK77bSSNgk+u9WSjbH1uYIAIPSffUZ
bti+jc1dUg5wb+aeZlgJAkEAurrpmpqj5vg087ZngKfFGR5rozDiTsK5DceTV97K
a3Y+Nzl+XWTxDBWk4YPh2ZlKv402hZEfWBYxUDn5ZkH/bw==
-----END RSA PRIVATE KEY-----

This library simply takes keys in the following format, and translates it to those variables needed to perform the encryptions used in Tom Wu's library.

Here are some good resources to investigate further.

With this information, we can translate a private key format to the variables required with the jsbn library from Tom Wu by using the following mappings.

modulus => n
public exponent => e
private exponent => d
prime1 => p
prime2 => q
exponent1 => dmp1
exponent2 => dmq1
coefficient => coeff

jsencrypt's People

Contributors

antife-yinyue avatar calve avatar crecket avatar ctso avatar dependabot[bot] avatar elden1221 avatar hwangtaehyun avatar jordiwang avatar jpsfs avatar kingller avatar kripod avatar leandrozuliani avatar llcorvinsll avatar lmnsg avatar marvinklein avatar maxkomarychev avatar mdjdenormandie avatar monako97 avatar originalix avatar pkaminski avatar qxo avatar spark-nf avatar thooton avatar tinycat2017 avatar tonkpils avatar travist avatar yq612 avatar zoloft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsencrypt's Issues

jsencrypt.js - replace atob() for compatibility with IE9 and older browsers

It doesn't work in IE 9 and older browsers because atob() is only supported from IE 10.

To make it working in old versions of Internet Explorer I replaced atob() in jsencrypt.js with another base64 function.

To fix it, I used base64.js by Chris Veness from http://www.movable-type.co.uk/scripts/base64.js which I loaded it in the header of HTML page as:

<script src="base64.js"></script>

Then, in jsencrypt.js I replaced following string:
str = atob(str);
with the following string:
str = Base64.decode(str);

can not encrypt with public key

I have a pubic key such as
4KXgatY/EqROEtvVcDt5qTcM8i2hP8JvpH6KN7HoZjHVJtfXaXW8c/sfJGZWrqdbogwFXVR/HxTscXWE1SeHay2QsGhkpEDV7YF7R9vyDIvWOd/2AXwcszjxB9swLQEjcSP7lLqQ226MhDah8rsSPljJ9FYNfGW6K2PxP+mqDf0=
but can not sign any string with this key ,the key is generated with a rsa key util,thanks.

Priv -> Public - Decryption without the private certificate does not work

Hello Travis,
I am using your code in the browser, and so far he did very well, congratulations.
But I'm struggling to encrypt a message with the private certificate, then decrypt the message using ONLY the public certificate.
Am I doing something wrong?
Thanks for support !
Fabrício Dias
[email protected]

//Private Cert
    var privKey = "";
    privKey += "-----BEGIN RSA PRIVATE KEY-----\n";
    privKey += "MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ\n";
    privKey += "WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR\n";
    privKey += "aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB\n";
    privKey += "AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv\n";
    privKey += "xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH\n";
    privKey += "m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd\n";
    privKey += "8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF\n";
    privKey += "z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5\n";
    privKey += "rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM\n";
    privKey += "V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe\n";
    privKey += "aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil\n";
    privKey += "psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz\n";
    privKey += "uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876\n";
    privKey += "-----END RSA PRIVATE KEY-----\n";

//Public Cert
    var pubKey = "";
    pubKey += "-----BEGIN PUBLIC KEY-----\n";
    pubKey += "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN\n";
    pubKey += "FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76\n";
    pubKey += "xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4\n";
    pubKey += "gwQco1KRMDSmXSMkDwIDAQAB\n";
    pubKey += "-----END PUBLIC KEY-----\n";

//Test - Public -> Private - ITS OK
    var txtPayload = 'This is a test! #1';
    var txtEncrypt = null;
    var txtDecrypt = null;
    var jsEncrypt = new JSEncrypt();
        jsEncrypt.setPublicKey(pubKey);
        txtEncrypt = jsEncrypt.encrypt(txtPayload);
    var jsDecrypt = new JSEncrypt();
        jsDecrypt.setPrivateKey(privKey);
        txtDecrypt = jsDecrypt.decrypt(txtEncrypt);
//Debug
    if ( txtPayload == txtDecrypt ) {
        alert('Public -> Private: It works!!!');
    } else {
        alert('Public -> Private: Something went wrong....');
    }
    console.log("Public -> Private");
    console.log("txtPayload: ", txtPayload);
    console.log("txtEncrypt: ", txtEncrypt);
    console.log("txtDecrypt: ", txtDecrypt);    
/**/

//Test - Private -> Public - ITS NOK
    var txtPayload = 'This is a test #2';
    var txtEncrypt = null;
    var txtDecrypt = null;
    var jsEncrypt = new JSEncrypt();
        jsEncrypt.setPrivateKey(privKey);
        txtEncrypt = jsEncrypt.encrypt(txtPayload);
    var jsDecrypt = new JSEncrypt();
        jsDecrypt.setPublicKey(pubKey);
        txtDecrypt = jsDecrypt.decrypt(txtEncrypt);
//Debug
    if ( txtPayload == txtDecrypt ) {
        alert('Private -> Public: It works!!!');
    } else {
        alert('Private -> Public: Something went wrong....');
    }
    console.log("Private -> Public");
    console.log("txtPayload: ", txtPayload);
    console.log("txtEncrypt: ", txtEncrypt);
    console.log("txtDecrypt: ", txtDecrypt);    
/**/

Automatic key expiration

I am having a scenario where i want to secure the JSON data which i am sending and storing at the client side, and i also want that, that data should be protected, The way to protect this data i suppose is encryption of the data but because the decryption logic and key is also at the client side (to decrypt the encrypted JSON data).

So to protect it i was wondering if we can set something like expiration time of key,

The way i was thinking this is to work that if someone is encrypting the data with the key then encrypted data must have some intelligence that after a period of time this data cannot be decrypted with the key with which it was encrypted(or may be cannot be decrypted at all).

is it possible? i suppose yes , and i don't it is there in the library now.

so i am asking to all members to please provide this facility in this library, or if it is not possible(which i suppose is not) or is not gonna solve a problem please justify.

Thanks.

client side encrypt, server side decrypt node.js ursa

Hello, i try to do this:

client side
var crypt = new JSEncrypt();
crypt.setKey('-----BEGIN PUBLIC KEY-----YOUR PUBLIC KEY-----END PUBLIC KEY-----'); //You can use also setPrivateKey and setPublicKey, they are
both alias to setKey

//Eventhough the methods are called setPublicKey and setPrivateKey, remember
//that they are only alias to setKey, so you can pass them both a private or
//a public openssl key, just remember that setting a public key allows you to only encrypt.

var text = 'test';
// Encrypt the data with the public key.
var enc = crypt.encrypt(text);
alert(enc);

And the server side:

'use strict';

var fs = require('fs')
, ursa = require('ursa')
, crt
, key
, msg
;

key = ursa.createPrivateKey(fs.readFileSync('./rsapriv.pem'));

msg = 'oDdwc6sYZz1FxpFr/ZumS2rrgkUN38raevlj4iNLDZg6JcQkxB9ARXnhd+Jljx37xgoVcQ+rmDQZQLMVjsFOoSBGjuR+uDnY3V8u+8OQpcODMgNU1nFaqrgt34s904Djf6a9kxqO33CZWg2rCjM+XzA2SlfcH66CiBMhW0
CeB+pPxLN0Hx+pmSzla7+J1B3DG8/Nan9LltzZ8/RdHwks2icWylCbUvRadQamQDUKjhKfPSH4ITLAw9QjJy+qT+GyXvv9JDRBI2WocIcADDRqkJScpw20pJKEz6WC8cs8stSpNrSOebDIj3tnquo0yqa4Ok8AXzakk4lndtBZqPI
JBA==';

console.log('Decrypt with Private');
msg = key.decrypt(msg, 'base64', 'utf8');
console.log(msg);

Error:
return encodeBuffer(rsa.privateDecrypt(buf, padding), outEncoding);
^
Error: error:0407A079:rsa routines:RSA_padding_check_PKCS1_OAEP:oaep decoding error
at Object.decrypt (/home/mari/node/jsencrypt/node_modules/ursa/lib/ursa.js:291:33)
at Object. (/home/mari/node/jsencrypt/server2.js:23:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3

thank you

Working with PHP data

I seem to have problems using PHP to get it to work with this library.
I intend to do this:

1st - Generate a session wide Public-Private key pair. The public key is always available on the website and the private key will be kept in a session variable or server text file link to the session.
2nd - When a user gives out the password, jsencrypt will crypt the password with the public key and the server side will decrypt it.

Below is a test script i've made ( from http://php.net/manual/en/function.openssl-pkey-new.php )

header("Content-type: text/plain");
$sslconfig = array(
        "private_key_bits" => 1024,
        "private_key_type" => OPENSSL_KEYTYPE_RSA);

$res = openssl_pkey_new($sslconfig);
// Extract the private key from $res to $privKey
openssl_pkey_export($res,$_SESSION["ffar_kagi"]);

// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$_SESSION["ffar_kagip"] = $pubKey["key"];

echo $_SESSION["ffar_kagi"];
echo "\n\n------\n\n";
echo $_SESSION["ffar_kagip"];

Copying and pasting the code to this lib's demo, and then try to encrypt with it, gives me false, so I presume that I have something wrong with the php script above.
I'm not sure if I should use sha512 as the digest alg, so I went with MD digest which is the default for openssl_pkey_new().

Anyone has already tried this lib with PHP?
Thank you :)

Keypair key-size does not match default_key_size

Hi
thanks for your great wrapper! I found one use case that gives me a headache and can be reproduced like this:

var crypt = new JSEncrypt({default_key_size: 2048});
crypt.getPrivateKey()

I then paste the return value into a file and parse that file with gives me the following output (note the key size):

#~ openssl rsa -in pkey.key -text -noout
Private-Key: (2047 bit)
modulus:
[SNIP]

So openssl (and every other user of the key) finds this is a 2047 bit key. My workaround is using a default_key_size of 2049, I feel that we should look into this.

The same happens with a 1024 bit key (output is 1023 bit). Any ideas? Is this maybe expected?

Edit: I found out that if I try multiple times I get an 2048 bit key eventually

iOS needs very long for async keypair generation

cheers,
i discovered that apple do some stuff what i can't realize.
what i've found out that iPhone 4 and iPod Touch 5 needs about 3m or hours to generate a keypair.
iPad Air needs 1m 30s

  • now the good ones -
    MotoG Android 4.4.4. needs 21s
    Google Chrome on Windows Desktop needs 25s
    Samsung S2 needs 48s

now the question what does apple different as android/desktop???

here a js profile screenshot of a generation on iPhone 4 (generation needs 8m):
Alt profiler

can someone help me please?

Unresolved variable 'DV'

On line 123 of jsencrypt.js, the variable 'DV' appears to be a typo. Every other usage of DV treats it as a property ("this.DV" on lines 317, 344, etc).

[enhancement] Add missing bower.json.

Hey, maintainer(s) of travist/jsencrypt!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library travist/jsencrypt is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "travist/jsencrypt",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Rhino support?

Hello! This is an awesome utility and I appreciate the work you've done to convert the work of Tom Wu. I am looking to do some decrypting with an application that uses the rhino javascript engine, however, when I try to load this jsencrypt.js file, I get a few errors related to window and navigator:

[user@host ~]$ which rhino
/usr/bin/rhino
[user@host ~]$ rhino
Rhino 1.7 release 0.7.r2.2.9.amzn1 2012 03 08
js> load( 'https://raw.github.com/travist/jsencrypt/5ce6c71731b1622983bfddcc499cdd80702ca88c/bin/jsencrypt.js' );
js: "https://raw.github.com/travist/jsencrypt/5ce6c71731b1622983bfddcc499cdd80702ca88c/bin/jsencrypt.js", line 72: uncaught JavaScript runtime exception: ReferenceError: "navigator" is not defined.
        at https://raw.github.com/travist/jsencrypt/5ce6c71731b1622983bfddcc499cdd80702ca88c/bin/jsencrypt.js:72
        at https://raw.github.com/travist/jsencrypt/5ce6c71731b1622983bfddcc499cdd80702ca88c/bin/jsencrypt.js:2
        at <stdin>:2

js>

I poked through and tried setting navigator = {} on line 73 and got an error about window, so I did the same for window = {} on 1276, but ran into another error about ASN1. Suggestions or ideas?

Thanks again!

Decrypt with public key

Hello, is there any way to decrypt text using public key instead a private key? I would like to encrypt message on server using server's private key and I would like to decrypt it in browser using public key.

Encrypting text with public key generated in a different browser returns false

I am trying to encrypt data with a public key from someone else received out of my database but all I get is "false". I checked if the public key I got from the database was the same as the one generated by the different browser and they match.
Code:

var crypt = new JSEncrypt();
crypt.setPublicKey($("#rkey").val());
var password = crypt.encrypt(pass);

(rkey is the recipients public key key gained from the database and pass is a password generated in the browser)

node.js?

Is there a version that works with node.js?

node-rsa can't decrypt

Probably having the same issue as #39 but my message error is more like ""Error during decryption (probably incorrect key).""

It works well on local.

Max string size for encrypt function

Hello,
Is there a maximum string size for the encrypt function? If I try to encrypt long texts using this I get false.

Example text:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Key Size: 2048bit

Missing parameter in addEventListener call produce JavaScript error under Firefox 4

Firefox 4 (an old release I agree) gives an error when loading the jsencrypt.js file. The error is in https://github.com/travist/jsencrypt/blob/master/jsbn/rng.js#L35 :

window.addEventListener("mousemove", onMouseMoveListener);

Firefox4 complains about a missing parameter. When adding "false" as a third parameter, the error is not raised up:

window.addEventListener("mousemove", onMouseMoveListener, false);

This issue is also reported in CreateJS/PreloadJS#4

@travist thanks for jsencrypt. It works as a breeze and is well documented.

makefile's @echo -e option not recognized

For some reason, the @echo -e option is not recognized on my system (linux mint 15, bash 4.2.5, make 3.81.8), which results in the invalid expression "-e" being added to the generated files. This raises an error on IE8 (and probably others).
A possible solution would be to remove this option from the makefile.

Below, the relevant output from the makefile

JSEncrypt.prototype.getPublicKeyB64 = function() {
    // Return the private representation of this key.
    return this.getKey().getPublicBaseKeyB64();
};-e 
exports.JSEncrypt = JSEncrypt;
})(JSEncryptExports);

about npm support

I see, you had publish done the library to npm.
But, the latest version still have not the main attribute, so, it is not available when I require it in my application.
however I can use require('jsencrypt/src/jsencrypt.js'), but..... you know, I am very lazy!

so, would you please republish a new version to fix it?
Thank you!

Bug in rsa.js

Hello,

I have found a bug in jsbn rsa.js which might lead to a security vulnerability
in jsencrypt (http://www-cs-students.stanford.edu/~tjw/jsbn/rsa.js).

I have a patch to submit.

Is there a specific procedure to report it ?

I already mailed the author of the original jsbn library, but my mail get rejected by the server. Maybe someone knows another contact ?

.html documents have broken links?

After I cloned to my machine, I found that the links in index.html of home, demo and test are broken.

The tag base href="/jsencrypt/" should be fixed to

base href="../" for index.html in demo and test directory,
base href="./" for index.html in home directory.

Thank you!

Support signing with private key and signature verification with public key

Currently it's only possible to encrypt using the Public key and decrypt using the private key. It's not possible to encrypt using the private key and decrypt using the public key for signature verification.

This feature is absolutely a MUST for me, and I really want to stick with this library instead of using one of the other "heavy" libraries out there.

Support encryption and decryption without padding

I need to implement deterministic RSA encryption on serverside(Ruby) and then decrypt this data on frontend. My ruby code:

require 'openssl'
require 'base64'

KEY_SIZE=2048

message = 'Test message'

if message.length < KEY_SIZE
  message = message + (' ' * (KEY_SIZE / 8 - message.length))
end

key_file = File.read('public.pem')
public_key = OpenSSL::PKey::RSA.new key_file
result = Base64.encode64(public_key.public_encrypt(message, OpenSSL::PKey::RSA::NO_PADDING))
puts result

But, jsencrypt can't decrypt it=( Is there any workarounds?

Issues decoding with PHP OpenSSL generated private key

Encryption works fine, and I can decrypt again in PHP using the private key. However, using a PHP5.5 private key, I'm unable to decrypt with JSEncrypt. PHP 5.4 generated private keys on my mac is able to decrypt with JSEncrypt however.

I do notice that the key no longer included RSA on the failing private keys (http://php.net/manual/en/function.openssl-pkey-export.php#101839)

Example Public Key:

-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtCllajSev6wdWy29Ow2l
28S0jZnVmnOsAzAa3bIWfeH54PbBcP0+799jR4Y8mHXcdyx229AKVpNr8nb30iwH
4w2PcG6EC1ozCw3J0Wc+jtIJkl97rFF3t2Zg34Jl2hrfdb29fb36WS5bMwII/ONN
XP1o7RBda/MOt4kl9dJE5CTQUW/x5Db44a1EFD3P8sKFWPlwCqs7KEGNmvPSvteO
UdCLNRyd8W1ORngrZ3agoDp8B0mwIzZnzVlS08Z7j66rLTrIitVDHc0o40jKm58i
GPBsrV9PXxz9DrNSkruIXmrziZuwdBX3ucTZXgu+anNdzCRcMET2tOgpO8mUtpwL
NYsDpyGZ89eta0nsxAQe9jcn2PEDl32HujaMyU8yVth/JhLXOW5pODi+KPfwCL2g
S6ZE1LPUkcsmuhozLT5ePVswRNYOO8DcFc63k4oV0ZuRiXpTzGBquzU6MeLoCkJm
wWAdtVD81H6fPeMvA7pWmFauTn847M8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En4F9K4K4YPfy/yd9GTMeeNfrjeA29fpqq0Afyt3arKk9lVlHPxdR1TrzNTAN3j
78J7JuEZxsq7lEI/72q7n+hzRA6KNFIaGmTNe+DoDjegaPh3Coj82rMRkuqEoYp6
KT0ixMYL8l60lIplD1zqekbtfEjhmRAMaRzP9fdQPqOZxS9lhrlYwyb0WRxb/a6s
Yqa08FSwsgK2GOEUJU4tx/m28a1lXA==
-----END PRIVATE KEY-----

Example of 'testing' encrypted:

UZ7xDUgPk06BIT1M3PFGlTN8h2iOJvwJl0MO8NkklkhfK6zsxgz25FQLRa37FcyPSSz3w/+HbUm1YQy0Kdg3DQsPYr8aNtTIZ5FyQlqoUZwViSEdAqrgtUFdcxWSTf6yaQsRjSsSGUz4UHh/rFt1shrUN9MJ1O+e0Gml9ySLhwffUz6vvReE0avbZXT/GbkwitxvcWTL3xTKM19U6mvTB/+vHse3HyrbNKxDqVzn7a10N+ZcxmQpVjf4uC8U5dQtkkCBVcexdY0vVqps62Ilw8cNLGD0MLejs0ypMgB9lMklInIYigvP45sgnEgs4tsKXio72kW/2LVN6c0EUtAhkrFIk9LY1cUVov/swEJ658GxKS088LWW+xLZz49rOdM6BPFrcdw2CCLxbbrCTF+wxm5tTKFKVW+Z3xSBX9tBTkj1ZiO9rIGLLUEX6QGFSy/BIEPOaxnKRExr92CD2Dg9mRgGJbGntYiaz07Pa89ciURkCEQssyZFqnCaLt2k9+0dXKWNr8N4dQr3v+GBPNZbKW7EGXNX1tRiLThiS+BHSBkcdgZD+RLtWEVg/mWogh9Ukg9Qz5/JZyRQt4r+4uFHCFcteiauS1qHWZxuLPRTHXeCRnpmRiY2bPeIscwMk8a2h5yrYeIgMrchzFKqRXsybjpyLFiSUiydLVR+t4bMzUY=

I've attempted multiple key lengths etc but that makes no difference.

SSL VERSIONS:

WORKS WITH: OpenSSL 0.9.8za 5 Jun 2014
FAILS WITH: OpenSSL 1.0.1f 6 Jan 2014

Math.random on V8 not random enough

I just read TIFU by using Math.random() (discussion on HN at https://news.ycombinator.com/item?id=10598065). TL;DR this is what Math.random yields on Firefox

firefox random 500x140

and this is what it yields on V8

v8 random 500x140

The author suggests using crypto.getRandomValues in the browser. That populates a typed array with random values. Example:

> var random_int32 = new Uint32Array(5);
> crypto.getRandomValues(random_int32)
[3893288831, 502897280, 4154045839, 415033321, 3522955257]

https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues

Support decrypting with public key

I am using ursa on a Node server which supports encrypting with private key, so I'd like to try to decrypt it on the client side with public key.

Would that be possible without rewriting the base?

Cannot decrypt binary data

Hi,
I made the library work for standard plain English data. But my real use case is RSA decrypting a binary data chunk and it does not seem to produce expected result. I have validated that both OpenSSL and C# RSA provider produce identical bytes. But JSEncryptor behaves strange. It produce strange set of characters which sometimes match the expected results and sometimes do not. Please review details below.
Private Key and Encypted text below. I am banging my head against the wall on this one so I really appreciate any pointers...

Expected result:
$ base64 -D test.enc | openssl rsautl -decrypt -inkey test.priv -hexdump
0000 - 57 27 19 73 ba 3c f4 48-04 1c 8e 5f f8 1c e0 d1 W'.s.<.H..._....
0010 - d7 97 7e 73 cc 53 77 d1-88 3f 0d 79 42 13 65 87 ..~s.Sw..?.yB.e.

My results. See how small numbers match but large numbers cannot be mapped to the expected bytes. It feels like it is UTF-8 but not quite. And there are strange misses and unexpected character at the end:
C# (Bytes) JS (characters)
087 0x57 87
039 0x27 39
025 0x19 25
115 0x73 115
186 0xBA 44852
060 0x3C
244 0xF4
072 0x48 72
004 0x04 4
028 0x1C 28
142 0x8E 59384
095 0x5F
248 0xF8
028 0x1C 28
224 0xE0 ????? <--- this byte is unclear
209 0xD1 1111
215 0xD7
151 0x97 32691
126 0x7E
115 0x73
204 0xCC 787
083 0x53
119 0x77 119
209 0xD1 1096
136 0x88
063 0x3F 63
013 0x0D 13
121 0x79 121
066 0x42 66
019 0x13 19
101 0x65 101
135 0x87 28672 <-- This one is unexpected....

$ cat test.priv
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKC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b9
ZeA+pW+JxcwC85kZ34u6jaNsGa9DijoaiRL5IgEKK35LAWMdq3c7fZUL5jv/E5KC
aCyAjPv1GQY5NEdABT3es8AUyfeCXyABR72rZ+yYPy11EfDypj0xSxK/mK94kArY
eWi0Q+Owezq7bhKtkhxpF6UCgYBiMxfQkTVH+78tENeLT+jNncJeYzyD26sJni9R
4Jh/3NP0J+iOk2t5h/iO3iH+KpLtOTNRRGDDURTlxbWweiCMo+ddzZb71uvuoNAM
rDi9S/JXEIJ0soySBpa42qMv0b26eXMGbB0LpV4xqeOzTOFarQJhrQndI/eRU20o
hE4HWwKBgQCX5TEkoeBnO2DDNj5vPN0LCOzcG4c4QqpkhfmAEpRNBBNiEKwuWsHq
S1LLlsR1Z/ycs21KOeaG5mXS4WWZjVQILUtOsgAg48ulkPfzUQU0c3w8oON4acP/
0gn/pSDyeUb+I9I2+ht8ekbhD9tXBEJGsY31tALqDmS7VqKt9Folvg==
-----END RSA PRIVATE KEY-----

$ cat test.enc
T+KOs8MMBNDmEiwiSqBIJWMucotbAGFhW1/kBZoRBT9uM3yOQs10xuqCm2Jo
EG5YU70lLTEQmuLgHJkW4P6fkX2E/63aFlSpy8A4Nli1ou1VKI2BLmGYH6N9
S/DrP7qySg/o9cH4wiBAbIuNoQmpTxeOyC9/r3+XbFO24+guNK+S3ytxB8rT
ADtLDK6PhL/BzagWfxydt6kQAIHGiCnVnunmYUwLataqDNdyZI0vBebiwaZ9
oW206JEk/S2WznKw6BReeTqB5CNwDxWdrMLSx/j5yk7W4faM8DdPwXbfT1RI
jKdrOlwFyWUbmlLGbZgJjVT9RoUzlMCezaWupJVHmQ==

How to decrypt the encrypted string by private key with public key?

I met a problem when I use the public key to decrypt the encrypted data by private key. However, there will be an exception when I use jsencrypt's decryption method directry, like following:
var decrypt = new JSEncrypt();
decrypt.setPublicKey(publicKey);
var decoded = decrypt.decrypt(encoded);

Furthermore, how to split the encrypted data into parts in decryption with private key while the data is too long?
Thank you for anyone can help me!

Issue with encrypting with a particular Public Key.

When I use the key mention in the below then output on the encrypt function is false.
Is there anything wrong with the public key?

var encryptor = new JSEncrypt()
encryptor.setPublicKey( key )
encryptor.encrypt('Hello World!')  // -> returns false

-----BEGIN RSA PUBLIC KEY-----
MIICCgKCAgEAsfvDzLf4oH9q3lPsIoahV7VO0hj2J7nEbB0OcRoxA0UpsMpBjIit
tskK4jIgZ/gVdf2zCOTiw9BWuOPr+CymCTl7785JSVmXi+FVLrN3nXYbo7sqkusb
DmrvRMTenx8M/f7zMiAS9iUF+jkFNg5MDkw4xiXFzgS7SYBVyRKIkVLte3JRjCPJ
vAgj3ddvet3FTylX09xrXemXEKXixLyrZrKMhrn/IQ/C0cbC6afrWI0XeBMTvxxp
ce88hxFM9d2LjCLa1MGs2eIDGVa+lOTZlu4OP8lZ7YCIYo2amNQg4511Lqqhgsqg
dYuvCnw9O41KyX7v2lzxVyLFDquhAuVG5zngWArvYCqnRNJMUZl/MYLYGo1ioh1L
lslfYZBxV5k4D8lfsK92GSzY4zQ/LfPRdRHQ3rVJ9YTp0q4mzgIe0OShCK71FcN2
8o/rrp4Pg2DcqTLDUeCDAfJchMJzbJ3ZbjB6zt0lYXqIt/iDMHbHlKKtKqoed1El
gG3Jz969vw1RDKFJJg2DKHlZobLxLbFmS/iQ686l+iTC0D/RraKrp2v4H3YRpap/
uYnfkpIqONDC1ULxCzFot2iHsDUFhL2wDaCgBYME1tzr8Klk4aQs+zFiILUduzJO
SB1tgxprKg8fwO5zv3tRJs8QDf74Z1QkgTVCG5P60YHsj5DCPEWsyO8CAwEAAQ==
-----END RSA PUBLIC KEY-----

JS Console

encryptor: l
   default_key_size: 1024
   default_public_exponent: "010001"
   key: H
     coeff: null
     d: null
     dmp1: null
     dmq1: null
     e: 0    <------------- This seems to be culprit
     n: null
     p: null
     q: null

Tests on ProjectPage fail

When I refresh the page a couple of times suddenly the shown test fails:
image

Error: global leaks detected: count, v
    at Runner.checkGlobals (http://travistidwell.com/jsencrypt/test/mocha.js:4308:21)
    at Runner.<anonymous> (http://travistidwell.com/jsencrypt/test/mocha.js:4186:44)
    at Runner.EventEmitter.emit (http://travistidwell.com/jsencrypt/test/mocha.js:521:20)
    at http://travistidwell.com/jsencrypt/test/mocha.js:4545:14
    at Test.Runnable.run (http://travistidwell.com/jsencrypt/test/mocha.js:4121:5)
    at Runner.runTest (http://travistidwell.com/jsencrypt/test/mocha.js:4488:10)
    at http://travistidwell.com/jsencrypt/test/mocha.js:4534:12
    at next (http://travistidwell.com/jsencrypt/test/mocha.js:4414:14)
    at http://travistidwell.com/jsencrypt/test/mocha.js:4423:7
    at next (http://travistidwell.com/jsencrypt/test/mocha.js:4367:23)

I'm using google chrome Version 36.0.1985.84 beta-m on Win7 x64

Decryption of specific messages is failing

Hello, first of all great library!

The issue I have is that specific messages cannot be decrypted after encryption. Here is an example:
"дф явеявасяв ф фаф яв ас асдгхй яв цжбзь я хйклт лсорив ала ас зь асдяв асявасдфе явер явсд асфяв"

This is cyrillic alphabet. I tested this isolated here http://travistidwell.com/jsencrypt/demo/ so that I am sure that I am not doing something wrong.

Java - Javascript implementation incompatibility. Possible JS bug parsing the private key

The following example does not work.... I am generating my keys in Java as per this example http://www.txedo.me/blog/java-generate-rsa-keys-write-pem-file/ or even with my own implementation in Java.

I am working on a project that will depend on the exchange of public keys from client to server and my back end is written in java. It seems like there may be a bug in this js library. If the bug is in the js library I would point it to the shared library you are using as the same example will not work for these guys either https://kjur.github.io/jsrsasign/

Seems like a deeper problem needs to be identified. When I debugged it in chrome I noticed an issue parsing the private key, as this condition is not met by the private key: "if (asn1.sub.length === 9) {"

Please see the RSAKey.prototype.parseKey method.

-----BEGIN RSA PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJLORhDfV6VwpZCF
0ZgCKc7cP3Sy5EFkkHY1LKDNqhYmU+ey7GzNjJbm/JIZQwtufcpP8K14kEq2rHo/
F2hN5DQ0hRpSAXljxuz0Y0l5DeELQYrYjcjFMOU5071ebBNuCxm7x3hqSXt/LlmW
GBo73rf3cksI5sxlKEvr69fl4vUJAgMBAAECgYBViTxHzmn56hV9jIrff7suXSPX
8feOpnKJfVgAZXSJrVFL+fNJPcaBkhptYayvt3QxcbxwxoOEFMWQALy5uFCSuWk8
WOiUVlVoCZUjW1fn6z3N0WiuW0yJH315yYjHunFI9THaToIT8XXANZPMS6Jw84Qy
EmNKF6DgirYKvmEyAQJBAORadaff+2yh9r8r25SIIujQpogYMB+JbyAtfSwHMPIC
ZWC137ah1hYj82KutL0yQ9r/6iM+/lY9a5W6SvpWpkECQQCklFfjFxlQ13VrkrGp
h8duqbWm0BdX32lqaTNPscDaz60GWw7LPNhb0LY2mlTP1iSgWdt3VCWKvowHA1Qh
92zJAkANxEJZl5BB0VXd2pgHUVnBbWrMw6CLFi8D4posQFa8EFbqSKyvBvywIwS2
S1AMI+6hUlJcQ5zzuAo3YZ7JjtXBAkARrd3DBzgw9vQmGhv7mhpSSOi6gp//UICC
bcqVRQLyflyX0jBEpMSZGFJ6ixmROe+1SfHJX8Cops9j8XeYLnwBAkEAqxZUZ4NB
kfTwjtxIsZhwaBHKPduFPg+kSKCvTwqpn87D2E0jk/dL4oFk3/otj4L1j1aelFb8
hmciN50QAVL2Bg==
-----END RSA PRIVATE KEY-----

-----BEGIN RSA PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSzkYQ31elcKWQhdGYAinO3D90
suRBZJB2NSygzaoWJlPnsuxszYyW5vySGUMLbn3KT/CteJBKtqx6PxdoTeQ0NIUa
UgF5Y8bs9GNJeQ3hC0GK2I3IxTDlOdO9XmwTbgsZu8d4akl7fy5ZlhgaO96393JL
CObMZShL6+vX5eL1CQIDAQAB
-----END RSA PUBLIC KEY-----

Issues when JSEncrypt wrapped in a function

Is there some kind of bizzare bug where this does not operate properly in a function?

I ran a lot of tests to play with saving the vars to use later, and everything works unless i stick it inside a very simple function.

when its wrapped in a function, the only encryption that works is when you initialize and simply setup the keys and use those, not if you changed the assigned key.

(i am a skilled PHP developer and a novice JS developer please forgive me if I've just done something stupid)

ugh

works

import jsencrypt.js in a web worker

Hello,
It would be great to have the possibility to import the library inside a web worker.
I know you have already discussed about it, two years ago (#31, #23 and #2). I write you just to know if there is any update on it.
thank you.

ajax issue

I have an issue when using ajax with the jsencrypt. It encode but I gets random whitespace. Then when I insert it into my database it adds + in the whitespace. The end result when I try to decode I get null error because it can't decode it correctly. I've tried to trim and replace whitespace to fix the issue but with no luck. If you could help me resolve this issue that would be great. Thanks

Not showing up as a global object in console

I'm loading the library into my application through webpack which means it gets bundled up with multiple other libraries I'm using. Anyways when I go to my console and lookup JSEncrypt nothing shows up. If anyone has done something similiar or if I'm missing something please let me know.

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.