I am working over one my student project over .Net4 and MVC3. Project is almost at completion except some security features such as Encoding/Decoding information for saving in config file such as Connection String etc.
I want to avoid a very complex solution and so I am looking for some easy to use Encryption technique in .NET ideally something where I can just provide a KEY and String and it gives me back the encoded text and vice versa (similar to the Base64 example given below).
I went through MSDN’s System.Security.Cryptography Namespace documentation online but it has a lot of options for a newbie like me I guess.
Kindly provide me with suggestions and path to follow to achieve it. Thank you.
While searching I found a simple solution of Base64 which I implemented like this:
static public string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string encodedValue = System.Convert.ToBase64String(toEncodeAsBytes);
return encodedValue;
}
static public string DecodeFrom64(string toDecode)
{
var toDecodeAsString = System.Convert.FromBase64String(toDecode);
string decodedValue = System.Text.ASCIIEncoding.ASCII.GetString(toDecodeAsString);
return decodedValue;
}
Works fine but the problem is as far as I’ve understood this is not something very reliable as a static encoding technique (one without a custom KEY) can be easily decoded and so many online base 64 decoders are available on net. I also tried to work with AES as expalined here but failed to succeed.