Answers for "how to decrypt in c#"

C#
0

how to decrypt in c#

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace encrypt_decrypt_string
{
    class Program
    {
        static string Decrypt()
        {
            try
            {
                string textToDecrypt = "v1JvjRGYn+g+4H/KjszL/g==";
                string ToReturn = "";
                string publickey = "12345678";
                string secretkey = "87654321";
                byte[] privatekeyByte = { };
                privatekeyByte = System.Text.Encoding.UTF8.GetBytes(secretkey);
                byte[] publickeybyte = { };
                publickeybyte = System.Text.Encoding.UTF8.GetBytes(publickey);
                MemoryStream ms = null;
                CryptoStream cs = null;
                byte[] inputbyteArray = new byte[textToDecrypt.Replace(" ", "+").Length];
                inputbyteArray = Convert.FromBase64String(textToDecrypt.Replace(" ", "+"));
                using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
                {
                    ms = new MemoryStream();
                    cs = new CryptoStream(ms, des.CreateDecryptor(publickeybyte, privatekeyByte), CryptoStreamMode.Write);
                    cs.Write(inputbyteArray, 0, inputbyteArray.Length);
                    cs.FlushFinalBlock();
                    Encoding encoding = Encoding.UTF8;
                    ToReturn = encoding.GetString(ms.ToArray());
                }
                return ToReturn;
            }
            catch (Exception ae)
            {
                throw new Exception(ae.Message, ae.InnerException);
            }
        }
        static void Main(string[] args)
        {
            string decrypted = Decrypt();
            Console.WriteLine(decrypted);
        }
    }
}
Posted by: Guest on October-13-2021

Code answers related to "how to decrypt in c#"

C# Answers by Framework

Browse Popular Code Answers by Language