Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi
How to convert encrypted password to decrypted in C# in windows application

in my database table password was encrypted now i want to do decrypted.
Posted
Updated 29-Apr-17 2:04am
Comments
Sunny_Kumar_ 18-May-12 8:08am    
depends on the encryption method that you've used to encrypt the password. I suggest you to share the encryption method to get any help...
Timberbird 18-May-12 8:12am    
Encrypt it. Seriously, you don't mention which encryption algorythm you used (maybe it's not even encryption but hashing), so who can help you? It sounds like "I broke arbitrary thing, how do I fix it?".
And why would you want your passwords decrypted, anyway?
__John_ 18-May-12 8:13am    
Most encryption methods are non-orthogonal i.e they only go one way. So the answer is almost certanly, you cant do it.

Why you need to decrypt the password? Usually a salted hash of the password is stored and compared. If you encrypt/decrypt the password you have the password as plain text again and this is dangerous. The hash should be salted to avoid duplicated hash if the some users have the same passwords. For the salt you can take the user name.

C#
HashAlgorithm hash = new SHA256Managed();
string password = "12345";
string salt = "UserName";

// compute hash of the password
byte[] plainTextBytes = Encoding.UTF8.GetBytes(password);
byte[] hashBytes = hash.ComputeHash(plainTextBytes);

// create salted byte array
byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + saltBytes.Length];
for (int i = 0; i < plainTextBytes.Length; i++)
{
   plainTextWithSaltBytes[i] = plainTextBytes[i];
}

// compute salted hash
byte[] saltedHashBytes = hash.ComputeHash(plainTextWithSaltBytes);
string saltedHashValue = Convert.ToBase64String(saltedHashBytes);


You can calculate the salted hash of the password and store that within your file. During the authentication you calculate the hash from the user entries again and compare this hash with the stored password hash. Since it should be very difficult (its never impossible, always a matter of time) to get the plain text from a hash the password is protected from reading as plain text again.

Tip: Never store or send a password unencrypted. If you get a new password, encrypt is as soon as possible!
Ref: stackoverflow.com

Please refer:
How To: Encrypt and Decrypt string Using C#[^]
How to encrypt and decrypt password in asp.net using C#?[^]

Some CP Articles:
Simple encrypting and decrypting data in C#[^]
Encrypt and Decrypt Data with C#[^]
Encrypt/Decrypt String using DES in C#[^]
Encryption and Decryption on the .NET Framework[^]
 
Share this answer
 
Comments
Maciej Los 18-May-12 8:11am    
Good work! +5
Prasad_Kulkarni 18-May-12 8:11am    
Thank you Isomac!
VJ Reddy 18-May-12 8:14am    
Good answer. 5!
Prasad_Kulkarni 18-May-12 8:17am    
Thank you VJ!
BillW33 18-May-12 9:45am    
Very nice answer, +5
By Using this piece of code you can encrypt your password written in the Textbox in asp.net application.

C#
String myPassword = this.txtpassword.Text;
HashAlgorithm mhash = new SHA1CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(myPassword);
byte[] bytHash = mhash.ComputeHash(bytValue);
mhash.Clear();
this.rtxtpassword.Text = Convert.ToBase64String(bytHash);


try it & suggest.
 
Share this answer
 
v2
Comments
RAKESH CHAUBEY 19-Dec-12 1:08am    
Thanks man /...Nice one
Member 12734006 29-Apr-17 8:33am    
i wanted to encrypt the above textbox encrypted in itself. is it possible ? plz render the code . thanks
Dave Kreskowiak 29-Apr-17 11:29am    
Don't resurrect a FIVE YEAR OLD question. Open your own question by going to the "quick answers" menu and clicking "Ask a question".

Chances are really good you're not going to get an answer from someone who hasn't posted anything in the last five years.

Your "question" also doesn't make any sense at all.

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