user971741
user971741

Reputation:

Strong and simple to implement encryption techniques in .NET?

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.

Upvotes: 1

Views: 2253

Answers (2)

poupou
poupou

Reputation: 43553

For maximum simplicity just have a look at Windows' Data Protection API (DAPI). This will provide encryption without requiring you to handle the keys.

You can easily use this with the ProtectedData class provided in .NET.

Upvotes: 2

parapura rajkumar
parapura rajkumar

Reputation: 24403

here is a simple example Simple String Encryption and Decryption with Source Code

Upvotes: 1

Related Questions