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

CSharp examples for System.Security.Cryptography:DES

Description

Encrypt DES With True Key

Demo Code


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

public class Main{
        public static string Encrypt3DESWithTrueKey(string sourceStr, string key)
        {
            ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.UTF8.GetBytes(key), Mode = CipherMode.ECB }.CreateEncryptor();
            byte[] bytes = Encoding.UTF8.GetBytes(sourceStr);
            return Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length));
        }
}

Related Tutorials