Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Can you tell me how can decrypte it
Posted
Updated 25-Oct-12 8:10am
v2
Comments
Sergey Alexandrovich Kryukov 25-Oct-12 14:20pm    
Why would you want it, ever? Wrong way!
--SA

You should never ever decrypt a password. You should never develop a system where a password needs to be decrypted, or where a password needs to be stored, or where there is a possibility that any person can know a password created by a user. Such practices are unsafe and never needed. If you think about it, you will understand that the original password is absolutely not needed for authentication.

Disagree? Feel puzzled? Keep reading.

One of the ways of solving this problem which is usually used is calculation of a cryptographic hash function in both cases and storing the hash. If you want to say that this stored value is just the encrypted password, think again. The big difference is: the cryptographic hash cannot be decrypted at all, this is a one-way function. So, it's infeasible to calculate a password from hash (and, of course, it has nothing to do with system permissions: this is equally infeasible for anyone). And this is not needed: you just store hash and compare hash with hash.

Please see:
http://en.wikipedia.org/wiki/Cryptographic_hash_function[^],
http://en.wikipedia.org/wiki/Computational_complexity_theory#Intractability[^].

[EDIT]

The algorithms you need are already available in .NET:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx[^].

Don't use MD5 or SHA-1 — they are found to be broken; better use one from the SHA-2 family:
http://en.wikipedia.org/wiki/MD5[^],
http://en.wikipedia.org/wiki/SHA-1[^],
http://en.wikipedia.org/wiki/SHA-2[^].

[END EDIT]

Please see my past answers:
storing password value int sql server with secure way[^],
Decryption of Encrypted Password[^].

—SA
 
Share this answer
 
v3
Comments
fjdiewornncalwe 25-Oct-12 15:23pm    
+5. People still always insist on wanting to decrypt instead of comparing encrypted values.
Sergey Alexandrovich Kryukov 25-Oct-12 15:29pm    
Thank you, Marcus.
Well, this is natural. The world of modern encryption offers inventions which are not obvious to most people, even after reading, unless people pay great attention to the matter. Public-key cryptography, cryptographic cash and one-way functions are part of it.
--SA
Espen Harlinn 25-Oct-12 16:11pm    
5'ed!
Sergey Alexandrovich Kryukov 25-Oct-12 16:24pm    
Thank you, Espen.
--SA
CPallini 25-Oct-12 16:28pm    
5.
In mysql you can use Query like select password from login_tb where binary username=+txt1.text;
 
Share this answer
 
TRY THESE CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Data;
using System.Windows.Forms;
namespace Inventory_Accountancy
{
public class Cryptography
{
private static string _key;
 
public Cryptography() { }
public static string key { set { _key = value; } }
 
public static string Encrypt(string encrypt)
{
try
{
return Encrypt(encrypt, _key);
}
catch (Exception ex)
{
return "Wrong " + ex.Message.ToString();//,"Inventory Accountancy",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
 
internal static string Encrypt(string encrypt, string strKey)
{
try
{
TripleDESCryptoServiceProvider objDESC = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
byte[] byteHash, byteBuff;
 
byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strKey));
objHashMD5 = null;
objDESC.Key = byteHash;
objDESC.Mode = CipherMode.ECB;
 
byteBuff = ASCIIEncoding.ASCII.GetBytes(encrypt);
return Convert.ToBase64String(objDESC.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
}//objDESCrypto.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length)
catch (Exception ex)
{
return "Wrong " + ex.Message.ToString();
}
}
 
public static string Decrypt(string decrypt)
{
try
{
return Decrypt(decrypt, _key);
}
catch (Exception ex)
{
return "Wrong " + ex.Message.ToString();
}
}
 
public static string Decrypt(string decrypt, string strkey)
{
try
{
TripleDESCryptoServiceProvider objDESC = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
byte[] byteHash, byteBuff;
string tempStrKey = strkey;
 
byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tempStrKey));
objHashMD5 = null;
objDESC.Key = byteHash;
objDESC.Mode = CipherMode.ECB;
 

byteBuff = Convert.FromBase64String(decrypt);
string strDecrypted = ASCIIEncoding.ASCII.GetString(objDESC.CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
objDESC = null;
 
return strDecrypted;
}
catch (Exception ex)
{
return "Wrong " + ex.Message.ToString();
}
}
}
}
 
Share this answer
 

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