public static string key = "esgdkcmf";
DES加密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string encryptKeyStr = textBox1.Text; byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, 8)); byte[] keyIv = keyBytes; byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptKeyStr); System.Security.Cryptography.DESCryptoServiceProvider provider = new System.Security.Cryptography.DESCryptoServiceProvider(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(stream, provider.CreateEncryptor(keyBytes, keyIv), System.Security.Cryptography.CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); richTextBox1.Text = Convert.ToBase64String(stream.ToArray());
DES解密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
tring encryptKeyStr = textBox1.Text; byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, 8)); byte[] keyIv = keyBytes; byte[] inputByteArray = Convert.FromBase64String(encryptKeyStr); System.Security.Cryptography.DESCryptoServiceProvider provider = new System.Security.Cryptography.DESCryptoServiceProvider(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(stream, provider.CreateDecryptor(keyBytes, keyIv), System.Security.Cryptography.CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); richTextBox1.Text = Encoding.UTF8.GetString(stream.ToArray());
MD5加密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string encryptKeyStr = textBox1.Text; System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); richTextBox1.Text = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(encryptKeyStr))).Replace("-", "");
RC2加密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string encryptKeyStr = textBox1.Text; byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, 8)); byte[] keyIv = keyBytes; byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptKeyStr); System.Security.Cryptography.RC2CryptoServiceProvider provider = new System.Security.Cryptography.RC2CryptoServiceProvider(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(stream, provider.CreateEncryptor(keyBytes, keyIv), System.Security.Cryptography.CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); richTextBox1.Text = Convert.ToBase64String(stream.ToArray());
RC2解密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string encryptKeyStr = textBox1.Text; byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, 8)); byte[] keyIv = keyBytes; byte[] inputByteArray = Convert.FromBase64String(encryptKeyStr); System.Security.Cryptography.RC2CryptoServiceProvider provider = new System.Security.Cryptography.RC2CryptoServiceProvider(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(stream, provider.CreateDecryptor(keyBytes, keyIv), System.Security.Cryptography.CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); richTextBox1.Text = Encoding.UTF8.GetString(stream.ToArray());
AES加密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string encryptKeyStr = textBox1.Text; byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, 8)); byte[] keyIv = Convert.FromBase64String("Rkb4jvUy/ye7Cd7k89QQgQ=="); byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptKeyStr); System.Security.Cryptography.Rijndael provider = System.Security.Cryptography.Rijndael.Create(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(stream, provider.CreateEncryptor(keyBytes, keyIv), System.Security.Cryptography.CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); richTextBox1.Text = Convert.ToBase64String(stream.ToArray());
AES解密
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string encryptKeyStr = textBox1.Text; byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key.Substring(0, 8)); byte[] keyIv = Convert.FromBase64String("Rkb4jvUy/ye7Cd7k89QQgQ=="); byte[] inputByteArray = Convert.FromBase64String(encryptKeyStr); System.Security.Cryptography.Rijndael provider = System.Security.Cryptography.Rijndael.Create(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Security.Cryptography.CryptoStream cStream = new System.Security.Cryptography.CryptoStream(stream, provider.CreateDecryptor(keyBytes, keyIv), System.Security.Cryptography.CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); richTextBox1.Text = Encoding.UTF8.GetString(stream.ToArray());