Safety Access Encryption Method

zhaozj2021-02-08  261

Safety Access Encryption Method

Xu Changyou

Microsoft Access Database is one of our common desktop data. Most small and medium-sized business database management systems can use it, but their security has always been an invisible, attempting, a financial management system, users directly open the database to change What will the data? Some systems may just change the extensions, or add a password, well known, cracking how the Access password is much! So this kind of encryption is asked, and the following introduces a simple method to achieve an encryption of Access data for your reference.

Open the MDB file with UltraEdit, you can see, the first 16 bytes of the file: 00 01 00 53 74 61 6e 64 61 72 64 20 4A 65 74 Now there is a few, then use Access to open, find different identification File format error, because the information saved in front of Access is some of the definitions and passwords of some MDB files. If you change these content, others are hard to see the format of this database, and it is impossible to open it, and this will not change the content of the database. Do not destroy the original data.

Below, Delphi is used as a simple encrypted solution: the used encryption solution is as follows:

Const Titlestr: Array [0..15] of Byte = ($ 00, $ 01, $ 00. $ 64, $ 61, $ 72, $ 64, $ 20, $ 4A, $ 65, $ 74); / / Corresponding to the top 16 bytes of MDB files Titlestr2: Array [0..15] of byte = ($ 48, $ 4A, $ 00, $ 58, $ 4E, $ 47, $ 59, $ 4F, $ 55, $ 00, $ 20, $ 20); // Change the first 16 bytes of MDB files, write it casually, such as writing a referred to as a company or a self-name propuster Encrypmdb (filename: string); // Titlestr2 content replaces the top 16 bytes of MDB to achieve encryption VAR f: TFileStream; Begin if not fileexists (filename) THEN EXIT; F: = TFileStream.create (FileName, Fmopenwrite); Try F.seek ($ 00, SOFROMBEGINNIN) ); F.Write (Titlestr2, 16); Finally F.Free; end; end; product uncrypmdb (filename: string); // Restore MDB 16 byte 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 lock file (.ldb file) will appear after opening the Access database, because we also use the database, so you must restore the database during use. If you do not encrypt after the restore, the user can also copy the MDB file, then open it with Access or other tools, so you should be in an encrypted state before and after the data can guarantee the security of the data. Using Delphi Ado Connection Database Use the following method to implement:

// Restore data so as to use the database 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 a MDB file uncrypmdb (App_Path 'Data / Temp.db') that has changed the extension; copyl (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 assembly is TADOConnection try adoconn.connected: = true EXCEPT MessageBox (Handle, 'Open the database appears fathers !!!', 'error', MB_OK MB_ICONEROR); END; // Immediately after opening 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 a MDB file encrypmdb that changes the extension (App_Path Data / Temp.db '); CopyFile (Pchar (App_Path 'Data / Temp.db'), Pchar (App_Path '/ Data / Account.db'), DELETEFILE (App_Path 'Data / Temp.db'); using two temporary files above, Because the database is opened, the MDB is directly written, and you can't determine how many users open the program. The entire program shares a Tadoconnection, which onlys the MDB file is restored when the database connection is turned on, and the MDB files have always been encrypted! Users have copied MDB files. It is very difficult to know what it is! After opening the database, there will be a .ldb file, the type will appear in the words, if you don't want to see what is, modify the registry, such as: reg: = tregistry.create; try reg.rootkey: = HKEY_CLASSESS_ROOT Reg.openkey ('. ldb'); reg.writeString ('', 'tempfile'); finally reg.closekey; reg.free; end; this type of file that users see is TempFile

Note: The database used by the above refers to Access 2000, other versions, I think it should be different, try it yourself. If you have any better way or suggestions, welcome to the communication: YOUSOFT@chinaren.com

转载请注明原文地址:https://www.9cbs.com/read-2696.html

New Post(0)