DES Encrypt Text - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:DES

Description

DES Encrypt Text

Demo Code


using System.Globalization;
using System.Text;
using System.Security.Cryptography;
using System.IO;/*from w w w  .  j a  v  a 2 s.c o m*/
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        public static string EncryptText(string input,
            Byte[] desKey, Byte[] desIV)
        {            
            MemoryStream fin = new MemoryStream();
            MemoryStream fout = new MemoryStream();

            foreach (char c in input.ToCharArray())
            {
                fin.WriteByte((Byte)Convert.ToInt32(c));
            }

            fin.Seek(0, SeekOrigin.Begin);

            EncryptData(fin, fout, desKey, desIV);

            fout.Seek(0, SeekOrigin.Begin);

            string ret = "";

            for (long ii = 0; ii<= fout.Length-1; ii++){
                ret += fout.ReadByte().ToString("X2");
            }

            return ret;
        }
}

Related Tutorials