phpseclib / phpseclib

PHP Secure Communications Library
http://phpseclib.com/
MIT License
5.31k stars 886 forks source link

Recommended JS library to integrate phpseclib RSA encryption? #864

Open shaysegev opened 8 years ago

shaysegev commented 8 years ago

Hello,

I'm using jsencrypt library to encrypt the messages in client and sending it to the server, though whenever I try to decode it, it always brings a 'Decryption error' message...

And when I encrypt the message on the server-side with the same public key and decrypt it, it works perfectly well...

So I wonder: a. What am I possibly doing wrong? b. Is there a recommended JS library that integrates well with phpseclib and makes it easier to work?

Much thanks!

terrafrost commented 8 years ago

Here's an example of a JS library being used with phpseclib:

http://www.frostjedi.com/terra/dev/rsa/index.php

The source code is here:

http://www.frostjedi.com/terra/dev/rsa/index.txt

More info:

https://area51.phpbb.com/phpBB/viewtopic.php?t=33024

As for what's wrong in your particular case... it's really hard to say without seeing any source code..

macdabby commented 8 years ago

I was also trying to do this. I tried npm-rsa (or node-rsa) using browserify. I am not getting an error when decrypting with phpseclib, but the output just returns null. I am able to decrypt the same cyphertext from the browser with the same private key. I'm wondering if this is a padding issue?

I have my code posted here: http://stackoverflow.com/questions/36222554/how-can-i-decrypt-data-created-by-npm-rsa-in-php