Simple C# encryption and decryption

There are various ways to encrypt and decrypt a string in with .Net. The simplest is to use Base64. But this just makes the string unreadable for a human, but it is not a real encryption. Although, for most case is is likely enough.

If you want something a little fancier, I have a simple solution for you:

I had to use the Base64 Encoding in addition to the encryption so you can use the result string like a normal string and write it somewhere. Otherwise it could contain non ASCII characters and you couldn’t easily use it.

If you want to use the encrypted string in a url, you should HTML encode it too: