tags:

views:

2896

answers:

1

My C++ program is using a standard blowfish.

My C# program is using the Blowfish encryption algorithm from here.

Both applications (TCP Clients) do the same thing: receive a packet, encrypt it and then send it back. If the server recognises the packet as normal - it sends another packet, otherwise it closes the socket. I followed all functions in C++ and C# and everything is the same except the encryption.

In the C++ file I have only one encryption. However, in the C# Blowfish I have

  • BlowfishCBC
  • BlowfishCFB
  • BlowfishECB
  • BlowfishSimple

I didn't know which one is the one in my C++ project, so I randomly picked BlowfishECB. But it doesn't work, the server (I don't have access to it) doesn't recognize the packet as encrypted.

My question: Is there a standard Blowfish for C# or if this is the only one, how do I solve this problem? EDIT:

The C++ blowfish code can be seen here.

+2  A: 

No, there is not a standard blowfish for C#. It will use whichever you tell it to. (Edit: I think I misunderstood. If you want a standards compliant blowfish for C#, I would recommend Bouncy Castle Crypto. It is a port from Java and contains most documented RFC standards. Take a look at the unit tests for examples of how to use the classes. Whenever I used it last the documentation was lacking, but the unit tests are pretty good examples of how things fit together.)

The question you want to ask is which flavour of Blowfish your C++ application is using. What library are you using in the C++ application to do your encryption? Once you know that, then you can make the correct choice in your C# application.

I personally encounter CBC the most. "Simple" would probably be worth trying to.

You will also have to deal with things like making sure your initialization vector matches up depending on which one you use.

AaronLS
@aaronls,you can see the C++ blowfish code here: http://pastebin.com/m178ea218
John
I don't think it's CBC or CFB, because in the loop in Encode it uses 8 bytes at a time, and doesn't seem to use any data from the previous iteration of the loop. I.e. a CBC or CFB would take data from the previous block that was encoded and use it in the next block.
AaronLS
What's the problem then? I used ECB and the server cannot recognize it.
John
Maybe it's the "Simple" mode, never heard of that it. One or the other may be non-standard. Something maybe somebody cooked up that follows the general algorithm of blowfish, but doesn't include all the little pieces of meta-data that most standards define.
AaronLS
This will be standards compliant on the C# side:http://www.mobilefish.com/developer/bouncycastle/bouncycastle.html
AaronLS
I tried them all,aarnols. None of them worked.As for the encryption from bauncycastle.com - http://pastebin.com/m7cab286bWhere's the Encode/Encrypt function?!
John
I've answered this on your other thread: http://stackoverflow.com/questions/694454/how-to-use-blowfish-in-c-as-an-external-dll-in-c
Dave Cluderay