2011-10-04 131 views
-1

我真的覺得自己很蠢張貼這一點,但因爲我得到了我的問題沒有答案,我仍然初級程序員,我會發布此:密鑰生成方法?

 //List of keys 
     byte[] Key0 = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; //mode 10 = 0 
     byte[] Key1 = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 }; // i + 2 
     byte[] Key2 = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }; // i mode 2 = 0 
     byte[] Key3 = { 66, 77, 88, 99, 111, 222, 110, 112, 114, 115 }; // mode 11 = 0 
     byte[] Key4 = { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121 }; //x^2 
     byte[] Key5 = { 6,17,34,57,86,121,162,209 }; //3x^2+2x+1 
     byte[] Key6 = { 77,78,79,80,81,82,83,84,85,86,87 }; // only in range 
     //Add all keys to the list 
     List<byte[]> oKeysList = new List<byte[]>(); 
     oKeysList.Add(Key0); 
     oKeysList.Add(Key1); 
     oKeysList.Add(Key2); 
     oKeysList.Add(Key3); 
     oKeysList.Add(Key4); 
     oKeysList.Add(Key5); 
     oKeysList.Add(Key6); 

     Random oRandom = new Random(); 
     //Generate random key index to be used in the encryption 
     int ListSelectedIndex = oRandom.Next(0, oKeysList.Count); 
     byte[] GeneratedKey = oKeysList[ListSelectedIndex]; 
     //Generate 3 random number from the selected key and concate the key index to it 
     byte[] GeneratedBytes = new byte[4]; 
     for (int i = 0; i < 3; i++) 
     { 
      GeneratedBytes[i] = GeneratedKey[oRandom.Next(0,GeneratedKey.Length)]; 
     } 
     //Add the list of key index 
     GeneratedBytes[3] = (byte)ListSelectedIndex; 
     //Return the genreated bytes 
     return GeneratedBytes; 

正如你看到我和一個8個字節一起生成此4字節數組從RNG密碼學生成,當我想檢查我的序列我採取最後4個字節,並使用它們之間的數學關係,我想生成很多連續並能夠檢查它們是否有效。我知道它的安全性可能很老,所以如果有人能夠幫助我或爲我的代碼添加任何東西,或者建議任何新的東西,我會非常感激。

+0

嘗試http://codereview.stackexchange.com/ –

+0

如果不知道您想要驗證的內容以及原因,很難提供任何建議。 –

回答

1

我不確定任何人都會在這裏分析你的代碼。我建議如下:不要讓軟件保護過於複雜。它不會對盜版產生重大影響,但100%會影響購買軟件的人。儘可能簡化您的軟件保護機制。