Saturday 16 March 2013

how to encraypt or decraypt password in asp.net



Description:-              

What is Encryption:-

                                Encryption means to Translate or Convert our Message or Text  called the PlainText into an Encoded Form called the Ciphertext.

What is Decryption:-

                        Decryption is the reverse Process of the Encryption means Converting our Ciphertext Message into an PlainText Message is Called Decryption.

What is Use or Advantages of Encryption and  Decryption:-

1.       To store our password in database when user is logged into the website so other user can not show the password.
2.       Password Security.
3.       Account Security.
4.       Even DataBase Administrator can aslo does not see your password.

Generally this Type of Facility are avilable in Banking Site or Social Netaworking so for Better Protection of His/her Account.

In this Example we Define to Function one is Encrypt password and Second is Decrypt password. Decrypt is used at Insert time and Encrypt is used at Fetch or select time.


Example:-

using System.Text;


 private string Decryptdata(string encryptpwd)
    {
        string decryptpwd = string.Empty;
        UTF8Encoding encodepwd = new UTF8Encoding();
        Decoder Decode = encodepwd.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
        int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
        char[] decoded_char = new char[charCount];
        Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
        decryptpwd = new String(decoded_char);
        return decryptpwd;
    }


 private string Encryptdata(string password)
    {
        string strmsg = string.Empty;
        byte[] encode = new byte[password.Length];
        encode = Encoding.UTF8.GetBytes(password);
        strmsg = Convert.ToBase64String(encode);
        return strmsg;
    }

  

0 comments:

Post a Comment