国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

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

2020-01-24 03:02:52
字體:
來源:轉載
供稿:網友


控件滾動方法:

復制代碼 代碼如下:

//具體方法
//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加密,這是一個類

復制代碼 代碼如下:

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;
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵州省| 莱芜市| 湛江市| 三台县| 平凉市| 稷山县| 达孜县| 海丰县| 宁夏| 巴林右旗| 平凉市| 五家渠市| 温宿县| 浑源县| 长宁区| 镇远县| 赫章县| 邻水| 黎平县| 绍兴县| 临漳县| 泾阳县| 阳江市| 达拉特旗| 中山市| 策勒县| 山西省| 虞城县| 霍城县| 拉孜县| 嘉义县| 台安县| 友谊县| 宿州市| 仪征市| 栾城县| 那坡县| 金山区| 本溪市| 收藏| 岢岚县|