Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 进程。以md5哈希作为参数开始_C#_Arguments_Md5_Process.start - Fatal编程技术网

C# 进程。以md5哈希作为参数开始

C# 进程。以md5哈希作为参数开始,c#,arguments,md5,process.start,C#,Arguments,Md5,Process.start,我需要MD5散列作为“login”之后的第二个参数 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Security.Crypt

我需要MD5散列作为“login”之后的第二个参数

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security.Cryptography;

namespace LauncherBeta1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            var password = System.Text.Encoding.UTF8.GetBytes(maskedTextBox1.Text);
            var account = System.Text.Encoding.UTF8.GetBytes(textBox1.Text);

            var hmacMD5 = new HMACMD5(password);
            var saltedHash = hmacMD5.ComputeHash(account);

            string[] args = { "login", saltedHash };
            Process.Start("program.exe", String.Join(" ", args));
        }

    }
}

编译器说行
string[]args={“login”,saltedHash}有语法问题。正确的语法是什么?

问题是
ComputeHash
返回的是字节数组,而不是字符串。您需要以某种方式将该字节数组转换为字符串。例如,您可以使用Base64编码:

string[] args = { "login", Convert.ToBase64String(saltedHash) };
但是编码必须是过程所期望的。它很可能期望使用十六进制编码的形式,例如

string hex = BitConverter.ToString(saltedHash).Replace("-", "");
string[] args = { "login", hex };

“正如你所见”-不,不是真的。。。如果您显示了编译器错误,这会有所帮助。但是…我们也无法找到任何信息,因为您没有包含异常详细信息。在方法的内容周围放置一个try catch,并用异常类型和消息或stacktrace编辑您的问题。@Davide:如果有语法错误,就不会有异常,因为它不能运行…对,对。。。所以编译器错误请…我猜是var saltedHash=。。。不要在“saltedHash”中添加字符串,谢谢Jon Skeet!现在开始工作~Edit:我必须将其转换为字符串。