2012-07-25 136 views
-2

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

+0

'BOOL的IsValid {返回true;}' – CodesInChaos 2012-07-25 11:19:28

回答

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