本文整理汇总了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)));
};
}
示例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)));
};
}