I am getting a runtime error when trying to use System.Security's crypto code. 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"
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
. From your question it appears you just added the reference and not the using statement.
Instead of the using statement you can also fully qualify the references like this:
byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect(
Encoding.Unicode.GetBytes(ToInsecureString(input)), salt,
System.Security.Cryptography.DataProtectionScope.CurrentUser);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With