System.Security.Cryptography Protect

Anybody have any idea why ProtectedData.Protect from System.Security.Cryptography isn’t working, thought it supported in mono.

here is the code i am trying to use.

public static byte [] Protect( byte [] data )
{
try
{
// Encrypt the data using DataProtectionScope.CurrentUser. The result can be decr
ypted
// only by the same current user.
return ProtectedData.Protect( data, s_aditionalEntropy, DataProtectionScope.Curre
ntUser );
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not encrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
}
public static byte [] Unprotect( byte [] data )
{
try
{
//Decrypt the data using DataProtectionScope.CurrentUser.
return ProtectedData.Unprotect( data, s_aditionalEntropy, DataProtectionScope.Cur
rentUser );
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not decrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
}

I am trying to store an UNIQUE data or reads UNIQUE data from Computer(each computer has to be different)

Current All I can see is doing Protected Data, Mac address, Hardware Serial number, I think .net lib for mac address doesn’t work as far as no plugin goes, I always get 0 nics, and Hardware serial number I need to use system.management which mono doesn’t have.

Any ideas?

I’m needing to use PropectedData.Protect and ProtectedData.Unprotect. Do you happen to know anything I can do to be able to use these methods?

1 Like

You need to reference System.Security.dll

To do this in Unity, create a text file called mcs.rsp in your assets folder and place the following line in the text file:
-r:System.Security.dll

Also ensure that you are using the full .net 2.0 api compatability level and not .net 2.0 subset.

Happy protecting!

4 Likes