C# 如何使用质询密钥进行MD5加密

C# 如何使用质询密钥进行MD5加密,c#,authentication,encryption,md5,challenge-response,C#,Authentication,Encryption,Md5,Challenge Response,我正在尝试使用MD5身份验证建立与服务器的连接。 服务器将质询密钥返回给我。 如何使用它加密密码并将其发送回服务器。 目前我知道的加密方法需要密码散列、Salt密钥和VI代码。 我怎样才能做到 static readonly string PasswordHash = "PasswordHash"; static readonly string SaltKey = "SaltKey"; static readonly string VIKey = "@1B2c3D4e5F

我正在尝试使用MD5身份验证建立与服务器的连接。 服务器将质询密钥返回给我。 如何使用它加密密码并将其发送回服务器。 目前我知道的加密方法需要密码散列、Salt密钥和VI代码。 我怎样才能做到

    static readonly string PasswordHash = "PasswordHash";
    static readonly string SaltKey = "SaltKey";
    static readonly string VIKey = "@1B2c3D4e5F6g7H8";

    public static string Encrypt(string plainText)
    {
        byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

        byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
        var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
        var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));

        byte[] cipherTextBytes;

        using (var memoryStream = new MemoryStream())
        {
            using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
            {
                cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                cryptoStream.FlushFinalBlock();
                cipherTextBytes = memoryStream.ToArray();
                cryptoStream.Close();
            }
            memoryStream.Close();
        }
        return Convert.ToBase64String(cipherTextBytes);

你能更清楚地说明你需要做什么吗?通常,您只需使用challange密钥+密码来创建md5哈希,然后将其发送回服务器。。。但我不确定这就是你想要的,不管你想实现什么,都要直截了当,糟糕透顶。只需1)获取垃圾桶2)将所有加密代码放入3)获取SSL即可