Pergunta

Is it possible to encrypt a message with a public key in PHP, then decrypt it with the private key in JS?

I've found a few different RSA encryption scripts for PHP and jQuery, but none of them seem to work both ways. Maybe i'm going about it all wrong, but basically i'm starting with: phpseclib-jsbn-rsa (https://github.com/mvhaen/phpseclib-jsbn-rsa) and i'm trying to reverse the process.

After a few searches I came accross this guy who seems to be trying to do the same thing: phpseclib/jsbn: encrypt with public key in PHP, decrypt with private key in jsbn .. But i've tried that code a few different ways and I can't get it to work.

I know that there are ways that I could achieve nearly the same thing using AES by just sharing a client generated key with the server through RSA. But is it possible to do what i'm trying to do?

Foi útil?

Solução

If you want someone to be able to copy / paste ciphertext the ciphertext probably ought to be either base64 encoded or maybe hex encoded (ie. so "\0" is "00", etc)

Aside from that just replace all instances of encrypt with decrypt and vice versa and I'd expect you'd be good to go.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top