找传奇、传世资源到传世资源站!

C# MD5/DES/RSA 加密、解密的实现 实例源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C# MD5/DES/RSA 加密、解密的实现 实例源码 C#网络编程-第1张C# MD5/DES/RSA 加密、解密的实现 实例源码 C#网络编程-第2张 C# MD5/DES/RSA 加密、解密的实现 实例源码 C#网络编程-第3张
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 Encoder{ public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void rdbDESDecrypt_CheckedChanged(object sender, EventArgs e) { this.btnDESEncryptOrDecrypt.Text = this.rdbDESDecrypt.Text; } private void rdbDESEncrypt_CheckedChanged(object sender, EventArgs e) { this.btnDESEncryptOrDecrypt.Text = this.rdbDESEncrypt.Text; } private void rdbRSADecrypt_CheckedChanged(object sender, EventArgs e) { this.btnRSAEncryptOrDecrypt.Text = this.rdbRSADecrypt.Text; } private void rdbRSAEncrypt_CheckedChanged(object sender, EventArgs e) { this.btnRSAEncryptOrDecrypt.Text = this.rdbRSAEncrypt.Text; } private void btnEncrypt_Click(object sender, EventArgs e) { string sourceText = string.Empty;//明文 string ciphertext = string.Empty;//密文 sourceText = this.txtMD5SourceText.Text;//获取明文 ciphertext = Encoder.MD5Encrypt(sourceText);//加密并获得密文 this.txtMD5Ciphertext.Text = ciphertext; } private void btnDESEncryptOrDecrypt_Click(object sender, EventArgs e) { /* * DES 加密 & 解密 */ string sourceText = this.txtDESSourceText.Text; string key = this.txtDESKey.Text; if (string.IsNullOrEmpty(sourceText)) { MessageBox.Show("源文本不能为空。"); return; } if (string.IsNullOrEmpty(key)) { MessageBox.Show("密钥不能为空。"); return; } string targetText = string.Empty; if (this.rdbDESEncrypt.Checked) { /* DES 加密 */ try { targetText = Encoder.DESEncrypt(sourceText, key); } catch (Exception ex) { MessageBox.Show("加密失败!\r\nError:" ex.Message); } } else { /* DES 解密 */ try { targetText = Encoder.DESDecrypt(sourceText, key); } catch (Exception ex) { MessageBox.Show("解密失败!\r\nError:" ex.Message); } } this.txtDESTargetText.Text = targetText; } private void btnRSAEncryptOrDecrypt_Click(object sender, EventArgs e) { /* * RSA 加密 & 解密 */ string sourceText = this.txtRSASourceText.Text; string key = this.txtRSAKey.Text; if (string.IsNullOrEmpty(sourceText)) { MessageBox.Show("源文本不能为空。"); return; } if (string.IsNullOrEmpty(key)) { MessageBox.Show("密钥不能为空。"); return; } string targetText = string.Empty; if (this.rdbRSAEncrypt.Checked) { /* RSA 加密 */ try { targetText = Encoder.RSAEncrypt(sourceText, key); } catch (Exception ex) { MessageBox.Show("解密失败!\r\nError:" ex.Message); } } else { /* RSA 解密 */ try { targetText = Encoder.RSADecrypt(sourceText, key); } catch (Exception ex) { MessageBox.Show("解密失败!\r\nError:" ex.Message); } } this.txtRSATargetText.Text = targetText; } private void btnCreateKeys_Click(object sender, EventArgs e) { CreateRSAKeysForm f = new CreateRSAKeysForm(); f.ShowDialog(); } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复