DES Decrypt Text - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:DES

Description

DES Decrypt Text

Demo Code


using System.Globalization;
using System.Text;
using System.Security.Cryptography;
using System.IO;/*from   w  ww.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 DecryptText(string input,
            Byte[] desKey, Byte[] desIV)
        {
            
            if (input.Length % 2 == 1) throw new ApplicationException("Invalid encrypted input format");
            
            MemoryStream fin = new MemoryStream();
            MemoryStream fout = new MemoryStream();

            for (int ii=0; ii<= input.Length-1;ii+=2){
                try
                {
                    fin.WriteByte(Byte.Parse(input.Substring(ii,2),NumberStyles.AllowHexSpecifier));
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Invalid input", ex);
                }
            }

            return "";
        }
}

Related Tutorials