Access 的一些早期版本使用异或方法进行简单加密,当忘记密码时可以用同样的办法进行恢复.
以Access2000版本为例,从42H字节开始的后40字节为unicode存储的密码信息,与字节组
0x0b,0x6d ,0xec ,0x37 ,0xd0 ,0xd2 ,0x9c ,0xfa ,0x4b ,0xc8 ,0x28 ,0xe6 ,0x9e ,0x20 ,0x8a ,
0x60 ,0xd9 ,0x02 ,0x7b ,0x36 ,0x78 ,0xe4 ,0xdf ,0xb1 ,0xfa ,0x62 ,0x13 ,0x43 ,0x42 ,0x39 ,
0xb1 ,0x33 ,0xb9 ,0xf7 ,0x79 ,0x5b ,0x1f ,0x23 ,0x7c ,0x2c
异或后即可还原.上述密钥字节组可通过新建ACCESS文件后查看得知.
Access是以轻量化为目的设计的数据库,在重要应用中应该采用更专业的数据库产品,如Microsoft SQL Server.
以下以C#为例,说明获取Access2000密码的方法. 注意:解密结果应用Unicode解码输出,以保证正常显示.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 80);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(232, 88);
this.button1.TabIndex = 0;
this.button1.Text = "解";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 16);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(376, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// button2
//
this.button2.Location = new System.Drawing.Point(408, 16);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(88, 24);
this.button2.TabIndex = 2;
this.button2.Text = "浏览";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(24, 48);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(272, 21);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(640, 181);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox2,
this.button2,
this.textBox1,
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Form1";
this.Text = "解";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text=this.openFileDialog1.FileName;
this.textBox2.Text ="";
}
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
this.textBox2.Text =getPassWord2000(this.textBox1.Text);
}
catch(System.Exception ee)
{
System.Windows.Forms.MessageBox.Show(ee.Message);
}
}
//
public static string getPassWord2000(string FilePath)
{
byte[] key={0x0b,0x6d ,0xec ,0x37 ,0xd0 ,0xd2 ,0x9c ,0xfa ,0x4b ,0xc8 ,0x28 ,0xe6 ,0x9e ,0x20 ,0x8a ,0x60 ,0xd9 ,0x02 ,0x7b ,0x36 ,0x78 ,0xe4 ,0xdf ,0xb1 ,0xfa ,0x62 ,0x13 ,0x43 ,0x42 ,0x39 ,0xb1 ,0x33 ,0xb9 ,0xf7 ,0x79 ,0x5b ,0x1f ,0x23 ,0x7c ,0x2c};
string result="";
System.Exception ex;
try
{
if(FilePath.Trim()=="")
{
ex=new Exception("未选定文件");
}
else if(System.IO.File.Exists(FilePath.Trim()))
{
ex=new Exception("文件不存在");
}
System.IO.BinaryReader br=new System.IO.BinaryReader(new System.IO.FileStream(FilePath.Trim(),System.IO.FileMode.Open));
byte[] db=new byte[40];
int ix=0;
while((ix++)<0x42)
{
br.ReadByte();
}
db=br.ReadBytes(40);
br.Close();
for(int i=0;i<40;i++)
{
byte b=(byte)(db[i]^key[i]);
db[i]=b;
}
System.IO.MemoryStream m=new System.IO.MemoryStream(db,0,40,false,true);
System.IO.StreamReader s=new System.IO.StreamReader(m,System.Text.Encoding.Unicode);
result =s.ReadToEnd();
s.Close();
m.Close();
}
catch(System.Exception ee)
{
throw ee;
}
return result;
}
}
}