title: What is the correct .Net method to decrypt an android AES encrypted file
body: <p>I have encrypted a zip file in android using this method:</p>
  
  <pre><code>String s_InitKey = "1612211310164660";
  String s_IvSpec = "MySecreteBytes00";
  
  IvParameterSpec iv = new IvParameterSpec(s_IvSpec.getBytes("UTF-8"));
  SecretKeySpec key = new SecretKeySpec(s_InitKey.getBytes("UTF-8"), "AES");
  Cipher cipher = Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE, key, iv);
  </code></pre>
  
  <p>I need to decrypt the file using windows, I have tried the following method:</p>
  
  <pre><code>    Private Sub LicenceEncryptOrDecrypt(LizenzDatei As String, EncryptOrDecrypt As String)
  
          Dim Rijndael As RijndaelManaged = New RijndaelManaged
  
          Dim passPhrase As String = "SuperPassword"
          Dim hashAlgorithm As String = "SHA1"
          Dim passwordIterations As Integer = 3
          Dim keySize As Integer = 128
  
          Dim initVector As String = "16charLongString"
          Rijndael.IV = Encoding.ASCII.GetBytes(initVector)
  
          Dim saltValue As String = "DoYouWantSomeSalt"
          Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
  
          Dim password As Rfc2898DeriveBytes = New Rfc2898DeriveBytes(passPhrase, saltValueBytes)
  
          Rijndael.Key = password.GetBytes(keySize / 8)
  
          Rijndael.Padding = PaddingMode.None
  
  
          Dim transform As ICryptoTransform
          Dim tempFile As String
  
  
          Select Case EncryptOrDecrypt
              Case "Encrypt"
                  transform = Rijndael.CreateEncryptor(Rijndael.Key, Rijndael.IV)
                  tempFile = LizenzDatei + ".enc"
              Case "Decrypt"
                  transform = Rijndael.CreateDecryptor(Rijndael.Key, Rijndael.IV)
                  tempFile = LizenzDatei + ".dec"
              Case Else
                  Debug.Print("&gt;&lt; EncryptOrDecrypt: Falshes parameter. Ende Sub.")
                  Success = False
          End Select
  
  
          Using inFS As FileStream = New FileStream(LizenzDatei, FileMode.Open)
              Dim data() As Byte = New Byte(inFS.Length - 1) {}
  
              Using outFS As FileStream = New FileStream(tempFile, FileMode.Create)
                  Using outStreamEncrypted As CryptoStream = New CryptoStream(outFS, transform, CryptoStreamMode.Write)
                      outStreamEncrypted.Write(data, 0, data.Length)
                      outStreamEncrypted.FlushFinalBlock()
                      outStreamEncrypted.Close()
                  End Using
                  outFS.Close()
              End Using
              inFS.Close()
          End Using
  
          File.Delete(LizenzDatei)
          File.Move(tempFile, LizenzDatei)
  
      End Sub
  </code></pre>
  
  <p>I am generating the zip file in android then I export it to a folder in the android sub system.  From there I copy it over to windows and it is here that I need to decrypt the file.</p>
  
  <p><strong>EDIT - Modified VB Code</strong></p>
  
  <pre><code>Private Sub LicenceEncryptOrDecrypt(EncryptedFile As SimpleFile, Direction As CryptoAction)
          Dim Rijndael As RijndaelManaged = New RijndaelManaged
  
          Dim hashAlgorithm As String = "AES"
  
          Rijndael.Padding = PaddingMode.None
  
          Dim s_Temp As String = EncryptedFile.Name.Substring(9, EncryptedFile.Name.Length - 9)
          Dim c_Date As New SimpleDate(s_Temp)
          'c_Date.getKey translates 16bit key'
          Dim Key As Byte() = System.Text.Encoding.UTF8.GetBytes(c_Date.getKey)
          Dim IV As Byte() = System.Text.Encoding.UTF8.GetBytes("MySecreteBytes00")
  
          Rijndael.IV = IV
          Rijndael.Key = Key
  
  
          Dim transform As ICryptoTransform
          Dim tempFile As String
  
  
          Select Case Direction
              Case CryptoAction.ActionEncrypt
                  transform = Rijndael.CreateEncryptor(Rijndael.Key, Rijndael.IV)
                  tempFile = EncryptedFile.FullPath
              Case CryptoAction.ActionDecrypt
                  transform = Rijndael.CreateDecryptor(Rijndael.Key, Rijndael.IV)
                  tempFile = EncryptedFile.Path + "\" + EncryptedFile.Name + ".zip""
          End Select
  
          Dim data() As Byte = System.IO.File.ReadAllBytes(EncryptedFile.FullPath)
  
          Using outFS As FileStream = New FileStream(tempFile, FileMode.Create)
              Using outStreamEncrypted As CryptoStream = New CryptoStream(outFS, transform, CryptoStreamMode.Write)
                  outStreamEncrypted.Write(data, 0, data.Length)
                  outStreamEncrypted.FlushFinalBlock()
                  outStreamEncrypted.Close()
              End Using
              outFS.Close()
          End Using
      End Sub
  </code></pre>