The user login password encrypted, in order to see the original password, can be decrypted. The main purpose is to prevent someone from knowing the database user name and password using Query Analyzer to enter the database to view the password
Without the use of MD5, MD5 cannot be decrypted.
<summary>
Encryption
</summary>
<param name= "RS" ></param>
<returns></returns>
public static string Desencryptmethod (String rs)
{
byte[] Deskey = new byte[] {0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08};
byte[] Desiv = new byte[] {0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08};
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
Try
{
byte[] Inputbytearray = Encoding.Default.GetBytes (RS);
Byte[] Inputbytearray=encoding.unicode.getbytes (RS);
Des. Key = Deskey; ASCIIEncoding.ASCII.GetBytes (SKey);
DES.IV = Desiv; ASCIIEncoding.ASCII.GetBytes (SKey);
MemoryStream ms = new MemoryStream ();
CryptoStream cs = new CryptoStream (MS, Des. CreateEncryptor (),
CryptoStreamMode.Write);
Write the byte array into the crypto stream
(It'll end up in the memory stream)
Cs. Write (Inputbytearray, 0, inputbytearray.length);
Cs. FlushFinalBlock ();
Get the data back from the memory stream, and into a string
StringBuilder ret = new StringBuilder ();
foreach (Byte b in Ms. ToArray ())
{
Format as Hex
Ret. AppendFormat ("{0:x2}", b);
}
Ret. ToString ();
return ret. ToString ();
}
Catch
{
Return RS;
}
Finally
{
des = null;
}
}
<summary>
Decrypt
</summary>
<param name= "RS" ></param>
<returns></returns>
public static string Desdecryptmethod (String rs)
{
byte[] Deskey = new byte[] {0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08};
byte[] Desiv = new byte[] {0x16, 0x09, 0x14, 0x15, 0x07, 0x01, 0x05, 0x08};
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
Try
{
Put the input string into the byte array
byte[] Inputbytearray = new Byte[rs. LENGTH/2];
for (int x = 0; x < Rs. LENGTH/2; X + +)
{
int i = (Convert.ToInt32 (Rs. Substring (x * 2, 2), 16));
INPUTBYTEARRAY[X] = (byte) i;
}
Des. Key = Deskey; ASCIIEncoding.ASCII.GetBytes (SKey);
DES.IV = Desiv; ASCIIEncoding.ASCII.GetBytes (SKey);
MemoryStream ms = new MemoryStream ();
CryptoStream cs = new CryptoStream (MS, Des. CreateDecryptor (), cryptostreammode.write);
Flush the data through the crypto stream into the memory stream
Cs. Write (Inputbytearray, 0, inputbytearray.length);
Cs. FlushFinalBlock ();
//get the decrypted data back from the memory stream
& nbsp; StringBuilder ret = new StringBuilder ();
return System.Text.Encoding.Default.GetString (Ms. ToArray ());
}
Catch
{
return RS;
}
finally
{
des = null;
}
}
can be used directly.
. NET password encryption (reversible)