Reputation: 31
I'm trying to decrypt using RSACryptoServiceProvider, but I only have the modulus and d pair as a private key and also the exponent.
RsaParameters struct wont make do with these. It rejects me upon decryption with an exception "Bad key".
To my understanding, this pair is enough to decrypt without the entire DQ DP INVERSEQ parts. More over, in an example I found for python with pyCrypto, it has an RSA.construct method that only takes the above parts.
Is it possible with the classes in the .NET framework or another library? I've tried with BountyCastle but had no luck.
Upvotes: 3
Views: 2437
Reputation: 42010
With the information you have, you can recover all the information your are missing and then provide the RSACryptServiceProvider with all the parameters it wants. The algorithm you need to get started is here. Look at section 8.2.2(i), "Relation to Factoring". The third paragraph, which starts out "On the other hand", proceeds to outline a simple algorithm which you can use to recover the primes p and q. From these, you can recover the other values easily. You'll need a reasonable BigInteger package.
Upvotes: 2
Reputation: 4664
it's just a little bit math ;)
k = c^d mod N
k is the plaintextmessage
c is the chiffre
d is your private key
N is your modulus
In Java it would be like this:
BigInteger c = ...
BigInteger d = ...
BigInteger n = ...
BigInteger k = c.modPow(d, n);
I hope C# has something which is equal.
Upvotes: 1
Reputation: 25601
If you can't get the .NET framework to do it, I long ago wrote a program in C++ (which you may be able to convert to C# with some effort) that manually performs RSA cryptographic transformations, and reviewing the source code, it looks like it should operate using a private key (d) without providing p and q. It's at http://sourceforge.net/projects/bmrsa/
Upvotes: 0