【问题标题】:Generate the Unlock key [closed]生成解锁密钥[关闭]
【发布时间】:2012-07-25 10:51:48
【问题描述】:

我正在使用 WIX 和 C# 自定义操作来解锁产品。 我们计划从旧样式修改我们的解锁密钥,例如 (34450-ee33-8736333-30393)。 你能告诉我哪种算法适合这个吗?提供在线资料来学习这一点会很有用。
如果您需要任何信息,请告诉我。

【问题讨论】:

    标签: c# .net wix


    【解决方案1】:

    您可以在 System.Net.Security 和 System.Net.Security.Cryptography 中使用各种加密类。我特别使用了像 MD5CryptoServiceProvider 这样的类来计算二进制块或文件的哈希值,并输出类似于您提到的摘要。然后,您可以匹配系统生成的与用户输入的键来激活/解锁您的软件。

    这是我的密码学工作中的一个示例:

                    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      相关资源
      最近更新 更多