Decrypt DES With True Key - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:DES

Description

Decrypt DES With True Key

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.IO;/*from   ww  w . ja va2s  .c  om*/
using System;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        public static string Decrypt3DESWithTrueKey(string sourceStr, string key)
        {
            ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.UTF8.GetBytes(key), Mode = CipherMode.ECB }.CreateDecryptor();
            string str = "";
            try
            {
                byte[] inputBuffer = Convert.FromBase64String(sourceStr);
                str = Encoding.UTF8.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length));
            }
            catch
            {
            }
            return str;
        }
}

Related Tutorials