Closed
Description
I met a problem when I use the public key to decrypt the encrypted data by private key. However, there will be an exception when I use jsencrypt's decryption method directry, like following:
var decrypt = new JSEncrypt();
decrypt.setPublicKey(publicKey);
var decoded = decrypt.decrypt(encoded);
Furthermore, how to split the encrypted data into parts in decryption with private key while the data is too long?
Thank you for anyone can help me!
Activity
jokerlin commentedon Apr 25, 2016
I have the same problem.
axellettieri commentedon Apr 29, 2016
Hello,
From the official page (http://travistidwell.com/jsencrypt/):
[...] crypt.setKey(YOUR_OPENSSL_PRIVATE_OR_PUBLIC_KEY); //You can use also setPrivateKey and setPublicKey, they are both alias to setKey
//Eventhough the methods are called setPublicKey and setPrivateKey, remember
//that they are only alias to setKey, so you can pass them both a private or
//a public openssl key, just remember that setting a public key allows you to only encrypt [...]
It has sense, because decrypt with the public key would make anyone allowed to decrypt.
jokerlin commentedon Apr 29, 2016
Yeah, but I need to decrypt the encrypted string by private key with public key to achieve digital signature.
zsxsoft commentedon Aug 5, 2016
I've found the solution, but I'm not sure whether it's correct all the times, because I didn't read any document about RSA yet. It's just a trick. So I'll not PR until anyone tell me what did I do.
My changes:
zsxsoft-deprecated@6b1a3a6
By the way, I transplanted it to Classic ASP. How poor I am, holy ****! =.=....
Chaunjie commentedon Aug 25, 2016
did you solved it?I have the same problem
Chaunjie commentedon Aug 25, 2016
@XXMY did you solved it?
XXMY commentedon Aug 25, 2016
@xudao520 I haven't study this problem for months, and gave it up, sorry for your inconvenience.
Chaunjie commentedon Aug 26, 2016
@XXMY I have solved this problem ,client take serve_publicKey, client_privateKey and serve take client_publicKey , serve_privateKey . so client encrypt data with serve_publicKey ,server decrypt with serve_privateKey and server encrypt data with client_publicKey ,client decrypt with client_privateKey
XXMY commentedon Aug 26, 2016
@xudao520
Two RSA key pairs, clearly you use public key to encrypt and use private key to decrypt, it not solves the problem. What I posted is how to use public to decrypt.
Sure, you enabled client to decrypt data, it is a new method, although sounds a bit complex.
Chaunjie commentedon Aug 26, 2016
sorry, I'm not in line with your request.
zsxsoft commentedon Aug 26, 2016
OK, did anyone had read my reply? My changes made a trick but solved the problem.
Get Outlook for Android
On Fri, Aug 26, 2016 at 11:12 AM +0800, "Fangwei Cai" notifications@github.com wrote:
@xudao520
Two RSA key pairs, clearly you use public key to encrypt and use private key to decrypt, it not solves the problem. The problem I posted is how to use public to decrypt.
Sure, you enable client to decrypt data, it is a new method, although sounds a bit complex.
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#70 (comment)
XXMY commentedon Aug 26, 2016
@zsxsoft
I included your modified file, just jsencrypt.js into my script, but it works fine in public key encrypt and private key decrypt. While use private key to encrypt and public key to decrypt, the decryption result is null
my script is:
var publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALpJXQXmlFbJo78DhqUcKNGkXna5bEqBxtQ4bg4NgTTK+udPm6fEynonLY7BRucAee9cOw49vsddDeGCcvhoY8kCAwEAAQ==";
var privateKey = "MIIBOQIBAAJBALpJXQXmlFbJo78DhqUcKNGkXna5bEqBxtQ4bg4NgTTK+udPm6fEynonLY7BRucAee9cOw49vsddDeGCcvhoY8kCAwEAAQJARdVqweOGiGJeuCSiPRMpWi28G9W2+tdbqgLdfvchEKDDCuxDY5ZZ1eLTJtFx1jJNoBWarks8WCnM4tlt0rqgAQIhAOkBQFYkZd5mUC16HkDIx4oBflvdCx6lbRhQX5GkaoWBAiEAzKvMRG5Yh8AuRJX24LFk1A/YF1Yl7V9PWrfVQ7vFUkkCIAh6vC2mW3KxhH9zL0CqTeCu1ztemvX9jS/SVPgG5L2BAiB2TtxttgdQuSNFnBYv/frVpi74FmEoHE7nlpodZB4EmQIgUEnhwSLlEFHjwhjbE8S2VoIElmUKV83mak5rOrs8LBw=";
var encrypt = new JSEncrypt();
var decrypt = new JSEncrypt();
encrypt.setPublicKey(publicKey);
decrypt.setPrivateKey(privateKey);
//encrypt.setPrivateKey(publicKey);
//decrypt.setPublicKey(privateKey);
var content = "abcdefg";
console.log("Content: " + content);
var encoded = encrypt.encrypt(content);
console.log("Encoded: " + encoded);
var decoded = decrypt.decrypt(encoded);
console.log("Decoded: " + decoded);
zsxsoft commentedon Aug 26, 2016
@XXMY

Are you sure your
jsencrypt.js
is correct? I tested in Internet Explorer 6 & Chrome 54.XXMY commentedon Aug 26, 2016
@zsxsoft

I'm sure the
jsencrypt.js
I used is correct.The script you tested is use public key to encrypt and use private key to decrypt, and I said it is fine.
You said you have solved the problem, so I try to use private key to encrypt data and use public key to decrypt, but failed.

zsxsoft commentedon Aug 26, 2016
@XXMY
I re-test it with PHP, passed.
index.html:
PHP Code:
41 remaining items