This is my 3rd thread concerning a blowfish problem in C#.Despite the fact I cannot have blowfish implemented in my application, I decided to use it as an external C++ dll. Please note I've tried Blowfish.NET and any other, the problem is that I'm translating code from C++ to C# and the C# code must do exactly the same as the C++ code does.
So far:
Note the exported functions are in the end of the code
C# code(definition)
[DllImport("TestDLL.dll", EntryPoint = "Initkey" ,ExactSpelling = true , CallingConvention = CallingConvention.Cdecl)] public static unsafe extern void Initkey(byte[] key); [DllImport("TestDLL.dll", EntryPoint = "encode", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] public static unsafe extern void encode(UInt32 *stream);
C# code(function calling)
-Initialize blowfish key
UInt32[] keyarray = new UInt32[2]; //some code Extern.Initkey(Misc.ConvertFromUInt32Array(keyarray)); // // //Helper function used to convert a UInt32 array into Byte array. public static byte[] ConvertFromUInt32Array(UInt32[] array) { List<byte> results = new List<byte>(); foreach (UInt32 value in array) { byte[] converted = BitConverter.GetBytes(value); results.AddRange(converted); } return results.ToArray(); }
-Encode the data.
UInt32[] keyarray2 = new UInt32[2]; //some code unsafe { fixed (UInt32* LPBYTE = keyarray2) { Extern.encode(LPBYTE); } }
After keyarray2 is overwritten by the Encode function, I check the values in the C++ code by decrypting them to make sure everything is alright.
Well, It's not alright.That's my problem, That's why I am asking you for your help.
The values are different when I decrypt them,but If I encrypt them and decrypt them in the C++ source, they are equal.The C++ code is absolutely the same,except that there's no DLL since the code is in C++.
Could that be, because of the Initialize function.I had read a couple of months ago that arrays in C++ are passed as Pointers.I don't believe it,but even so - could that be the problem?
I can't find a clue. I have wasted my life with that blowfish in C#. At least that solution should work, but it doesn't - Why?