Saturday, February 9, 2013

Encrypt a Password string in C Sharp (C#)

When you develop a secured ASP.NET web application you need to encrypt the password before it getting stored in database. Encryption means converting input data into an unreadable format.

Here is a simple code to encrypt a given string. You can use it in your project.
public string EncryptIt(string inputString)  
{  
    try  
    {  
        byte[] encryptedByteData= new byte[inputString.Length];  
        encryptedByteData= System.Text.Encoding.UTF8.GetBytes(inputString);  
        string encryptedData= Convert.ToBase64String(encryptedByteData);  
        return encryptedData;  
    }  
    catch (Exception ex)  
    {  
        throw ex;  
    }  
}  

1 comment:

  1. I always used to study paragraph in news papers but now as I
    am a user of net thus from now I am using net for articles or reviews, thanks to web.

    ReplyDelete