小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

DESC加密解密

 shymi 2010-09-17
        /// <summary>
        /// 對數(shù)據(jù)進行加密
        /// </summary>
        /// <param name="encryptstring">需要加密的數(shù)據(jù)</param>
        /// <returns></returns>
        public string DESEncrypt(string encryptstring)
        {
            string strRtn;
            try
            {
                DESCryptoServiceProvider desc = new DESCryptoServiceProvider();   //des進行加密
                PasswordDeriveBytes encryptkey = new PasswordDeriveBytes(encryptstring, null);//產(chǎn)生key
                byte[] key = encryptkey.GetBytes(8);
                byte[] data = System.Text.Encoding.Unicode.GetBytes(encryptstring);//取到密碼的字節(jié)流
                MemoryStream ms = new MemoryStream();                            //用來存儲加密后的數(shù)據(jù)                           
                CryptoStream cs = new CryptoStream(ms, desc.CreateEncryptor(key, key), CryptoStreamMode.Write); //進行加密
                cs.Write(data,0,data.Length );
                cs.FlushFinalBlock();                                            //用緩沖區(qū)的當前狀態(tài)更新基礎數(shù)據(jù)源或存儲庫,隨后清除緩沖區(qū)
                strRtn = Convert.ToBase64String(ms.ToArray());                   //將整個流內(nèi)容寫入字節(jié)數(shù)組,轉(zhuǎn)換到字符串返回
                return strRtn;
            }
            catch (Exception ex)
            {
                //彈出捕獲的異常信息
                MessageBox.Show("錯誤:"+ex.Message ,"錯誤消息提示框",MessageBoxButtons.OKCancel,MessageBoxIcon.Error );
                return null ;
            }
        }
        /// <summary>
        /// 對數(shù)據(jù)進行解密
        /// </summary>
        /// <param name="decryptstring">需要解密的數(shù)據(jù)</param>
        /// <returns></returns>
        public string DESDecrypt(string decryptstring)
        {
            string strRtn;
            try
            {
                //定義訪問數(shù)據(jù)加密標準(DES)算法的加密服務提供程序(CSP)版本的包裝對象
                DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
                PasswordDeriveBytes encryptkey = new PasswordDeriveBytes(decryptstring, null);//產(chǎn)生key
                byte[] key = encryptkey.GetBytes(8);
                byte[] data = Convert.FromBase64String(decryptstring);
                MemoryStream ms = new MemoryStream();                            //用來存儲解密后的數(shù)據(jù)                           
                CryptoStream cs = new CryptoStream(ms, desc.CreateEncryptor(key, key), CryptoStreamMode.Write);
                cs.Write(data, 0, data.Length);                                  //進行解密
                cs.FlushFinalBlock();                                            //用緩沖區(qū)的當前狀態(tài)更新基礎數(shù)據(jù)源或存儲庫,隨后清除緩沖區(qū)
                strRtn = System.Text.Encoding.Unicode.GetString(ms.ToArray());   //將整個流內(nèi)容寫入字節(jié)數(shù)組
                return strRtn;
            }
            catch (Exception ex)
            {
                //彈出捕獲的異常信息
                MessageBox.Show("錯誤:" + ex.Message, "錯誤消息提示框", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return null;
            }
        }

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約