Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I would like to create a login form in ASP.Net MVC application.

When the user registered, the Password should be encrypted and then it should be stored in DB.


Now, my point is any one can provide me the proper links for encrypting and decrypting the string using C# language..

I do not know how many types of algorithms are there and how to use them but i want to use the simplest one as it is the starting step for me.....

I hope you understand my question and thanks in advance
Posted

Why you need to decrypt the password. It should never be decrypted for security reasons. And for encryption try these:

how to create password encrypt decrypt in c#[^]

encrypt or decrypt password in c# with asp.net[^]

hope it helps :)
 
Share this answer
 
Comments
P_A_1 6-May-12 6:16am    
Hi Uday, can you explain a little bit about your words

"Why you need to decrypt the password. It should never be decrypted for security reasons"..
Hi all,

What i understand till now is,

if we want to provide the security to passwords, then we can do it in two ways...

1. Using Hashing Concept

2. Usning Encrypting and Decrypting concepts..

Explanation:

If we want to use the Hashing then, we will use the Salt Value.

Ex Links:

Example 1[^]

Example 2[^]



If we want to use the Encryption and Decryption concept, then we should use any of the algorithms like MD5, DES . SHA etc..

Ex Links:

Encrypt/Decrypt String using DES in C#[^]

Is it correct ?. It not just guide me once....and which one is preferable(i.e either Hashing Concept or E&D Concept....
 
Share this answer
 
 
Share this answer
 
Hi Uday,
can you explain a little bit about your words
"Why you need to decrypt the password. It should never be decrypted for security reasons".
 
Share this answer
 
use these two function to enrypt and derypt the string
you can use C# to encrypt and decrypt strings using a salt key to protect the data.
This type of encryption is called symmetric-key encryption, which means that the string can only be decrypted if the other party has the correct key


<pre lang="c#">
using System;
using System.Security.Cryptography;
using System.Text;

 public static string Encrypt(string input, string key)
   {
      byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input);
      TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
      tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key);
      tripleDES.Mode = CipherMode.ECB;
      tripleDES.Padding = PaddingMode.PKCS7;
      ICryptoTransform cTransform = tripleDES.CreateEncryptor();
      byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
      tripleDES.Clear();
      return Convert.ToBase64String(resultArray, 0, resultArray.Length);
   }
   public static string Decrypt(string input, string key)
   {
      byte[] inputArray = Convert.FromBase64String(input);
      TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
      tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key);
      tripleDES.Mode = CipherMode.ECB;
      tripleDES.Padding = PaddingMode.PKCS7;
      ICryptoTransform cTransform = tripleDES.CreateDecryptor();
      byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
      tripleDES.Clear();
      return UTF8Encoding.UTF8.GetString(resultArray);
   }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900