Access数据库加密表头,让Access不那么脆弱

本文介绍了一个使用Delphi编写的程序,该程序通过修改MDB文件的头部来实现对这些文件的加密与解密操作,并利用ADO连接进行数据库操作。
部署运行你感兴趣的模型镜像

 

 

 #include <vcl.h>
#pragma hdrstop

#include "FrmAccessHeard.h"
#include   <Registry.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
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 TForm1::FormCreate(TObject *Sender)
{
    ADOConnection1->Connected=false;
    AnsiString DBName,TempName;
    char CDBName[100];
    char CTempName[100];
    DBName=ExtractFilePath(Application->ExeName)+"Message.db";
    TempName=ExtractFilePath(Application->ExeName)+"Temp.db";
    strcpy(CDBName,DBName.c_str());
    strcpy(CTempName,TempName.c_str());
    CopyFile(CDBName,CTempName,false);
    uncrypMDB(CTempName);
    CopyFile(CTempName,CDBName,false);
    ADOConnection1->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source='"+DBName+"';Persist Security Info=False;Jet OLEDB:Database Password=123456";
    ADOConnection1->Connected=true;
    CopyFile(CDBName,CTempName,false);
    EncrypMDB(CTempName);
    CopyFile(CTempName,CDBName,false);
    DeleteFile(CTempName);
    TRegistry   *reg = new TRegistry();
    try
    {
        reg->RootKey =HKEY_CLASSES_ROOT;
        reg->OpenKey(".ldb",true);
        reg->WriteString("","tempdb");
    }
    __finally
    {
        reg->CloseKey();
        reg->Free();
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EncrypMDB(String filename)
{
   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 TForm1::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();
   }
}

由Delphi代码翻译而来,经过些加工处理。

您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值