我正在使用WIX和C#自定义操作来解锁产品。 我们计划从旧式修改我们的解锁密钥,如(34450-ee33-8736333-30393)。 你能告诉我哪种算法适合这个吗?提供在线资料来学习这一点很有用 如果您需要任何信息,请告诉我。
答案 0 :(得分:1)
您可以使用System.Net.Security和System.Net.Security.Cryptography中的各种加密类。我特别使用像MD5CryptoServiceProvider这样的类来计算二进制块或文件的哈希值,并输出类似于你提到的摘要的摘要。然后,您可以匹配系统生成的vs用户输入键以激活/解锁您的软件。
以下是我的一项加密工作的示例:
byte[] bytes = System.IO.File.ReadAllBytes(ofd.FileName);
byte[] checksum = null;
if (optMD5.IsChecked==true)
{
MD5 md5 = System.Security.Cryptography.MD5.Create();//.MD5CryptoServiceProvider();
checksum=new byte[1024];
checksum = md5.ComputeHash(bytes);
}
else if (optSHA1.IsChecked == true)
{
SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
checksum = sha1.ComputeHash(bytes);
}
else {
MessageBox.Show("No option selected.");
return;
}
//string schecksum = BitConverter.ToString(checksum);//ASCIIEncoding.ASCII.GetString(checksum);
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sb = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < checksum.Length; i++)
{
sb.Append(checksum[i].ToString("x2"));
}
// Return the hexadecimal string.
//return sb.ToString();
MessageBox.Show("checksum-1 = " + sb.ToString() + Environment.NewLine + "checksum-2 = " + txtChecksum.Text);