Encryption and Decryption in c# windows form application

encrypt and decrypt string class Simple and common method to encrypt and decrypt string in c# windows form application class which allows only authorized parties to view content protect data.
Pass plain text to decrypt , algorithm technique used to encrypt and decrypt, using cryptography algorithm sample code snippets will protect the confidentiality of data , privacy and authority.





Encryption Online with Key

encryption Online free

Encryption Online with Key, available in this site for common person encryptonline.ecomparefiles.com to convert classified plaintext information to protected ciphertext which cannot read by human.

Download

Example Source Snippets - encryptAndDecrypt.zip

namespace : using System.Security.Cryptography

Class encrypt and decrypt


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace encryptAndDecrypt
{
    public class Encryptor
    {       
        private static readonly byte[] _key = { 0xF1, 0x46, 0xA6, 0xBB, 0xA2, 0x5A, 0x37, 0x6F, 0x81, 0x2E, 0x17, 0x41, 0x72, 0x2C, 0x43, 0x27 };      

        private static readonly byte[] _initVector = { 0xE1, 0xF1, 0xA6, 0xBB, 0xA9, 0x5B, 0x31, 0x2F, 0x81, 0x2E, 0x17, 0x4C, 0xA2, 0x81, 0x53, 0x61 };

        protected internal static string Encrypt(string value)
        {
            if (string.IsNullOrEmpty(value))
                return string.Empty;

            byte[] Value = Encoding.UTF8.GetBytes(value);
            SymmetricAlgorithm mCSP = new RijndaelManaged();
            mCSP.Key = _key;
            mCSP.IV = _initVector;
            using (ICryptoTransform ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write))
                    {
                        cs.Write(Value, 0, Value.Length);
                        cs.FlushFinalBlock();
                        cs.Close();
                        return Convert.ToBase64String(ms.ToArray());
                    }
                }
            }
        }

        protected internal static string Decrypt(string Value)
        {
            SymmetricAlgorithm mCSP;
            ICryptoTransform ct = null;
            MemoryStream ms = null;
            CryptoStream cs = null;
            byte[] byt;
            byte[] _result; mCSP = new RijndaelManaged();
            try
            {
                mCSP.Key = _key;
                mCSP.IV = _initVector;
                ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV);
                byt = Convert.FromBase64String(Value);
                ms = new MemoryStream();
                cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
                cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock();
                cs.Close();
                _result = ms.ToArray();
            }
            catch (Exception ex)
            {
                _result = null;
                throw ex;
            }
            finally
            {
                if (ct != null)
                    ct.Dispose();

                if (ms != null)
                    ms.Dispose();

                if (cs != null)
                    cs.Dispose();
            }
            return ASCIIEncoding.UTF8.GetString(_result);
        }
    }
}
       

C# Windows Application


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace encryptAndDecrypt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            if (rchInputEncrypt.Text != "")
                rchOutPut.Text = Encryptor.Encrypt(rchInputEncrypt.Text);
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            if (rchInputDecrypt.Text != "")
                rchOutPut.Text = Encryptor.Decrypt(rchInputDecrypt.Text);
        }       
    }
}
       

Parent Comment shyam Aug 17 2019
http://www.encryptonline.ecomparefiles.com/ Perfect online tool to Encrypt online
Reply  Cancel


smartsnipps.ecomparefiles.com © 2019, All Rights Reserved | Disclaimer: smartsnipps.eCompareFiles.com is free to use any code snippets without guarantee