6

使用Windows.Security.Credentials.PasswordVault该类,我可以访问存储在 Windows 凭据管理器中“Web 凭据”下的密码:

using System;
using Windows.Security.Credentials;

class Program {
    static void Main(string[] args) {
        PasswordVault vault = new PasswordVault();
        foreach (var cred in vault.RetrieveAll()) {
            cred.RetrievePassword();
            Console.WriteLine("Resource: {0}", cred.Resource);
            Console.WriteLine("UserName: {0}", cred.UserName);
            Console.WriteLine("Password: {0}", cred.Password);
        }
    }
}

我想知道是否有办法检索存储在“Windows 凭据”下的凭据。

4

1 回答 1

4

这里的答案有一个名为 CredentialManagement http://nuget.org/packages/CredentialManagement/的 Nuget 库 :Retrieve Credentials from Windows Credentials Store using C#

完美运行

        var cm = new Credential();
        cm.Target = "mycredentialname";

        if (!cm.Exists())
        {
            Console.WriteLine("cm is null");
        }
        cm.Load();
        Console.WriteLine("Password: " + cm.Password);
        Console.WriteLine("Username: " + cm.Username);
于 2016-01-19T11:27:16.110 回答