如何在C#的Windows凭据中传递长字符串作为密码? [英] How to pass long string as password in windows credentials in C#?
问题描述
我在使用c#和Credential Manager API传递一个长字符串以保存到windows vault文件夹时遇到异常。否则它会成功保存到保险库。
例外情况是
I am getting exception while passing a long string to save to the windows vault folder using c# and Credential Manager API. Else it is getting saved successfully to the vault.
Exception coming is
Specified argument was out of the range of valid values.
Parameter name: The password has exceeded 512 bytes.
&
传递的密码字符串为< br $> b $ b
我的尝试:
&
password string passed is "TERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRTGVBFXDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDTREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEECFGBBCVBDRFGDXFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXRETWEREWRW3ERWERWRWRWRRRRRRRRRRRRRRRRRRRRRFDSFFFSDFSFSFSFDSFDDFSFSFSFGRWERWREWRWRWRDXVGFDGFDGFDGFDGDGDFGDGDGDREWRWREWRERRWREWREWRDXVCXBCVVVVVVVVVVVVVVREWRWERRRRRRRRRRREWRWRWREWR"
What I have tried:
public void SavePassword(string password)
{
try
{
using (var cred = new Credential())
{
cred.Password = password;
cred.Target = PasswordName;
cred.Type = CredentialType.Generic;
cred.PersistanceType = PersistanceType.LocalComputer;
cred.Save();
}
}
catch(Exception ex)
{
}
}
推荐答案
Parameter name: The password has exceeded 512 bytes.
您的密码长度为600字节,允许的最大密码为512.
Your password is 600 bytes long and the maximum allowed is 512.
这篇关于如何在C#的Windows凭据中传递长字符串作为密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!