I would like to encrypt a short textbox or string (not a file) in my program to render its contents for human unreadable or encrypt it with simple encryption that it is safe (like any sensitive passwords etc.). In Visual Basic were easy five-liners to do this which aren't working in my C# when I copy it there. I could not find something appropriate. There are only very difficult examples out with huge amount of code needed which mostly throws a lot of errors and requires yourself setting up any complex keys or key pairs or hashes, utf encodings or both to make it working and it just never does. I have no clue of all that and I need just a simple function which works both ways for encryption. Could not find anything like that for C# which is really working without errors and does the Job forward and also backward. In VB encrypted me the XOR function which isn't existing in C#.
Or how would I get that code sample below working, it is the most promising one: it gives me many errors if I copy it in my C# in the button1_click event:
Error 1: Type or Namespace Definition or end-the-file expected
Error 2: The type or Namespace "TripleDESCryptoServiceProvider" could not be found
Error 3: "CipherMode" does not exist in the current context
Error 4: "Getkey" does not exist in the current context
Error 5: "PaddingMode" does not exist in the current context Error 6: Error 8 The type or namespace name 'ICryptoTransform' could not be found (are you missing a using directive or an essemble reference?)
public static string Encrypt(string data)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
DES.Mode = CipherMode.ECB;
DES.Key = GetKey("a1!B78s!5(");
DES.Padding = PaddingMode.PKCS7;
ICryptoTransform DESEncrypt = DES.CreateEncryptor();
Byte[] Buffer = ASCIIEncoding.ASCII.GetBytes(data);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
}
public static string Decrypt(string data)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
DES.Mode = CipherMode.ECB;
DES.Key = GetKey("a1!B78s!5(");
DES.Padding = PaddingMode.PKCS7;
ICryptoTransform DESEncrypt = DES.CreateDecryptor();
Byte[] Buffer = Convert.FromBase64String(data.Replace(" ","+"));
return Encoding.UTF8.GetString(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
}