Blowfish in C#

泪湿孤枕 提交于 2019-12-12 18:07:29

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/694331/blowfish-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!