CSharp examples for System.Security.Cryptography:DES
Encrypt String with DES
using System.Security.Cryptography; using System.IO;/*from w ww . ja va 2 s . c o m*/ using System.Text; using System; public class Main{ private static DESCryptoServiceProvider desCSP = new DESCryptoServiceProvider(); public static string Encrypt(string input) { byte[] Key = Encoding.UTF8.GetBytes(strKey); byte[] IV = Encoding.UTF8.GetBytes(strIV); byte[] byt = Encoding.UTF8.GetBytes(input); ICryptoTransform ct = desCSP.CreateEncryptor(Key, IV); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Convert.ToBase64String(ms.ToArray()); } }