title: Decrypt a string with C# that was originally encrypted in Foxpro
body: <p>I'm writting a .Net MVC program that has to be able to read strings that were encrypted by a Foxpro application. If I were doing the encryption and decryption from the start, no problem. I don't know what foxpro's Encrpyt and Decrypt methods are doing under the hood to know how to apply the same encrypt and decrypt methods in C#.</p>
  
  <p>Here is the call to Encrypt in foxpro.</p>
  
  <pre><code>encyptedString = ENCRYPT(saltString + unencryptedString, secretkey_aes256,2,0)
  </code></pre>
  
  <p>Here is the call to Decrypt in foxpro (second line removes the salt)</p>
  
  <pre><code>unencryptedString = DECRYPT(encryptedString, secretkey_aes256,2,0)
  unencryptedString = SUBSTR(unencryptedString, LEN(saltString) + 1)
  </code></pre>
  
  <p>I obviously know the values for the saltString and secretkey_aes256 and yes the aes256 is a clue but I don't know what the parameters 2 and 0 are doing. </p>
  
  <p>Thought someone would get a kick out of solving this riddle and maybe to them it isn't even a riddle. I've been working on it for a couple of hours and I'm just not savvy enough with encrypt and decrypt to figure it out so far. </p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>if 2 mean AES256 and 0 means ECB, any clues as to what I'm doing wrong with the code below??</p>
  
  <pre><code>public string DecryptString(string encrypted)
          {
              RijndaelManaged myAES = new RijndaelManaged();
              myAES.KeySize = 256;
              myAES.BlockSize = 256;
              myAES.Mode = CipherMode.ECB;
              myAES.Padding = PaddingMode.None;
  
              byte[] _key = ASCIIEncoding.UTF8.GetBytes(_secret);
  
              myAES.Key = _key;
  
              byte[] encrypted_bytes = ASCIIEncoding.UTF8.GetBytes(@encrypted.Trim());
  
              ICryptoTransform decrypto = myAES.CreateDecryptor();
  
              string decrypted = "";
  
              decrypted = ASCIIEncoding.UTF8.GetString(decrypto.TransformFinalBlock(encrypted_bytes, 0, encrypted.Trim().Length));
  
              return decrypted;
          }
  </code></pre>