欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2013年11月29日 10:15:14   作者:  
這是一個加密軟件,但只限于文本加密,加了窗口控件的滑動效果,詳細(xì)看下面的代碼


控件滾動方法:

復(fù)制代碼 代碼如下:

//具體方法
//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 +“/”+加密后的串 組成一個文本文件,(二進(jìn)制更好了)

解密原理:

先分離出文件里的 密碼+問題+答案的md5在與用戶輸入的密碼+問題+答案的md5對比

如果相符則 以此密碼解密文件

如果不相符則 提示密碼問題及答案錯誤

我使用DES加密,這是一個類

復(fù)制代碼 代碼如下:

namespace Pd_kernel
{
    public class Encrypt
    {
        /// <summary>
        /// 進(jìn)行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>
        /// 進(jìn)行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;
        }
    }
}

相關(guān)文章

  • c#檢測文本文件編碼的方法

    c#檢測文本文件編碼的方法

    這篇文章主要介紹了c#檢測文本文件編碼的方法
    2016-03-03
  • Unity實(shí)現(xiàn)毫秒延時回調(diào)功能

    Unity實(shí)現(xiàn)毫秒延時回調(diào)功能

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)毫秒延時回調(diào)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Unity3D繪制地形的實(shí)現(xiàn)方法

    Unity3D繪制地形的實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了Unity3D繪制地形的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • c#顯示當(dāng)前在線人數(shù)示例

    c#顯示當(dāng)前在線人數(shù)示例

    這篇文章主要介紹了c#顯示當(dāng)前在線人數(shù)的示例,需要的朋友可以參考下
    2014-02-02
  • 支持多類型數(shù)據(jù)庫的c#數(shù)據(jù)庫模型示例

    支持多類型數(shù)據(jù)庫的c#數(shù)據(jù)庫模型示例

    本文為大家提供一個c#數(shù)據(jù)庫訪問模型,支持多類型數(shù)據(jù)庫,簡單抽取數(shù)據(jù)庫訪問函數(shù),大家參考使用吧
    2014-01-01
  • C#中正則表達(dá)式(Regex)過濾內(nèi)容的基本使用方法

    C#中正則表達(dá)式(Regex)過濾內(nèi)容的基本使用方法

    在 Regex 類中提供了很多方法來操作正則表達(dá)式,這篇文章主要給大家介紹了關(guān)于C#中正則表達(dá)式(Regex)過濾內(nèi)容的基本使用方法,需要的朋友可以參考下
    2022-08-08
  • C#中DataTable實(shí)現(xiàn)篩選查詢的示例

    C#中DataTable實(shí)現(xiàn)篩選查詢的示例

    本文主要介紹了C#中DataTable實(shí)現(xiàn)篩選查詢的示例,主要是DataTable進(jìn)行過濾篩選,常用的一些方法為:Select,dataview,具有一定的參考價值,感興趣的可以了解一下
    2023-04-04
  • C#讀寫Excel的流程步驟

    C#讀寫Excel的流程步驟

    這篇文章主要介紹了詳解C#讀寫Excel的流程步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起來學(xué)習(xí)吧
    2023-12-12
  • C#實(shí)現(xiàn)裝飾器模式

    C#實(shí)現(xiàn)裝飾器模式

    這篇文章介紹了C#實(shí)現(xiàn)裝飾器模式的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-07-07
  • C#算法之整數(shù)反轉(zhuǎn)

    C#算法之整數(shù)反轉(zhuǎn)

    這篇文章介紹了C#算法之整數(shù)反轉(zhuǎn),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01

最新評論