using System.Security.Cryptography;
class Program{
static void Main() {
string sMsg = "The message to encrypt!";
string sEnc, sDec;
System.Text.Encoding utf = new System.Text.UTF8Encoding();
byte[] entropy = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
{
byte[] bMsg = utf.GetBytes(sMsg);
byte[] bEnc = ProtectedData.Protect(
bMsg , entropy , DataProtectionScope.CurrentUser);
sEnc = System.Convert.ToBase64String(bEnc);
}
{
byte[] bEnc = System.Convert.FromBase64String(sEnc);
byte[] bDec = ProtectedData.Unprotect(
bEnc, entropy, DataProtectionScope.CurrentUser);
sDec = utf.GetString(bDec);
}
System.Console.WriteLine("Message : " + sMsg);
System.Console.WriteLine("Encrypted: " + sEnc);
System.Console.WriteLine("Decrypted: " + sDec);
}
}