我需要登录散列是“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 };行有一个语法问题。正确的语法是什么?
发布于 2011-06-29 02:23:10
问题是ComputeHash返回的是字节数组,而不是字符串。您需要以某种方式将该字节数组转换为字符串。例如,您可以使用Base64编码:
string[] args = { "login", Convert.ToBase64String(saltedHash) };但编码需要是进程所需的任何编码。它很可能会使用十六进制编码的形式,例如
string hex = BitConverter.ToString(saltedHash).Replace("-", "");
string[] args = { "login", hex };https://stackoverflow.com/questions/6511235
复制相似问题