Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

we know RSA key pair need p,q (prime numbers), and if we want to generate RSA key on 128 bit length we need to generate p and q on 128 bit length and do some math with them.

my problem is how to generate these big prime numbers and do some of operations on it( + * - )

please note I don't need to use C# cryptography classes, I want to make my own.

thanks in advance.

What I have tried:

I was searching for 7 hours but no answer.
Updated 17-Jun-20 20:02pm
George Swan 20-Jun-20 6:19am    
The original RSA paper gives a good example of how to DIY

1 solution

Why on earth would you want to do that?
"Rolling your own" with encryption is a good way to get problems later: it's a complicated field with complex code, and tiny differences can cause encrypted data to either be easily broken or corrupted beyond recovery.

But, if you must ... start here: Reference Source[^] - it's the source code that Microsoft use for RSA, and includes the code for key generation.

I'd still reccomend using the .NET Framework methods though.
Share this answer
AnasMHDAbbas 18-Jun-20 12:41pm    
thanks a lot, the main idea I need is to check the p and q (if prime or not) hence to deduce e (public key) and d (private key).. I am practicing with big numbers so I choose RSA because there is some tools to help to determinate my answer true or false.
OriginalGriff 18-Jun-20 14:14pm    
When you ask a question, always ask about what you are actually doing - asking about generating RSA keys when you are trying to crack encryption is a silly idea: you don't get the help you want.

If fact, there is no real point in helping you: a brute force hack like that will be unlikely to succeed within your lifetime - far too many values and combinations of them mean that the odds are heavily stacked against you - unless you find a fully working quantum computer of course. Just do the math, and you'll see what I mean ... remember that each prime factor is between 150 and 600 decimal digits long.

That's why RSA uses what it does: to prevent brute force attacks being in any way effective in a reasonable time frame.
I'd abandon it if I was you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900