Setting Encryption Options
When you encrypt a database, the encryption is performed by calling into a Cryptographic Service Provider (CSP) that is registered by Windows. The CSP uses a specified encryption algorithm and key length to encrypt the specified data. For additional information about database encryption.
By default, Access uses Microsoft Base Cryptographic Provider v1.0 for database encryption. The default encryption algorithm is RC4.
These options can be changed in DAO by executing the SetOption method of the DBEngine object. The three option values for database encryption are:
Option Value | Description |
---|---|
dbPasswordEncryptionAlgorithm | Used to change the encryption algorithm. Access only supports stream ciphers such as "RC4." |
dbPasswordEncryptionKeyLength | Key length for the encryption algorithm. Set to 0 to use the default key length for the algorithm as defined by the CSP. |
dbPasswordEncryptionProvider | Changes the Cryptographic Service Provider (CSP). Valid CSP names can be found in the registry. |
SetOption changes settings for the current session in Access. When Access is closed, the database engine reverts to the default settings. SetOption does not affect the database that is currently open. Instead, the setting is reflected after calling another method on DBEngine.
The following code demonstrates how to change the CSP and encrypt the current database by setting the database password:
Sub SetPasswordAndCSP(strOldPassword As String, strNewPassword As String) Dim dbs As DAO.Database 'Get the current database Set dbs = CurrentDb 'Change the CSP DBEngine.SetOption dbPasswordEncryptionProvider, _ x"Microsoft Enhanced RSA and AES Cryptographic Provider" 'Now, set the password dbs.NewPassword strOldPassword, strNewPassword 'You could also choose to compact a database or 'create a new database once the CSP was set 'Cleanup Set dbs = Nothing End Sub
You receive a runtime error if you set the dbPasswordEncryptionProvider value to an invalid CSP name. The error is displayed when you execute either the NewPassword, CompactDatabase, or CreateDatabase method. The SetOption method does not display any errors.
In this tutorial:
- Using DAO to Access Data
- Data Access Objects
- New Features in DAO
- Referring to DAO Objects
- The DBEngine Object
- Using Transactions
- The Errors Collection
- The Databases Collection
- The CurrentDb() Function
- Opening an External Database
- Closing and Destroying Database Object References
- DAO Property Types
- Setting and Retrieving Built-In Object Properties
- Setting and Retrieving SummaryInfo Properties
- Creating Schema Objects with DAO
- Creating Indexes
- Creating Relations
- Creating Multi-Value Lookup Fields
- Database Encryption with DAO
- Setting Encryption Options
- Managing Access (JET) Security with DAO
- Creating Security Objects
- Creating and Deleting Groups
- Managing Passwords
- Data Access with DAO
- Modifying a QueryDef
- Filtering and Ordering Recordsets
- Navigating Recordsets
- BOF, EOF
- Navigating Recordsets with Multi-Value Lookup Fields
- Bookmarks and Recordset Clones
- Finding Records
- Working with Recordsets
- Using Arrays with Recordsets
- Working with Attachment Fields
- Append Only Fields