嗨即时通讯使用C#和我制作加密器/解密器和我的解密按钮不起作用它启动正常,但当我点击按钮似乎没有发生帮助 [英] Hi im using C# and im making a encryptor/decryptor and my decrypt button doesnt work it starts up fine but when I click the button nothing seems to happen help
本文介绍了嗨即时通讯使用C#和我制作加密器/解密器和我的解密按钮不起作用它启动正常,但当我点击按钮似乎没有发生帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码按钮2无效但在启动时出现
this is my code button 2 doesnt work but appears when it starts
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
推荐答案
请参阅以下MSDN文章。它有一个使用Triple DES加密加密和解密的示例 - 它是一个命令行应用程序,但您应该能够根据需要进行编辑。
Rfc2898DeriveBytes Class(System.Security.Cryptography) [ ^ ]
亲切的问候
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
引用:
可以使用更新的哈希函数,例如安全哈希算法SHA-256和SHA-512。考虑使用SHA256类或SHA512类而不是MD5CryptoServiceProvider类。仅使用MD5CryptoServiceProvider与遗留应用程序和数据兼容。
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.
这篇关于嗨即时通讯使用C#和我制作加密器/解密器和我的解密按钮不起作用它启动正常,但当我点击按钮似乎没有发生帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文