源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c#文本加密程序代码示例

  • 时间:2022-11-03 19:04 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#文本加密程序代码示例
[img]http://files.jb51.net/file_images/article/201311/20131129101326.jpg?20131029101357[/img] 控件滚动方法:
[u]复制代码[/u] 代码如下:
//具体方法 //Movegroup(string u, Panel p1, Panel p2) //Movegroup(方向<或>,被移走的控件,被移入的控件) //注意还要添加两个timer :Return,Next , Interval = 10         public void Movegroup(string u, Panel p1, Panel p2)         {             if (u == ">")     //这是向右,             {                 up1 = p1;                 up2 = p2;                 p2.Visible = true;                 p1.Enabled = false;                 p2.Enabled = false;                 Next.Enabled = true;             }             if (u == "<")             {                 up1 = p1;                 up2 = p2;                 p2.Visible = true;                 p1.Enabled = false;                 p2.Enabled = false;                 Return.Enabled = true;             }         }         Panel up1, up2;         int a = 0;         int b = -580;         int i = 0;         int j = 580;         private void Next_Tick(object sender, EventArgs e)         {             i -= 30;             j -= 30;             up1.Location = new Point(i, up1.Location.Y);             up2.Location = new Point(j, up2.Location.Y);             if (i <= -580 || j <= 0)             {                 Next.Enabled = false;                 up2.Enabled = true;                 up1.Enabled = false;                 up1.Visible = false;                 i = 0;                 j = 580;             }         }         private void Return_Tick(object sender, EventArgs e)         {             a += 30;             b += 30;             up1.Location = new Point(a, up1.Location.Y);             up2.Location = new Point(b, up2.Location.Y);             if (a >= 580 || b >= 0)             {                 Return.Enabled = false;                 up2.Enabled = true;                 up1.Visible = false;                 up1.Enabled = false;                 a = 0;                 b = -580;             }         }
加密原理: 密码+问题+答案的md5 +“/”+加密后的串 组成一个文本文件,(二进制更好了) 解密原理: 先分离出文件里的 密码+问题+答案的md5在与用户输入的密码+问题+答案的md5对比 如果相符则 以此密码解密文件 如果不相符则 提示密码问题及答案错误 我使用DES加密,这是一个类
[u]复制代码[/u] 代码如下:
namespace Pd_kernel {     public class Encrypt     {         /// <summary>         /// 进行DES加密。         /// </summary>         /// <param name="pToEncrypt">要加密的字符串。</param>         /// <param name="sKey">密钥,且必须为8位。</param>         /// <returns>以Base64格式返回的加密字符串。</returns>         public static string DESEncrypt(string pToEncrypt, string sKey)         {             using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())             {                 byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);                 des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);                 des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);                 System.IO.MemoryStream ms = new System.IO.MemoryStream();                 using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))                 {                     cs.Write(inputByteArray, 0, inputByteArray.Length);                     cs.FlushFinalBlock();                     cs.Close();                 }                 string str = Convert.ToBase64String(ms.ToArray());                 ms.Close();                 return str;             }         }         /// <summary>         /// 进行DES解密。         /// </summary>         /// <param name="pToDecrypt">要解密的以Base64</param>         /// <param name="sKey">密钥,且必须为8位。</param>         /// <returns>已解密的字符串。</returns>         public static string DESDecrypt(string pToDecrypt, string sKey)         {             byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);             using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())             {                 des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);                 des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);                 System.IO.MemoryStream ms = new System.IO.MemoryStream();                 using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))                 {                     cs.Write(inputByteArray, 0, inputByteArray.Length);                     cs.FlushFinalBlock();                     cs.Close();                 }                 string str = Encoding.UTF8.GetString(ms.ToArray());                 ms.Close();                 return str;             }         }         public static string MD5encrypt(string text, string method)         {             string strMD5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text, method);             return strMD5;         }     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部