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.
  1. public string EncryptIt(string inputString)
  2. {
  3. try
  4. {
  5. byte[] encryptedByteData= new byte[inputString.Length];
  6. encryptedByteData= System.Text.Encoding.UTF8.GetBytes(inputString);
  7. string encryptedData= Convert.ToBase64String(encryptedByteData);
  8. return encryptedData;
  9. }
  10. catch (Exception ex)
  11. {
  12. throw ex;
  13. }
  14. }

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