This content has been marked as final. Show 1 reply
We had a bug related to encrypting database when using the C# API, bug #18891, but that was fixed in 5.2 (see the entry in the 5.2 change log)
+Fixed a bug where encryption could not be enabled for individual databases in an encrypted environment. [#18891]+
, hence the fix is part of Berkeley DB 5.3.21.
You haven't posted a complete stack trace or a small stand-alone testcase, so I cannot know exactly what is the problem.
But, here are the rules around using encryption:
A. When the database is part of an environment
- you will need to specify the encryption password and encryption algorithm using the DatabaseEnvironmentConfig.SetEncryption() method
- if you want a database in the environment to be encrypted (using the password and algorithm specified for the environment), you will need to set the DatabaseConfig.Encrypted property to true
- note that it is an error to try to set an encryption password/algorithm using the DatabaseConfig.SetEncryption() method for a database that is part of an environment, because the database will use the encryption password/algorithm specified for the environment
- here is a snippet of code showing how to correctly encrypt a database that is part of an environment:
B. When the database is NOT part of an environment
DatabaseEnvironmentConfig envCfg; envCfg = new DatabaseEnvironmentConfig(); envCfg.Create = true; envCfg.UseMPool = true; envCfg.SetEncryption("123456789", EncryptionAlgorithm.DEFAULT); ... env = DatabaseEnvironment.Open(envHome, envCfg); ... BTreeDatabaseConfig btreeCfg = new BTreeDatabaseConfig(); btreeCfg.Creation = CreatePolicy.IF_NEEDED; btreeCfg.Env = env; btreeCfg.Encrypted = true; ... db = BTreeDatabase.Open(dbName, btreeCfg); ...
This should clarify things. If not or you have additional questions let me know.
BTreeDatabaseConfig btreeCfg2 = new BTreeDatabaseConfig(); btreeCfg2.Creation = CreatePolicy.IF_NEEDED; btreeCfg2.Encrypted = true; btreeCfg2.SetEncryption("123456789", EncryptionAlgorithm.DEFAULT); ... db2 = BTreeDatabase.Open(db2Name, btreeCfg2);