How to Encrypt and Decrypt a String in C#

By FoxLearn 11/20/2024 1:09:05 PM   7.56K
The Eramake.eCryptography library provides a simple way to encrypt and decrypt strings in C#.

It's particularly useful for scenarios like protecting sensitive data in Windows Forms applications.

Open Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "EncryptDecryptDemo" and then click OK

You can install the Eramake.eCryptography library via NuGet Package Manager

Right click on your project select Manage NuGet Packages -> Search eramake.ecryptography -> Install

eramake.ecryptography

Drag and drop the Label, TextBox and Button controls from Visual Toolbox onto your form designer, then you can design your form as shown below.

encrypt decrypt in c#

You can easily integrate this into a Windows Forms application by adding TextBox controls for input/output and Buttons for actions as shown below.

using System;
using System.Windows.Forms;

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

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            // Encrypt the input text
            txtEncrypt.Text = Eramake.eCryptography.Encrypt(txtValue.Text);
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            // Decrypt the encrypted text
            txtDecrypt.Text = Eramake.eCryptography.Decrypt(txtEncrypt.Text);
        }
    }
}

With these steps, you can easily encrypt and decrypt strings using the Eramake.eCryptography library in a C# Windows Forms application.

VIDEO TUTORIAL