views:

484

answers:

1

Hello,

It seems there's no blowfish in C# that would do the same as this one.So I decided to use it as an external and if it doesnt work again then translate the whole blowfish in C#. But first I'll try to use as an external.

Could you take a look at the C++ blowfish and tell me if I have to change the function parameters(some of them are LPBYTE,which is not included in C#).

Also,I'd be thankful if you tell me how to use them as an external dll(I have it compiled as a dll already),but the function parameters in C++ are frustrating me.

Edit: I need to call only Initialize,Encode and Decode.

Thanks in advance!

+2  A: 

I've had a similar problem to this on a previous project. Having looked at the C++ code, it is using ECB as you suspected in your previous post. I think I see the reason why you get different results using Blowfish.NET (Arkain's suggestion). The C++ code casts the inputs into two DWORDs as it enciphers. I believe Blowfish.NET will be doing the right thing by preserving the byte order in the DWORDs it uses internally to encipher.

For example: In the C++ code, the bytes 0102030405060708 become 0x04030201 and 0x08070605. The .NET implementation will be becoming 0x01020304 and 0x05060708.

Dave Cluderay
@Dave Cluderay,Thanks! Can you give me more information about fixing that problem? How to fix the byte order
John
@Dave, I'd very thankful if you could take a look at what i did(check the //comments) http://pastebin.com/m2df92629Eventually,if i did something wrong ,please use pastebin.com to show me how it should be done.Thanks,Dave!
John
OK - see new comments - I think that should be OK.
Dave Cluderay
@Dave,It doesn't work. I also tried passing the bytes in reverse order.Not working either.This is what I'm doing:Encrypt the array in C# and try to decrypt it in C++.The key is the same.Any other suggestions? :(
John
I do apologize - the code we just changed is also called during initialisation - so we have caused a side-effect.
Dave Cluderay
Try changing the EncryptBlock method as shown here: http://pastebin.com/m6b4d8ff8
Dave Cluderay
None of them worked. I tried your way.Then i tried 0,1,2,3,7,6,5,4;3,2,1,0,4,5,6,7;7,6,5,4,1,2,3. Nothing worked.To be honest I tried to rewrite this project in Delphi few months ago ,but i couldn't finish it,because of the same problem - blowfish.I dont want to fail again.Please help,Dave!
John
I made another thread.Now it has a lot more code,should be easier,but it gets even worse though.http://stackoverflow.com/questions/695419/problem-in-calling-a-c-dll-function-from-c
John