我在http://www.broccoliproducts.com/softnotebook/desblowfish/BlowFishCrytography.cs
中找到了这个免费的源代码当我在项目中导入它时,它给了我一些关于
的错误当前上下文中不存在名称“_assertBufferMatch”
当前上下文中不存在名称“_assertBufferMatch”
当前上下文中不存在名称“Trace”
我没有修改所有内容,只是重建项目,然后发生了错误。
这个错误是
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);
}
}
答案 0 :(得分:1)
该代码是模块的单元测试。似乎测试包含在Silverlight中,但Silverlight不包括它所需的_assertBufferMatch
方法。
我会删除该方法以及对它的任何调用。它只能在调试版本中运行,因此算法无法实际工作。