I have a string that I want to Encrypt with the AES algorithm. Then I want to store the result into a cookie within web browsers.
The result of the AES Encryption is a byte array. I want to make this into a string that can be store in a cookie. It seems none of the Encodings work properly.
It would be nice to be able to encrypt special characters as well, like ë… Currently, I’m encrypting the string, then I’m using the base 64 string encoding and replacing some characters, like “=”, “+” and “/”. While this works, it seems to not be an elegant solution…
Is there a better way?
This is a pretty common approach to what your doing.
The following class wraps all this up by using ‘-‘ and ‘_’ while omitting the padding. It is much more efficient than replacing characters and is nearly as fast as the Convert.ToBase64String method:
http://csharptest.net/browse/src/Library/Formatting/Safe64Encoding.cs
Usage Example: