using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace Windowscsharpone
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
key = "a1ccada";
}
string key;
private void Form4_Load(object sender, EventArgs e)
{
}
private string criptog(string textto,string strhash)
{
TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] byehash, byteText;
byehash = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(strhash));
byteText = UTF8Encoding.UTF8.GetBytes(textto);
tdsp.Key = byehash;
tdsp.Mode = CipherMode.ECB;
return
Convert.ToBase64String( tdsp.CreateEncryptor().TransformFinalBlock(byteText,0,byteText.Length));
}
private string descriptog(string textto, string strhash)
{
TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] byehash, byteText;
byehash = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(strhash));
byteText =Convert.FromBase64String(textto);
tdsp.Key = byehash;
tdsp.Mode = CipherMode.ECB;
return
UTF8Encoding.UTF8.GetString(tdsp.CreateDecryptor().TransformFinalBlock(byteText, 0, byteText.Length));
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("请输入字符串");
}
textBox2.Text = criptog(textBox1.Text,key);
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = descriptog(textBox2.Text,key);
}
}
}
(责任编辑:admin) |