Secure ACCESS Encryption Method

Source: Internet
Author: User
Microsoft's ACCESS database is one of our commonly used desktop data. Most small and medium-sized enterprise database management systems can use it, but its security is still worrying. Imagine a financial management system, what will happen if the user directly opens the database to change the data? Some systems may only change the ACCESS database extension or add a password,

Microsoft's ACCESS database is one of our commonly used desktop data. Most small and medium-sized enterprise database management systems can use it, but its security is still worrying. Imagine a financial management system, what will happen if the user directly opens the database to change the data? Some systems may only change the ACCESS database extension or add a password,

Microsoft's ACCESS database is one of our commonly used desktop data. Most small and medium-sized enterprise database management systems can use it, but itsSecurityNature has been worrying. Imagine what would happen if users directly open the database to change data in a financial management system? Some systems may only change the ACCESS database extension or add a password. As we all knowMethodAnd tools are mostly online! SoEncryptionThe following is a simple example.MethodTo implement ACCESS dataEncryptionFor your reference.

Open the MDB file with UltraEdit and you can see the content of the first 16 bytes of the file:

00 01 00 00 53 74 61 6E 64 61 72 64 20 4A 65 74

Now you can change a few items at will and use ACCESS to open the file. It is found that different file formats are incorrect, because the information saved before ACCESS is the definitions and passwords of some MDB files. If you change the content, it is hard for others to see the format of the database and cannot open it. In this way, the database content will not be changed and the original data will not be damaged.

The following uses Delphi as a simpleEncryptionSolution:

UsedEncryptionThe solution function is as follows:

Const
Titlestr: array [0 .. 15] of byte =
($00, $01, $00, $00, $53, $74, $61, $ 6E, $64, $61, $72, $64, $20, $ 4A, $65, $74); // the first 16 bytes of the MDB File
Titlestr2: array [0 .. 15] of byte =
($48, $ 4A, $00, $58, $55, $43, $48, $41, $ 4E, $47, $59, $ 4F, $55, $00, $20, $20); // write the first 16 bytes of the modified MDB file, such as your company name or your name.
Produce EncrypMDB (filename: string); // Replace the first 16 bytes of the MDB with the titlestr2 content for implementationEncryptionFunction
Var F: TFileStream;
Begin
If not fileExists (filename) then exit;
F: = TFileStream. create (filename, fmopenwrite );
Try
F. seek ($00, soFromBeginning );
F. Write (titlestr2, 16 );
Finally
F. free;
End;
End;
Produce uncrypMDB (filename: string); // restore the first 16 bytes of MDB
Var F: TFileStream;
Begin
If not fileExists (filename) then exit;
F: = TFileStream. create (filename, fmopenwrite );
Try
F. seek ($00, soFromBeginning );
F. Write (titlestr, 16 );
Finally
F. free;
End;
End;

We know that a locked file (. ldb file) will appear after opening the ACCESS database. Because we also need to use the database, we must restore the database during use.

If it is not restoredEncryptionYou can copy the MDB file and open it with ACCESS or other tools.EncryptionStatus to ensure dataSecurity.

Use Delphi to connect to the database using ADOMethodYou can:

// Restore data so that you can use the database
Copyfile (pchar (APP_path + 'dataaccount. db'), pchar (app_path + 'ememp. db'), false); // app_path indicates the current directory of the program, account. db is an MDB file that has changed its extension.
UncrypMDB (App_path + 'datatemp. db ');
Copyfile (pchar (App_path + 'ememp. db'), pchar (APP_path + 'dataaccount. db'), false );
Adoconn. connectionstring: = 'provider = Microsoft. Jet. OLEDB.4.0; Data Source = '+ App_path + 'dataaccount. db; Persist Security Info = false'; // adocon is a TADOConnection component
Try
Adoconn. connected: = true;
Except
MessageBox (handle, 'a fatal error occurred when opening the database !!! ', 'Error', MB_ OK + MB_ICONERROR );
End;
// Enable it immediatelyEncryption
Copyfile (pchar (APP_path + 'dataaccount. db'), pchar (app_path + 'ememp. db'), false); // app_path indicates the current directory of the program, account. db is an MDB file that has changed its extension.
EncrypMDB (App_path + 'datatemp. db ');
Copyfile (pchar (App_path + 'ememp. db'), pchar (APP_path + 'dataaccount. db'), false );
Deletefile (App_path + 'datatemp. db ');

The above two temporary files are used because there is a problem when the database is opened and then directly writes the MDB, and you cannot determine how many users have opened the program.

The entire program shares a TADOConnection and restores the MDB file only when the database connection is enabled. The MDB file remains inEncryptionStatus! It is generally difficult for users to know what an MDB file is!

After opening the database, there will be a. ldb file with ACCESS and other words for the type. If you don't want to see what it is, modify the registry, for example:

reg:=TRegistry.Create;
try
 reg.RootKey:=HKEY_CLASSES_ROOT;
 reg.OpenKey('.ldb');
 reg.WriteString('','tempfile');
finally
 reg.closekey;
 reg.free;
end;

In this way, the file type you see is tempfile.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.