Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code button 2 doesnt work but appears when it starts

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        byte[] encrypted;
        private void button1_Click(object sender, EventArgs e)
        {
            TripleDESCryptoServiceProvider triple = new TripleDESCryptoServiceProvider();
            UTF8Encoding u = new UTF8Encoding();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            triple.Key = md5.ComputeHash(u.GetBytes(textBox1.Text));
            triple.Mode = CipherMode.ECB;
            triple.Padding = PaddingMode.PKCS7;
            ICryptoTransform trans = triple.CreateEncryptor();
            encrypted = trans.TransformFinalBlock(u.GetBytes(textBox2.Text), 0, u.GetBytes(textBox2.Text).Length);
            textBox3.Text = BitConverter.ToString(encrypted);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            TripleDESCryptoServiceProvider triple = new TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            UTF8Encoding u = new UTF8Encoding();
            triple.Key = md5.ComputeHash(u.GetBytes(textBox1.Text));
            triple.Mode = CipherMode.ECB;
            triple.Padding = PaddingMode.PKCS7;
            ICryptoTransform trans = triple.CreateDecryptor();
            textBox5.Text = u.GetString(trans.TransformFinalBlock(encrypted, 0, encrypted.Length));
        }
    }
}


What I have tried:

many things i have tried but no result
Posted
Updated 6-Feb-18 22:50pm
v2

Refer the following MSDN article. It has an example that encrypts and decrypts using Triple DES encryption - it is a command line application but you should be able to edit as required.

Rfc2898DeriveBytes Class (System.Security.Cryptography)[^]

Kind Regards
 
Share this answer
 
Quote:
Newer hash functions such as the Secure Hash Algorithms SHA-256 and SHA-512 are available. Consider using the SHA256 class or the SHA512 class instead of the MD5CryptoServiceProvider class. Use MD5CryptoServiceProvider only for compatibility with legacy applications and data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900