简体   繁体   中英

File RSA Decryption

I have a RSA Encrypted file & I want to decrypt it with C# in .NET

I have the foll. parameters of (1024 bit enc) message(cipher text) to decrypt

  • modulus
  • public exponent
  • private exponent
  • prime p
  • prime q
  • prime exponent p
  • prime exponent q
  • CRT coefficient

The cipher text is in HEX format

I know the CRT method to decrypt the message but not clear on how to use it

m1 = (ciphertext ^ dP) Mod P
m2 = (ciphertext ^ dQ) Mod Q
h = (qInv * (m1 - m2)) Mod P
m = m2 + (h * Q)

I tried performing the decryption using foll namespace

System.Security.Cryptography

can someone help me with a sample code to achieve decryption, as this is my first time to deal with Decryption.

Is there any ready API available? in which I just need to pass the parameters & I will receive the desired output.

Yes, you may use the System.Security.Cryptography namespace. MSDN Reference For some examples just dig a little deeper in to the MSDN library . For example, there are examples for the RSACryptoServiceProvider here.

First create an RSAParameters structure and fill it with your own RSA parameters. Next create an RSACryptoServiceProvider instance and call ImportParameters on your previously defined parameters. At that point you should be able to call Decrypt on your data with (or without) using the OAEP padding.

So something like:

RSAParameters p = new RSAParameters ();
p.D = d;
// ... all parameters
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider ();
rsa.ImportParameters (p);
byte[] decrypted = rsa.Decrypt (encrypted, false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM