I have a PHP webpage, where I use OpenSSL to encrypt a text in PHP (openssl_private_decrypt).
Encripted text:
bhYtdNghwutjxqgHg8AoyebLm5AY+X/4GLNzzb0PVuyiUX2QKwwDBXH4kVQFJIqUUrm6nYGk740wWkSoAMzygA==
Public key: -----BEGIN PUBLIC KEY-----MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMYQWDqtLgDKlQvWzacGeBMQpbicd/uoXAvgLNpFZLM7zuYFDhrYncRsl8LIHK0K3f7e1aFmUVgM4LrKU2WFIw0CAwEAAQ==-----END PUBLIC KEY-----
I don't know how to decrypt it in a browser in JavaScript. I'm looking for some code or library, which I can decode it.
I have a PHP webpage, where I use OpenSSL to encrypt a text in PHP (openssl_private_decrypt).
Encripted text:
bhYtdNghwutjxqgHg8AoyebLm5AY+X/4GLNzzb0PVuyiUX2QKwwDBXH4kVQFJIqUUrm6nYGk740wWkSoAMzygA==
Public key: -----BEGIN PUBLIC KEY-----MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMYQWDqtLgDKlQvWzacGeBMQpbicd/uoXAvgLNpFZLM7zuYFDhrYncRsl8LIHK0K3f7e1aFmUVgM4LrKU2WFIw0CAwEAAQ==-----END PUBLIC KEY-----
I don't know how to decrypt it in a browser in JavaScript. I'm looking for some code or library, which I can decode it.
Share Improve this question edited Oct 16, 2019 at 6:16 4b0 22.3k30 gold badges96 silver badges143 bronze badges asked Nov 20, 2012 at 12:01 HorbertHorbert 3713 gold badges6 silver badges16 bronze badges 2- Why are you doing this manually instead of letting the browser and web server handle it automatically by using HTTPS? – Quentin Commented Nov 20, 2012 at 12:02
- check out stackoverflow./a/3977325/861940 – Bruno Commented Nov 20, 2012 at 12:06
3 Answers
Reset to default 4I found the answer:
I found an encryption algorithm in this page:
https://github./ziyan/javascript-rsa (You need the rsa.js and jsbn.js)
But it only contains the encryption algorithm, and some characters are encrypted bad.
I have written a decryption code into the js, and changed the code that makes an error in the encryption.
And you'll need the following libraries from here!
- prng4.js
- rng.js
Finally you should change the following text for this:
var RSA = {
...
}
I hope it can help somebody.
Horbert
You may want to try out forge as well -- it does RSA encryption/decryption and more. There are lots of examples on the README:
https://github./digitalbazaar/forge
What you could also use is our NoSSL, it is open-source and free for private/non-mercial use: http://www.nossl There is also an Indiegogo campaign right now: http://www.indiegogo./projects/nossl-security-for-your-website/x/6399437