当我尝试使用System.Security的加密代码时,我得到了一个运行时错误。我添加了一个对System.Security的引用,一切看起来都很好,但我得到了这个错误:“编译器错误消息: CS0103:名称'ProtectedData‘在当前上下文中不存在”
下面是抛出错误的代码。
public static string EncryptString(SecureString input, string entropy)
{
byte[] salt = Encoding.Unicode.GetBytes(entropy);
byte[] encryptedData = ProtectedData.Protect(
Encoding.Unicode.GetBytes(ToInsecureString(input)),
salt,
DataProtectionScope.CurrentUser);
return Convert.ToBase64String(encryptedData);
}谢谢,山姆
发布于 2013-08-27 09:21:51
您需要为System.Security.Cryptography添加一条using语句,并且需要一个对System.Security.dll的引用。从您的问题可以看出,您只是添加了引用,而没有添加using语句。
除了using语句,您还可以完全限定引用,如下所示:
byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect(
Encoding.Unicode.GetBytes(ToInsecureString(input)), salt,
System.Security.Cryptography.DataProtectionScope.CurrentUser);https://stackoverflow.com/questions/18455442
复制相似问题