I am creating a little software to encrypt and decrypt data using asymmetric keys.
The problem is, I am coding in C# and even if I use :
BigInteger.Pow(BigIntenger myNumber, int myExponent);
The exponent is an "int" and my value is to big for an int.
Just to quickly explain and to be sure I am not doing any mistake, you have to use big numbers to make it more difficult to decrypt without having the private key.
So I have
- N = P * Q
- P and Q are both prime numbers.
- M = (P-1)+(Q-1)
- C is a prime number with M
- Then find U with : C×U+M×V=1
Public key (N,C).
Private key (U,N).
For example you want to encrypt : "Bonjour !" to UTF8.
You will have :
B⇔66 / o⇔111 / n⇔110 / j⇔106 / o⇔111 / u⇔117 / r⇔114 / (espace)⇔32 / !⇔33
Then raise each numbers to the power of C and modulo N.
Ex : valueOfB = (66^C)%N.
Now your message is encrypted.
If you want to decrypt it, you have to multiply each value by exponent U and modulo N.
Ex : (valueOfB^U)%N
So I can do this only if I use small number because I will have a small U value that fit with a "int" but it's not secure, how can I do this with a big U like BigInteger and not int ?