Gathering detailed insights and metrics for nodejs-jsencrypt
Gathering detailed insights and metrics for nodejs-jsencrypt
Gathering detailed insights and metrics for nodejs-jsencrypt
Gathering detailed insights and metrics for nodejs-jsencrypt
A zero-dependency Javascript library to perform OpenSSL RSA Encryption, Decryption, and Key Generation.
npm install nodejs-jsencrypt
Typescript
Module System
Node Version
NPM Version
JavaScript (75.34%)
TypeScript (23.3%)
HTML (0.89%)
CSS (0.43%)
Shell (0.03%)
Ruby (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
6,750 Stars
248 Commits
2,020 Forks
176 Watchers
8 Branches
29 Contributors
Updated on Jul 11, 2025
Latest Version
3.0.0-rc.1
Package Id
nodejs-jsencrypt@3.0.0-rc.1
Unpacked Size
634.34 kB
Size
138.17 kB
File Count
20
NPM Version
6.13.4
Node Version
10.6.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
http://travistidwell.com/jsencrypt
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.
This library should work hand-in-hand with openssl. With that said, here is how to use this library.
openssl genrsa -out rsa_1024_priv.pem 1024
cat rsa_1024_priv.pem
openssl rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem
cat rsa_1024_pub.pem
1<!doctype html> 2<html> 3 <head> 4 <title>JavaScript RSA Encryption</title> 5 <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> 6 <script src="bin/jsencrypt.min.js"></script> 7 <script type="text/javascript"> 8 9 // Call this code when the page is done loading. 10 $(function() { 11 12 // Run a quick encryption/decryption when they click. 13 $('#testme').click(function() { 14 15 // Encrypt with the public key... 16 var encrypt = new JSEncrypt(); 17 encrypt.setPublicKey($('#pubkey').val()); 18 var encrypted = encrypt.encrypt($('#input').val()); 19 20 // Decrypt with the private key... 21 var decrypt = new JSEncrypt(); 22 decrypt.setPrivateKey($('#privkey').val()); 23 var uncrypted = decrypt.decrypt(encrypted); 24 25 // Now a simple check to see if the round-trip worked. 26 if (uncrypted == $('#input').val()) { 27 alert('It works!!!'); 28 } 29 else { 30 alert('Something went wrong....'); 31 } 32 }); 33 }); 34 </script> 35 </head> 36 <body> 37 <label for="privkey">Private Key</label><br/> 38 <textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY----- 39MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ 40WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR 41aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB 42AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv 43xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH 44m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd 458XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF 46z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5 47rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM 48V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe 49aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil 50psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz 51uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876 52-----END RSA PRIVATE KEY-----</textarea><br/> 53 <label for="pubkey">Public Key</label><br/> 54 <textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY----- 55MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN 56FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76 57xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4 58gwQco1KRMDSmXSMkDwIDAQAB 59-----END PUBLIC KEY-----</textarea><br/> 60 <label for="input">Text to encrypt:</label><br/> 61 <textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/> 62 <input id="testme" type="button" value="Test Me!!!" /><br/> 63 </body> 64</html>
Look at how http://www.travistidwell.com/jsencrypt/example.html works to get a better idea.
Signing and verification works in a similar way.
1// Sign with the private key... 2var sign = new JSEncrypt(); 3sign.setPrivateKey($('#privkey').val()); 4var signature = sign.sign($('#input').val(), CryptoJS.SHA256, "sha256"); 5 6// Verify with the public key... 7var verify = new JSEncrypt(); 8verify.setPublicKey($('#pubkey').val()); 9var verified = verify.verify($('#input').val(), signature, CryptoJS.SHA256); 10 11// Now a simple check to see if the round-trip worked. 12if (verified) { 13 alert('It works!!!'); 14} 15else { 16 alert('Something went wrong....'); 17}
sign
method. Possible values are: md2
, md5
, sha1
, sha224
, sha256
, sha384
, sha512
, ripemd160
.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.
-----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
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/14 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
34 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More