构建一个读取 Access 数据库文件的 C# 应用程序。 每个数据库都有不同的密码。目前我使用的是Access Passview http://www.nirsoft.net/utils/accesspv.html (免费软件)读取密码,但我希望能够将其自动化,以便我可以将其分配给 OLEDB 连接字符串的字符串。 (exe执行时的屏幕截图)
exe 可以从命令行运行,这是我尝试在我的应用程序中实现的
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "accesspv.exe",
Arguments = _filePath,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadToEnd();
Console.WriteLine(line);
_password2016 = line;
}
这对我不起作用,因为 access passview exe 正常运行并且密码不会显示在控制台中。
我的主要问题是 1. 是否可以读取密码并将其分配给我的连接字符串的变量? 2. 是否让 accesspv.exe 在后台运行,最终用户看不到它?
谢谢。
最佳答案
该实用程序的源代码可在网站 here 上找到。 。您可以用 C# 编写相同的代码。
public class Program
{
private static readonly byte[] XorBytes = {
0x86, 0xFB, 0xEC, 0x37, 0x5D, 0x44, 0x9C, 0xFA, 0xC6,
0x5E, 0x28, 0xE6, 0x13, 0xB6, 0x8A, 0x60, 0x54, 0x94
};
public static void Main(string[] args)
{
var filePath = args[0];
var fileBytes = new byte[256];
using (var fileReader = File.OpenRead(filePath))
{
fileReader.Read(fileBytes, 0, fileBytes.Length);
}
var passwordBytes = XorBytes
.Select((x, i) => (byte) (fileBytes[i + 0x42] ^ x))
.TakeWhile(x => x != 0);
var password = Encoding.ASCII.GetString(passwordBytes.ToArray());
Console.WriteLine($"Password is \"{password}\"");
Console.ReadKey();
}
}
关于c# - 使用 C# 检索 Access .mdb 数据库密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41445602/