0

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

            }

        }
4

1 回答 1

1

该代码是模块的单元测试。似乎该测试包含在 Silverlight 中,但_assertBufferMatch它所需的方法不包含在 Silverlight 中。

我只会删除该方法和对它的任何调用。它只会在调试版本中运行,因此算法不需要实际工作。

于 2012-08-23T01:31:30.673 回答