Simple MD5 Encryption
The first thing to have a decryption rule is key.
The code is as follows
Create key
public string GenerateKey ()
{
DESCryptoServiceProvider descrypto = (DESCryptoServiceProvider) descryptoserviceprovider.create ();
Return ASCIIEncoding.ASCII.GetString (Descrypto.key);
}
Then it's encryption.
The parameters passed in are the strings you want to encrypt, and then the encryption rules;
MD5 encryption
public string Md5encrypt (string ptoencrypt, String SKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
byte[] Inputbytearray = Encoding.Default.GetBytes (Ptoencrypt);
Des. Key = ASCIIEncoding.ASCII.GetBytes (SKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes (SKey);
MemoryStream ms = new MemoryStream ();
CryptoStream cs = new CryptoStream (MS, Des. CreateEncryptor (), cryptostreammode.write);
Cs. Write (Inputbytearray, 0, inputbytearray.length);
Cs. FlushFinalBlock ();
StringBuilder ret = new StringBuilder ();
Write your encrypted content according to the rules
foreach (Byte b in Ms. ToArray ())
{
Ret. AppendFormat ("{0:x2}", b);
}
Ret. ToString ();
return ret. ToString ();
}
Decryption to correspond to after encryption:
The arguments passed are: strings encrypted with the rules above, then rules
MD5 decryption
public string Md5decrypt (string ptodecrypt, String SKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
byte[] Inputbytearray = new BYTE[PTODECRYPT.LENGTH/2];
Interpret byte according to rules
for (int x = 0; x < PTODECRYPT.LENGTH/2; × x + +)
{
int i = (Convert.ToInt32 (ptodecrypt.substring (x * 2, 2), 16));
INPUTBYTEARRAY[X] = (byte) i;
}
Des. Key = ASCIIEncoding.ASCII.GetBytes (SKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes (SKey);
MemoryStream ms = new MemoryStream ();
CryptoStream cs = new CryptoStream (MS, Des. CreateDecryptor (), cryptostreammode.write);
Cs. Write (Inputbytearray, 0, inputbytearray.length);
Cs. FlushFinalBlock ();
StringBuilder ret = new StringBuilder ();
Return System.Text.Encoding.Default.GetString (Ms. ToArray ());
}
Simple MD5 encryption, decryption
Can be written as a public class in any place called
Good bye!!!!
C#,asp. NET simple MD5 encryption, decryption