public void TestSetEncryption()
        {
            testName = "TestSetEncryption";
            SetUpTest(true);

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.SetEncryption("key", EncryptionAlgorithm.AES);
            Assert.AreEqual("key", envConfig.EncryptionPassword);
            Assert.AreEqual(EncryptionAlgorithm.AES, envConfig.EncryptAlgorithm);
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            Assert.AreEqual(EncryptionAlgorithm.AES, env.EncryptAlgorithm);
            env.Close();
        }
        public void TestEncryption()
        {
            testName = "TestEncryption";
            SetUpTest(true);

            // Open an encrypted environment.
            DatabaseEnvironmentConfig envCfg =
                new DatabaseEnvironmentConfig();
            envCfg.Create = true;
            envCfg.UseMPool = true;
            envCfg.UseLogging = true;
            envCfg.UseTxns = true;
            envCfg.SetEncryption("bdb", EncryptionAlgorithm.AES);
            DatabaseEnvironment env =
            DatabaseEnvironment.Open(testHome, envCfg);
            Transaction txn = env.BeginTransaction();

            // Open a non-encrypted database in the environment.
            BTreeDatabaseConfig dbCfg =
                new BTreeDatabaseConfig();
            dbCfg.Creation = CreatePolicy.IF_NEEDED;
            dbCfg.Env = env;
            BTreeDatabase db1 = BTreeDatabase.Open(
                testName + "1.db", dbCfg, txn);
            Assert.IsFalse(db1.Encrypted);
            for (int i = 0; i < 10; i++)
                db1.Put(new DatabaseEntry(
                    BitConverter.GetBytes(i)),
                    new DatabaseEntry(
                    BitConverter.GetBytes(i)), txn);

            // Open an encrypted database in the environment.
            dbCfg.Encrypted = true;
            BTreeDatabase db2 = BTreeDatabase.Open(
                testName + "2.db", dbCfg, txn);
            Assert.IsTrue(db2.Encrypted);
            for (int i = 0; i < 10; i++)
            db2.Put(new DatabaseEntry(BitConverter.GetBytes(i)),
                new DatabaseEntry(BitConverter.GetBytes(i)), txn);

            // Close all.
            txn.Commit();
            db1.Close();
            db2.Close();
            env.Close();

            // Verify the environment is encrypted.
            DatabaseEnvironmentConfig verifyEnvCfg =
                new DatabaseEnvironmentConfig();
            verifyEnvCfg.Create = true;
            verifyEnvCfg.UseMPool = true;
            verifyEnvCfg.UseLogging = true;
            verifyEnvCfg.UseTxns = true;
            try {
                env = DatabaseEnvironment.Open(
                    testHome, verifyEnvCfg);
                // Do nothing
                env.Close();
                throw new TestException();
            } catch (DatabaseException) {
            }

            // Verify the non-encrypted database is not encrypted.
            BTreeDatabaseConfig verifyDbCfg =
                new BTreeDatabaseConfig();
            verifyDbCfg.Creation = CreatePolicy.IF_NEEDED;

            using (db1 = BTreeDatabase.Open(
                testHome + "/" + testName + "1.db", verifyDbCfg)) {
                for (int i = 0; i < 10; i++)
                    db1.Get(new DatabaseEntry(
                        BitConverter.GetBytes(i)));
            };

            /// Verify the encrypted database is encrypted.
            verifyDbCfg.SetEncryption(envCfg.EncryptionPassword,
                envCfg.EncryptAlgorithm);
            verifyDbCfg.Encrypted = true;
            using (db1 = BTreeDatabase.Open(
                testHome + "/" + testName + "2.db",
                verifyDbCfg)) {
                for (int i = 0; i < 10; i++)
                    db1.Get(new DatabaseEntry(
                        BitConverter.GetBytes(i)));
            };
        }