RSA Encryption

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

RSA Encryption

Post by devendra-m »

when I choose small values of p and q then it becomes very easy to find p and q from n. And when I choose large values of p and q then the calculation becomes so huge that even bc math cannot handle the values. Is there any simple way to implement RSA.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

I's suggest using built-in functions (mcrypt or openssl) for cryptography.
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Post by devendra-m »

But I need public key encryption method. Because I have to encrypt username and password before passing it to the server
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Can't you connect over https?

You can always use PGP too if you really need to use public key encryption.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

bc math can handle those values. I've used it to calculate values well into hundreds of hundreds of places.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

devendra-m wrote:But I need public key encryption method. Because I have to encrypt username and password before passing it to the server
isn't that supposed to be a strong suit of openssl?
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Post by devendra-m »

when i try to calculate pow(3434,45435435) the server takes too much time and apparently just hangs. In this case I am not being able to calculate large values which is a must for RSA. I have implemented RSA with small values of p and q which is obviously not secured but I am not being able to take large values like 768 bits which is secured.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

didja look at bcmath as was suggested? Are you reading any of these replies?
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Post by devendra-m »

I am reading replies but you are understanding my problem, my problem is not about calculation, my problem is bcpow(large values,large values) takes so much time that you can have a cup of coffee at that time. In that case how can I implement RSA.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

As with all large computations it is often beneficial to have the values precalculated if at all possible.
GloriousEremite
Forum Newbie
Posts: 13
Joined: Tue Aug 14, 2007 1:00 pm

Post by GloriousEremite »

If memory serves, you don't really need to calculate any huge exponentials when applying RSA because the operations are done modulo some other number. Maybe bcpowmod would do the trick? Also see http://en.wikipedia.org/wiki/Exponentiation_by_squaring
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Post by devendra-m »

thank you all for your time. My problem of calculation has been solved. I have found the algorithm which can calculate the power modulo of 1024 bits number in a minute.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

devendra-m wrote:thank you all for your time. My problem of calculation has been solved. I have found the algorithm which can calculate the power modulo of 1024 bits number in a minute.
Care to share?
Post Reply