当前位置: 首页>>代码示例>>C#>>正文


C# BTreeDatabaseConfig.SetEncryption方法代码示例

本文整理汇总了C#中BerkeleyDB.BTreeDatabaseConfig.SetEncryption方法的典型用法代码示例。如果您正苦于以下问题:C# BTreeDatabaseConfig.SetEncryption方法的具体用法?C# BTreeDatabaseConfig.SetEncryption怎么用?C# BTreeDatabaseConfig.SetEncryption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BerkeleyDB.BTreeDatabaseConfig的用法示例。


在下文中一共展示了BTreeDatabaseConfig.SetEncryption方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestEncryption

        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)));
            };
        }
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:86,代码来源:DatabaseEnvironmentTest.cs

示例2: TestEncryption

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

            BTreeDatabase db1;

            BTreeDatabaseConfig dbCfg =
                new BTreeDatabaseConfig();
            dbCfg.Creation = CreatePolicy.IF_NEEDED;

            // Open an encrypted database.
            dbCfg.SetEncryption("bdb", EncryptionAlgorithm.AES);
            using (db1 = BTreeDatabase.Open(
                testHome + "/" + testName + ".db", dbCfg)) {
                Assert.IsTrue(db1.Encrypted);
                for (int i = 0; i < 10; i++)
                    db1.Put(new DatabaseEntry
                        (BitConverter.GetBytes(i)),
                        new DatabaseEntry(
                        BitConverter.GetBytes(i)));
            }

            // Verify the database is encrypted.
            BTreeDatabaseConfig verifyDbCfg =
                new BTreeDatabaseConfig();
            verifyDbCfg.Creation = CreatePolicy.IF_NEEDED;
            verifyDbCfg.SetEncryption(
                dbCfg.EncryptionPassword,
                dbCfg.EncryptAlgorithm);
            verifyDbCfg.Encrypted = true;
            using (db1 = BTreeDatabase.Open(
                testHome + "/" + testName + ".db",
                verifyDbCfg)) {
                for (int i = 0; i < 10; i++)
                    db1.Get(new DatabaseEntry(
                        BitConverter.GetBytes(i)));
            };
        }
开发者ID:hyc,项目名称:BerkeleyDB,代码行数:39,代码来源:BTreeDatabaseTest.cs


注:本文中的BerkeleyDB.BTreeDatabaseConfig.SetEncryption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。