c# - 使用 C# 检索 Access .mdb 数据库密码

标签 c# ms-access

构建一个读取 Access 数据库文件的 C# 应用程序。 每个数据库都有不同的密码。目前我使用的是Access Passview http://www.nirsoft.net/utils/accesspv.html (免费软件)读取密码,但我希望能够将其自动化,以便我可以将其分配给 OLEDB 连接字符串的字符串。 (exe执行时的屏幕截图)

enter image description here

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/

相关文章:

c# - 将两个值插入一列,包括乘法 C#

c# - Windows 10 邮件样式 ListView

c# - 查询生成器是否可以防止 SQL 注入(inject)?

ms-access - 如何从前端在 Access 数据库后端上执行 VB 代码?

c# - 如何将选定的 WP7 强调画笔转换为 HTML 颜色代码?

c# - 任务中的阻塞方法

c# - 如何对 List(Of Integer()) 进行区分?

c# - 如何获取详细的 ExecuteNonQuery 错误消息?

c - 微软 Access : Search through Table for the same part of the String

sql - 加入 Is Null MS Access SQL