Can I add custom properties to PasswordCredential.

2019-01-28 23:28发布

问题:

In WinRT API there is Windows.Security.Credentials namespace which contains the PasswordCredential class. Using it we can encrypt sensitive data like user names and passwords but the class itself has a property named "Properties" which looks to me like a handy container for other custom properties somehow related to the stored credential but I can't get it to work. There is a "Read-only" access type for the "Properties" in the documentation but I thought that meant only that I can't change the reference to the container it points to. My question is:

Is the "Properties" property of PasswordCredential useable for programmers?

Sorry for any errors in text, you can also correct my english in the answers, it is not my native language ;)

EDIT: This may be useful:

The "Add" method in the following code throws ArgumentException:

PasswordVault v = new PasswordVault();
PasswordCredential c = new PasswordCredential("TEST", "TEST", "TEST");
c.Properties.Add("Name", "testName");
v.Add(c);

回答1:

Unfortunately, the PasswordCredentials.Properties is an instance of PasswordCredentialPropertyStore which documentation describes every method as "...reserved for internal use and not intended to be used in your code".

That's why it is not useable for programmers.



回答2:

No it is a read only property, so you can't set it. It's designed so you can enumerate the properties of the object (not that the c# class properties, but the individual properties of a properties collection). The naming makes this confusing.