C# 进程。以md5哈希作为参数开始
我需要MD5散列作为“login”之后的第二个参数 代码如下: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
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:我必须将其转换为字符串。