tags:

views:

1534

answers:

2

I have 3 byte arrays of 128, 128, 3 bytes respectively. I don't know what it is, but I expect them to be Modulus, D, Exponent. Now how to use these arrays in C# to decrypt a byte array using RSA? When I create RSA param and assign the 3 byte arrays to Modulus, D, Exponent and try to use that RSAParameters in RSACryptoServiceProvider.ImportParameters, Decryption fails stating corrupt keys. I guess the other entries also need to be filled DQ,DP,...etc...

How do I do that in C#? I don't have that values, is there an easy way to decrypt a byte array using only Modulus, D, Exponent in C#, as in other languages?

A: 

You don't have enough when you just have Mod, D, and the exponent. (Well you might have enough) P and Q are VERY hard to calculate from the mod. I wouldn't know how to do that and there are almost certainly more primes than the right ones that multiplied end up with the same mod.

You need atleast P, Q and the public exponent.

P, Q and D are the building blocks

DP = D mod (p - 1)
DQ = D mod (q - 1)
InverseQ = Q^-1 mod p
Modulus = P * Q

so now we have 

P Q and D.

and we can calulate DP, DQ, InverseQ and Modulus and Exponent (see below)

long gcd(long a, long b)
{
    long temp;
    while (b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

Exponent = gcd(1, (P - 1)*(Q - 1));
the_ajp
A: 

Mono have some classes to do the same. BigIntegers, etc.

Priyank Bolia