我需要将MD5哈希作为“登录”之后的第二个参数。
以下是代码:
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 };
有语法问题。什么是正确的语法?
答案 0 :(得分:2)
问题是ComputeHash
返回一个字节数组,而不是字符串。您需要以某种方式将该字节数组转换为字符串。例如,您可以使用Base64编码:
string[] args = { "login", Convert.ToBase64String(saltedHash) };
但编码需要是进程所期望的。它可能需要一个十六进制编码的形式,例如
string hex = BitConverter.ToString(saltedHash).Replace("-", "");
string[] args = { "login", hex };