Does RSA do the work right?

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

Does RSA do the work right?

Postby blagorod » Thu Aug 04, 2011 7:26 am

Hi.
I had a look at the example in RSA phpseclib.
Code: Select all
<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();

extract($rsa->createKey());
$plaintext = 'terrafrost';
$rsa->loadKey($privatekey);
$ciphertext = $rsa->encrypt($plaintext);
$rsa->loadKey($publickey);
echo $rsa->decrypt($ciphertext);
?>


As I see it encrypts with private key. But the RSA specs tells that it should be done with public key. Check it out: http://en.wikipedia.org/wiki/RSA
Any thoughts?
blagorod
Traveler
 
Posts: 6
Joined: Thu Aug 04, 2011 7:14 am

Re: Does RSA do the work right?

Postby TerraFrost » Thu Aug 04, 2011 4:34 pm

If you encrypt with the public key you decrypt with the private key and if you encrypt with the private key you decrypt with the public key.

If you're encrypting something with the private key I guess that's more analogous to signing but there are instances where you might want to do encryption too.
TerraFrost
Legendary Guard
 
Posts: 12217
Joined: Wed Dec 04, 2002 6:37 am

Re: Does RSA do the work right?

Postby robiwan » Tue Dec 13, 2011 9:10 am

I don't think you can encrypt with private key and decrypt with the public key to get an intelligible result, which is why RSA is called asymmetric, right ?

This procedure is useful for signing though.
robiwan
Traveler
 
Posts: 5
Joined: Tue Dec 13, 2011 5:30 am

Re: Does RSA do the work right?

Postby TerraFrost » Sun Dec 18, 2011 7:24 am

RSA is called asymmetric because it uses a different key for decrypting than it does for encrypting. A symmetric key encryption algorithm would have the same key - symmetry - on both sides. And yeah - in the case of RSA you can encrypt with one key and decrypt with the other.
TerraFrost
Legendary Guard
 
Posts: 12217
Joined: Wed Dec 04, 2002 6:37 am

Re: Does RSA do the work right?

Postby bantu » Wed Dec 21, 2011 12:40 pm

Jim, the problem here is that the example for encrypting/decrypting with RSA at http://phpseclib.sourceforge.net/docume ... a_examples seems to use $privatekey for encryption and $publickey for decrypting. This confuses people and is probably not what you wanted to write there. I would suggest to swap the two parameters.
bantu
Traveler
 
Posts: 14
Joined: Wed Nov 02, 2011 3:59 pm

Re: Does RSA do the work right?

Postby bantu » Sun Jan 15, 2012 11:01 am

Bump.
bantu
Traveler
 
Posts: 14
Joined: Wed Nov 02, 2011 3:59 pm

Re: Does RSA do the work right?

Postby TerraFrost » Thu Jan 19, 2012 1:59 pm

It's been updated - thanks!
TerraFrost
Legendary Guard
 
Posts: 12217
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 0 guests

cron