Web Based RSA Key Generator JavaScript public private key system share the public key but only the private key can decode the message style body min height 800px style script src https ajax googleapis com ajax libs jquery 1 10 2 jquery min js script script type text javascript src https cdnjs cloudflare com ajax libs jsencrypt 3 2 1 jsencrypt min js script hr button id generate Generate New Keys button span class input group addon Key Size span select id keysize option value 512 selected 512 option option value 1024 1024 option option value 2048 2048 option option value 4096 4096 option select div label for privkey Private Key label br textarea id privkey rows 15 style width 100 font size 80 textarea div div label for pubkey Public Key label br textarea id pubkey rows 15 style width 100 font size 80 readonly readonly textarea div hr h3 RSA Encryption Test h3 div style text align center vertical align top width 100 span style display inline block width 40 label for input Text to encrypt label br textarea id input name input style width 100 rows 6 This is a test textarea span span style display inline block width 19 button id execute class btn btn primary Encrypt Decrypt button span span style display inline block width 40 label for crypted Encrypted label br textarea id crypted name crypted style width 100 rows 6 textarea span div script window onload function keysize change function var end this value console log keysize end var firstDropVal pick val generateKeys Change the key size value for new keys change key size each function index value var el value var keySize el attr data value el click function e var button key size button attr data value keySize button html keySize bit span class caret span e preventDefault Execute when they click the button execute click function Create the encryption object var crypt new JSEncrypt Set the private crypt setPrivateKey privkey val return If no public key is set then set it here var pubkey pubkey val if pubkey pubkey val crypt getPublicKey Get the input and crypted values var input input val var crypted crypted val Alternate the values if input crypted val crypt encrypt input input val else if crypted var decrypted crypt decrypt crypted if decrypted decrypted Failed input val decrypted crypted val var generateKeys function var keySize keysize option selected val console log keySize keySize var crypt new JSEncrypt default_key_size keySize var async async ck is checked var dt new Date var time dt getTime if async time report text var load setInterval function var text time report text time report text text 500 crypt getKey function clearInterval load dt new Date time dt getTime time report text Generated in time ms privkey val crypt getPrivateKey pubkey val crypt getPublicKey return crypt getKey dt new Date time dt getTime time report text Generated in time ms privkey val crypt getPrivateKey pubkey val crypt getPublicKey If they wish to generate new keys generate click generateKeys generateKeys script
ize bit span class caret span e preventDefault Execute when they click the button execute click function Create the encryption object var crypt new JSEncrypt Set the private crypt setPrivateKey privkey val return If no public key is set then set it here var pubkey pubkey val if pubkey pubkey val crypt getPublicKey Get the input and crypted values var input input val var crypted crypted val Alternate the values if input crypted val crypt encrypt input input val else if crypted var decrypted crypt decrypt crypted if decrypted decrypted Failed input val decrypted crypted val var generateKeys function var keySize keysize option selected val console log keySize keySize var crypt new JSEncrypt default_key_size keySize var async async ck is checked var dt new Date var time dt getTime if async time report text var load setInterval function var text time report text time report text text 500 crypt getKey function clearInterval load dt new Date time dt getTime time report text Generated in time ms privkey val crypt getPrivateKey pubkey val crypt getPublicKey return crypt getKey dt new Date time dt getTime time report text Generated in time ms privkey val crypt getPrivateKey pubkey val crypt getPublicKey If they wish to generate new keys generate click generateKeys generateKeys script