title: Is there any way to know what version of SQLCipher was a file encrypted in, programmatically in C#
body: <p>I want to open db files which can be encrypted with SQLCipher3 or SQLCipher4. Since they can be any of the two types, I cannot hardcode the version value in the connection string. Is there any way to know what version it must be opened with programmatically?
  Here is what I have so far</p>
  <pre><code>DbProviderFactory provider = DbProviderFactories.GetFactory(&quot;System.Data.SQLite&quot;);
  license = ConfigurationManager.AppSettings[&quot;license&quot;].ToString();
  using (DbConnection conn = provider.CreateConnection())
  {
      try
      {
          FileInfo[] Files = sourcePath.GetFiles(&quot;*.db&quot;);
          foreach (FileInfo file in Files)
          {
              try
              {
                  fileCorrupted = false;
                  if (Files.Length != 0)
                  {
                      string filename = file.FullName;
                      string pwd = &quot;password&quot;;
                      ((SQLiteConnection)conn).ParseViaFramework = true;
                      conn.ConnectionString = @&quot;Data Source=&quot; + filename + &quot;; Version=3;&quot;;
                      ((SQLiteConnection)conn).SetPassword(pwd);
                      conn.Open();
                      using (IDbCommand command = conn.CreateCommand())
                      {
                          command.CommandText = String.Format(&quot;PRAGMA cipher_license = '{0}';&quot;, license);
                          command.ExecuteScalar();
                      }
                      using (IDbCommand command = conn.CreateCommand())
                      {
                          command.CommandText = &quot;PRAGMA cipher_version;&quot;;
                          Console.WriteLine(&quot;Cipher version:{0}&quot;, command.ExecuteScalar());
                          command.CommandText = &quot;PRAGMA cipher_fips_status;&quot;;
                          Console.WriteLine(&quot;FIPS status:{0}&quot;, command.ExecuteScalar());
                      }
  
                      using (var command = conn.CreateCommand())
                      {
                          command.CommandText = &quot;SELECT count(*) As TableExist FROM sqlite_master WHERE name = 'TABLENAME' &quot;;
                          var reader = command.ExecuteReader(); //Line giving error
                          long TableCount = 0;
                          while (reader.Read())
                          {
                              TableCount = Convert.ToInt64(reader[&quot;TableExist&quot;]);
                          }
                          reader.Close();
                      }
                  }
              }
          }
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.ToString());
      }
  }
  
  </code></pre>
  <p>the exception message says
  <code>file is not a database file is not a database</code></p>
  <p>now i know that this file is a sqlcipher4 db and i can open it with the password
  how do i do this programmatically</p>