![]() Private static Credential ReadCredential(CREDENTIAL credential) Using (CriticalCredentialHandle critCred = new CriticalCredentialHandle(nCredPtr))ĬREDENTIAL cred = critCred.GetCredential() Public static Credential ReadCredential(string applicationName)īool read = CredRead(applicationName, CredentialType.Generic, 0, out nCredPtr) Original answer with the native API wrapper (A more recent version of this is available on GitHub): using System Var cred = CredentialManager.ReadCredential("ApplicationName") Īssert.AreEqual("username", cred.UserName) Īssert.AreEqual("Pa$$w0rd", cred.Password) ĬredentialManager.DeleteCredential("ApplicationName") How to use it: CredentialManager.WriteCredential("ApplicationName", "username", "Pa$$w0rd", CredentialPersistence.Session) Or you can use the Windows Credential Manager (This is the way I prefer because it allows users to backup/restore/edit their credentials even if your application has no such functionality). String data = (ProtectedData.Unprotect(protectedData, entropy, DataProtectionScope.CurrentUser)) Public static string Unprotect(string str)īyte protectedData = Convert.FromBase64String(str) String protectedData = Convert.ToBase64String(ProtectedData.Protect(data, entropy, DataProtectionScope.CurrentUser)) Here's an example: public static string Protect(string str)īyte entropy = (Assembly.GetExecutingAssembly().FullName) īyte data = (str) NET implementation ( ProtectedData) to encrypt the password. You can use the Data Protection API and its. Here's a summary of my blog post: How to store a password on Windows?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |