- #region MD5 Encryption
- // <summary>
- // MD5 encryption
- // </summary>
- /// <param name= "strsource" > string required for encryption </param>
- /// <RETURNS>MD5 string after encryption </returns>
- public static string Md5encrypt (string strsource)
- {
- //Put the string in a byte array
- byte[] Bytin = System.Text.Encoding.Default.GetBytes (strsource);
- //Establish keys and offsets for encrypted objects
- Byte[] IV = {102, 16, 93, 156, 78, 4, 218, 32}; //define offset
- byte[] key = {55, 103, 246, 79, 36, 99, 167, 3}; //define key
- //Instance DES encryption class
- DESCryptoServiceProvider mobjcryptoservice = new DESCryptoServiceProvider ();
- Mobjcryptoservice.key = IV;
- MOBJCRYPTOSERVICE.IV = key;
- ICryptoTransform encrypto = Mobjcryptoservice.createencryptor ();
- //instance MemoryStream stream encryption file
- System.IO.MemoryStream ms = new System.IO.MemoryStream ();
- CryptoStream cs = New CryptoStream (MS, Encrypto, CryptoStreamMode.Write);
- Cs. Write (bytin, 0, bytin.length);
- Cs. FlushFinalBlock ();
- return System.Convert.ToBase64String (Ms. ToArray ());
- }
- #endregion
- #region MD5 Decryption
- // <summary>
- /// MD5 decryption
- // </summary>
- /// <param name= "Source" > String to Decrypt </param>
- /// <RETURNS>MD5 decrypted string </returns>
- public static string Md5decrypt (string Source)
- {
- //Convert decrypted string to byte array
- byte[] Bytin = System.Convert.FromBase64String (Source);
- //Given the decrypted key and offset, the key and offset must be the same as the key and offset at the time of encryption
- Byte[] IV = {102, 16, 93, 156, 78, 4, 218, 32}; //define offset
- byte[] key = {55, 103, 246, 79, 36, 99, 167, 3}; //define key
- DESCryptoServiceProvider mobjcryptoservice = new DESCryptoServiceProvider ();
- Mobjcryptoservice.key = IV;
- MOBJCRYPTOSERVICE.IV = key;
- //instance stream for decryption
- System.IO.MemoryStream ms = New System.IO.MemoryStream (bytin, 0, bytin.length);
- ICryptoTransform encrypto = Mobjcryptoservice.createdecryptor ();
- CryptoStream cs = New CryptoStream (MS, Encrypto, CryptoStreamMode.Read);
- StreamReader STRD = new StreamReader (CS, Encoding.default);
- return STRD. ReadToEnd ();
- }
- #endregion
MD5 encryption MD5 decryption