求助转化一段Delphi代码为C++Builder
以下是一段加密和解密Access头文件的代码,我就想用来加密Access数据库,让它不那么容易被破解。。
但是,下面这段代码我翻译不过来,,特来请教。谢谢
consttitlestr:array[0..15] of byte=($00,$01,$00,$00,$53,$74,$61,$6E,$64,$61,$72,$64,$20,$4A,$65,$74) ;//对应MDB文件的前16个字节titlestr2:array[0..15] of byte=($48,$4A,$00,$58,$55,$43,$48,$41,$4E,$47,$59,$4F,$55,$00,$20,$20) ;//更改后的MDB文件的前16个字节,自己随便写吧,比如写上自己公司的简称或自已的名produce EncrypMDB(filename:string); //用titlestr2内容替换MDB前16个字节,以便实现加密的作用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); //还原MDB前16个字节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;
copyfile(pchar(APP_path+'\data\account.db'),pchar(app_path+'data\temp.db'),false); //app_path表示程序的当前目录,account.db是个更改了扩展名的MDB文件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是个TADOConnection组件try adoconn.connected:=true;except MessageBox(handle,'打开数据库出现致命的错误!!!','错误',MB_OK+MB_ICONERROR);end;//打开后马上对其加密copyfile(pchar(APP_path+'\data\account.db'),pchar(app_path+'data\temp.db'),false); //app_path表示程序的当前目录,account.db是个更改了扩展名的MDB文件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');
reg:=TRegistry.Create;try reg.RootKey:=HKEY_CLASSES_ROOT; reg.OpenKey('.ldb'); reg.WriteString(','tempfile');finally reg.closekey; reg.free;end;
const Byte titlestr[16] ={0x00,0x01,0x00,0x00,0x53,0x74,0x61,0x6E,0x64,0x61,0x72,0x64,0x20,0x4A,0x65,0x74} ;//对应MDB文件的前16个字节 Byte titlestr2[16] ={0x48,0x4A,0x00,0x58,0x55,0x43,0x48,0x41,0x4E,0x47,0x59,0x4F,0x55,0x00,0x20,0x20} ;//更改后的MDB文件的前16个字节,自己随便写吧,比如写上自己公司的简称或自已的名void __fastcall EncrypMDB(String filename) //用titlestr2内容替换MDB前16个字节,以便实现加密的作用{ TFileStream *F; if (!FileExists(filename))return; F = new TFileStream(filename,fmOpenWrite); try{ F->Seek(0x00,soFromBeginning); F->Write(titlestr2,16); } __finally{ F->Free(); }}void __fastcall uncrypMDB(String filename) //还原MDB前16个字节{ TFileStream *F; if (!FileExists(filename)) return; F = new TFileStream(filename,fmOpenWrite); try{ F->Seek(0x00,soFromBeginning); F->Write(titlestr,16); }__finally{ F->free; }}
[解决办法]
void __fastcall uncrypMDB(String filename) //还原MDB前16个字节{ TFileStream *F; if (!FileExists(filename)) return; F = new TFileStream(filename,fmOpenWrite); try{ F->Seek(0x00,soFromBeginning); F->Write(titlestr,16); }__finally{ F->Free(); }}
[解决办法]
#include <Registry.hpp>
TRegistry * reg = new TRegistry();