[英]Compiler Error Message: CS0103: The name 'ProtectedData' does not exist in the current context
I am getting a runtime error when trying to use System.Security's crypto code. 我在尝试使用System.Security的加密代码时遇到运行时错误。 I added a reference to System.Security and everything looks good but I am getting this error: "Compiler Error Message: CS0103: The name 'ProtectedData' does not exist in the current context"
我添加了对System.Security的引用,一切看起来不错,但我收到此错误:“编译器错误消息:CS0103:名称'ProtectedData'在当前上下文中不存在”
here is the code that is throwing the error. 这是抛出错误的代码。
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);
}
Thanks, Sam 谢谢,山姆
You need to add a using statement for System.Security.Cryptography
and you need a reference to System.Security.dll
. 您需要为
System.Security.Cryptography
添加using语句,并且需要对System.Security.dll
的引用。 From your question it appears you just added the reference and not the using statement. 从您的问题看来,您刚刚添加了引用而不是using语句。
Instead of the using statement you can also fully qualify the references like this: 您也可以完全限定引用,而不是using语句,如下所示:
byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect(
Encoding.Unicode.GetBytes(ToInsecureString(input)), salt,
System.Security.Cryptography.DataProtectionScope.CurrentUser);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.