Des中包含中文文字加密

///


    /// DES加密
    ///

    /// 要加密的字符串字符串
    /// 密钥
    ///
    public static string EncEncrypt(string encryptString, string key)
    {
        byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
        byte[] keyIV = keyBytes;
        byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
        DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
        MemoryStream mStream = new MemoryStream();
        CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
        cStream.Write(inputByteArray, 0, inputByteArray.Length);
        cStream.FlushFinalBlock();
        return Convert.ToBase64String(mStream.ToArray());
    }

你可能感兴趣的:(C#)