Thabo
Thabo

Reputation: 1554

Purpose of RijndaelManaged instance?

I have Found following Code Sample on MSDN when i was searching for RSACypthyServiceProvider.I couldn't understand some part of thecode with the help of comment.

  1. What is modulus and Exponent ?

  2. What is IV?

  3. Why they are using RijndaelManagedclass to do asymmetric encryption? Based on my search RSACryptoServiceProvider provides Asymmetric encryption functionality and it will automatically creates Private and Public key when we create the object .So What is the Purpose of RijndaelManaged instance here?

Can any one please explain?

Code Sample:

class Class1
{

   static void Main()
   {

     //Initialize the byte arrays to the public key information.
      byte[] PublicKey = {Somethink in byte}

      byte[] Exponent = {1,0,1};

      //Create values to store encrypted symmetric keys.
      byte[] EncryptedSymmetricKey;
      byte[] EncryptedSymmetricIV;

      //Create a new instance of the RSACryptoServiceProvider class.
      RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

      //Create a new instance of the RSAParameters structure.
      RSAParameters RSAKeyInfo = new RSAParameters();

      //Set RSAKeyInfo to the public key values. 
      RSAKeyInfo.Modulus = PublicKey;
      RSAKeyInfo.Exponent = Exponent;

      //Import key parameters into RSA.
      RSA.ImportParameters(RSAKeyInfo);

      //Create a new instance of the RijndaelManaged class.
      RijndaelManaged RM = new RijndaelManaged();

      //Encrypt the symmetric key and IV.
      EncryptedSymmetricKey = RSA.Encrypt(RM.Key, false);
      EncryptedSymmetricIV = RSA.Encrypt(RM.IV, false);
    }
}

Upvotes: 2

Views: 608

Answers (1)

CodesInChaos
CodesInChaos

Reputation: 108840

RSA is very slow, and has overhead for padding. So it's common to generate a random symmetric key, encrypt it with RSA, and encrypt the message with the symmetric key. This approach is known as hybrid cryptosystem.

IVs are important if a single key is used to encrypt multiple messages, but since this code creates a new key for each message, the IV isn't really important here. Still using an IV can prevent multi-target attacks, so it's not completely useless with unique keys, especially if the key only has 128 bits.

This code is pretty inefficient too: It encrypts IV and key separately, instead of concatenating them. This doubles the RSA overhead.

Modulus and exponent are the two parts of an RSA public key. Look up wikipedia for details. The exponent is often chosen to be 2^16 + 1 = 65537, which corresponds to the {1,0,1} in this code.

Upvotes: 1

Related Questions