15,938,218 members
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.

What I have tried:

I was searching for 7 hours but no answer.
Posted
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
https://people.csail.mit.edu/rivest/Rsapaper.pdf

## Solution 1

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.

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

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!