Microsoft Access database, is one of our common desktop data, most of the small and medium-sized Enterprise database management System can adopt it, but its security has always been a burden, imagine, a financial management system, users directly open the database to change data, what will the consequences? Some systems may simply change the extension or add a password to an Access database, and it is well known that the methods and tools for breaking access passwords are many online! So this kind of encryption as a burden, the following describes a simple way to achieve access data encryption, for everyone's reference.
Open the MDB file with UltraEdit to see the contents of the first 16 bytes of the file:
4 A 65 74 (a) of 6E
Now just change a few, and then open with access to find different recognized file format errors, because the information saved before access is the definition of some MDB files and passwords, if you change the content, it is difficult for others to see the format of the database, can not open it, This does not make changes to the contents of the database and does not break the original data.
The following is to use Delphi to make a simple encryption solution program:
The cryptographic solution functions used are 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);//corresponds to 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);//Change the first 16 bytes of the MDB file, write it yourself, for example, write your company's short name or own
Produce Encrypmdb (filename:string); Replaces the first 16 bytes of the MDB with TITLESTR2 content to enable encryption
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 MDB first 16 bytes
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) appears when you open an Access database, because we also want to use the database ourselves, so we must restore the database when we use it.
If the restore is not encrypted, the user can also copy the MDB file, and then open it with access or other tools, so it should be encrypted before and after the data is opened to ensure data security.
Using Delphi to connect with the database using the following methods can be implemented:
Restore data so that you can use the database yourself
CopyFile (Pchar (app_path+ ' \data\account.db '), Pchar (app_path+ ' data\temp.db '), false); App_path represents the current directory of the program, Account.db is an MDB file that has changed the extension
Uncrypmdb (app_path+ ' data\temp.db ');
CopyFile (Pchar (app_path+ ' data\temp.db '), Pchar (app_path+ ' \data\account.db '), false);
adoconn.connectionstring:= ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= ' +app_path+ ' data\account.db; Persist security Info=false '; ADOcon is a tadoconnection component.
Try
Adoconn.connected:=true;
Except
MessageBox (handle, ' open the database for fatal error!!! ', ' wrong ', mb_ok+mb_iconerror);
End
Encrypt it immediately after it is turned on
CopyFile (Pchar (app_path+ ' \data\account.db '), Pchar (app_path+ ' data\temp.db '), false); App_path represents the current directory of the program, Account.db is an MDB file that has changed the extension
Encrypmdb (app_path+ ' data\temp.db ');
CopyFile (Pchar (app_path+ ' data\temp.db '), Pchar (app_path+ ' \data\account.db '), false);
DeleteFile (app_path+ ' data\temp.db ');
The above two temporary files are used because there is a problem when the database is opened and then write directly to the MDB, and you cannot determine how many users have opened the program.
The entire program share a tadoconnection, only when the database connection to restore the MDB file, other time MDB file has been in the encryption state! The user has copied the MDB file and it's hard to know what it is!
After you open the database, you will have a. ldb file, the type will appear, access, and so on, if you do not want to let people see what it is, modify the registry, such as:
Reg:=tregistry.create;
Try
Reg. Rootkey:=hkey_classes_root;
Reg. Openkey ('. ldb ');
Reg. WriteString (', ' tempfile ');
Finally
Reg.closekey;
Reg.free;
End
This allows the user to see the file type is Tempfile
Note: The above database refers to Access 2000, the other version of I think it should be the same, try it yourself. If you have any better methods or suggestions, welcome to the exchange of letters: yousoft@chinaren.com
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.