影子博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

// 调用方法
string password = DateBasicInfo.ConDb.DesEncrypt(txtPassword.Text.Trim(), "ILOVEYOU");

    /// <summary>
    /// 加密
    /// </summary>
    /// <param name="strText"></param>
    /// <param name="strEncrKey"></param>
    /// <returns></returns>
    public static string DesEncrypt(string strText, string strEncrKey)
    {
        byte[] byKey = null;
        byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, strEncrKey.Length));
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());


        }
        catch
        {
            return "";
        }
    }
posted on 2016-02-17 15:14  影子博客  阅读(478)  评论(0编辑  收藏  举报