Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Security.Cryptography;
- public string encrypt(string InputText)
- {
- byte[] clearData = System.Text.Encoding.UTF8.GetBytes(InputText);
- MemoryStream ms = new MemoryStream();
- CryptoStream cs = new CryptoStream(ms, this.tDes.CreateEncryptor(), CryptoStreamMode.Write);
- cs.Write(clearData, 0, clearData.Length);
- cs.FlushFinalBlock();
- byte[] CipherBytes = ms.ToArray();
- ms.Close();
- cs.Close();
- string EncryptedData = Convert.ToBase64String(CipherBytes);
- return EncryptedData;
- }
- /// <summary>
- /// Decrypt the specified CipherText.
- /// </summary>
- /// <param name="CipherText">Cipher text.</param>
- public string decrypt(string CipherText)
- {
- //return CipherText;
- //Console.WriteLine ("dec {0}",CipherText);
- //byte[] cipherData = System.Text.Encoding.UTF8.GetBytes(CipherText);
- byte[] decriptedData = Convert.FromBase64String(CipherText);
- MemoryStream ms = new MemoryStream();
- CryptoStream cs = new CryptoStream(ms, this.tDes.CreateDecryptor(), CryptoStreamMode.Write);
- cs.Write(decriptedData, 0, decriptedData.Length);
- cs.FlushFinalBlock();
- byte[] ClearBytes = ms.ToArray();
- ms.Close();
- cs.Close();
- return System.Text.Encoding.UTF8.GetString (ClearBytes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement