title: AES-256/CBC encryption with OpenSSL and decryption in C#
body: <p>I am a newbie to cryptography. My requirement is to decrypt/encrypt the text that is encrypted/decrypted using openssl. The algorithm that we are using is aes-256-cbc in the Openssl.
  So, I am trying to implement the same functionality in my application. so far after a lot of googling all i was able to do is..</p>
  
  <pre><code>private static string Encryptor(string TextToEncrypt)
  {
      //Turn the plaintext into a byte array.
      byte[] PlainTextBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToEncrypt);            
  
      //Setup the AES providor for our purposes.
      AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
  
      aesProvider.BlockSize = 128;
      aesProvider.KeySize = 256;  
      //My key and iv that i have used in openssl
      aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
      aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);  
      aesProvider.Padding = PaddingMode.PKCS7;
      aesProvider.Mode = CipherMode.CBC;
  
      ICryptoTransform cryptoTransform = aesProvider.CreateEncryptor(aesProvider.Key, aesProvider.IV);            
      byte[] EncryptedBytes = cryptoTransform.TransformFinalBlock(PlainTextBytes, 0, PlainTextBytes.Length);
      return Convert.ToBase64String(EncryptedBytes);                        
  }
  
  private static string Decryptor(string TextToDecrypt)
  {
      byte[] EncryptedBytes = Convert.FromBase64String(TextToDecrypt);
  
      //Setup the AES provider for decrypting.            
      AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
      //aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
      //aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);
      aesProvider.BlockSize = 128;
      aesProvider.KeySize = 256;  
      //My key and iv that i have used in openssl
      aesProvider.Key = System.Text.Encoding.ASCII.GetBytes(strKey);
      aesProvider.IV = System.Text.Encoding.ASCII.GetBytes(strIV);  
      aesProvider.Padding = PaddingMode.PKCS7;
      aesProvider.Mode = CipherMode.CBC;
  
  
      ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor(aesProvider.Key, aesProvider.IV);
      byte[] DecryptedBytes = cryptoTransform.TransformFinalBlock(EncryptedBytes, 0, EncryptedBytes.Length);
      return System.Text.Encoding.ASCII.GetString(DecryptedBytes);
  }
  </code></pre>
  
  <p>My openssl command is </p>
  
  <pre><code>openssl aes-256-cbc -e -nosalt -a -in  inputfile.txt -out  output.txt -k key -iv ivkey
  </code></pre>
  
  <p>My key length is 32digits and iv is 16digits</p>
  
  <p>Thnx ...</p>