2012-08-23 33 views
0

我找到了這個免費的源代碼在http://www.broccoliproducts.com/softnotebook/desblowfish/BlowFishCrytography.csC#如何在Silverlight中使用河豚?

當我進口它在我的項目,它給了我一定的誤差約

名稱「_assertBufferMatch」在目前情況下

將不存在名「_assertBufferMatch」不在當前情況下存在

「追蹤」並沒有在目前情況下

我沒有修改的電郵裏的名字非常重要,只是重建項目,然後發生錯誤。

此錯誤之一是

 public static void Test() 
     { 

      // Declaration of local variables 
      Random rnd = new Random(1); 
      byte[] Key = null; 
      byte[] bufferIn = null; 
      byte[] bufferOut = null; 
      byte[] bufferReturned = null; 

      // Loop through the test vectors 
      for (int iTest = 0; iTest < TestKeys.Length; iTest++) 
      { 

       // Load the key and plain-text 
       Key = BitConverter.GetBytes(TestKeys[iTest]).Reverse().ToArray(); 
       bufferIn = BitConverter.GetBytes(TestPlainText[iTest]).Reverse().ToArray(); 

       // Encrypt with BlowFish 
       BlowFishCrytography.BlowFish(bufferIn, ref bufferOut, Key, true); 

       // Compare with expected result 
       byte[] expectedBufferOut = BitConverter.GetBytes(TestCypherText[iTest]).Reverse().ToArray(); 
       _assertBufferMatch(expectedBufferOut,bufferOut); 

      } 

      // Loop through decrypt-encrypt tests 
      for (int iTest = 0; iTest < 100*1000; iTest++) 
      { 

       // Dump progress 
       if ((iTest % 100) == 0) 
        Trace.TraceInformation("Test {0}", iTest); 

       // Load the key and plain-text 
       Key = CreateBlowFishKey(rnd, MAX_KEY_BYTE_LENGTH); 

       // Create a buffer of data 
       int iLength = rnd.Next(1, 10*1024); 
       _softCreateBuffer(ref bufferIn, iLength); 
       rnd.NextBytes(bufferIn); 

       // Encrypt with BlowFish 
       BlowFishCrytography.BlowFishWithPadding(bufferIn, ref bufferOut, Key, true); 

       // Decrypt with BlowFish 
       BlowFishCrytography.BlowFishWithPadding(bufferOut, ref bufferReturned, Key, false); 

       // Compare buffers 
       _assertBufferMatch(bufferIn, bufferReturned); 

      } 

     } 

回答

1

該代碼是用於該模塊的單元測試。看起來這個測試包含在Silverlight中,但它所需的_assertBufferMatch方法被排除在Silverlight之外。

我只是刪除方法和任何調用它。它只能在調試版本中運行,所以算法不需要實際工作。