delphi - Encrypt/Decrypt a MS Access 2000 (*.mdb) Database File (Extra Security) -
for security, encrypt/decrypt ms access 2000 (*.mdb) database file.
i using delphi 7 , looking free or opensource solution (possible 2 functions allow pass file name , key).
i perform decrypt before app starts, , encrypt when app shuts down. best places this. oncreate, ondestroy events?
i assume first have create small utility uses encrypt portion of solution encrypt database file first?
thanks
i understand reasons have encrypt old access database , because security of access 2000 , 2003 weak. primary recommendation try upgrade access 2007 or higher uses microsoft cryptographic api, , incorporates significant improvements in security.
if can't upgrade, here leave option encrypt mdb file.
1) encrypt data can use jwawincrypt
unit part of jedi jwscl
library, can download library here.
check sample function uses 3des algorithm encrypt file.
uses classes, jwawintype, jwawincrypt, sysutils; procedure cryptfile(const infilename, outfilename, password: ansistring; encrypt: boolean); const buffersize=1024*64; var streamsource : tfilestream; streamdest : tfilestream; cryptprov : hcryptprov; crypthash : hcrypthash; cryptkey : hcryptkey; buffer : lpbyte; bytesin : dword; final : boolean; begin cryptacquirecontext(cryptprov, nil, nil, prov_rsa_full, crypt_verifycontext); try cryptcreatehash(cryptprov, calg_3des_112, 0, 0, crypthash); try crypthashdata(crypthash, @password[1], length(password), 0); cryptderivekey(cryptprov, calg_3des, crypthash, 0, cryptkey); cryptdestroyhash(crypthash); end; streamsource := tfilestream.create(infilename, fmopenread or fmsharedenywrite); streamdest := tfilestream.create(outfilename, fmcreate); try getmem(buffer, buffersize); try repeat bytesin := streamsource.read(buffer^, buffersize); final := (streamsource.position >= streamsource.size); if encrypt cryptencrypt(cryptkey, 0, final, 0, buffer, bytesin, bytesin) else cryptdecrypt(cryptkey, 0, final, 0, buffer, bytesin); streamdest.write(buffer^, bytesin); until final; freemem(buffer, buffersize); end; streamsource.free; streamdest.free; end; cryptreleasecontext(cryptprov, 0); end; end;
and use in way
to encrypt file
cryptfile('c:\temp\in.zip', 'c:\temp\out.zip','fdkjldf3832kka83' ,true);
to decrypt file
cryptfile('c:\temp\out.zip', 'c:\temp\in.zip','fdkjldf3832kka83' ,true);
2) location of code encryot , decrypt data, depends of design of application.
3) keep in mind if application crashes data unprotected.
4) maybe best option build small application decrypt data , launch main application , stay monitoring status until main application ends. , encypt data again.
Comments
Post a Comment