河豚在C# [英] Blowfish in C#

查看:126
本文介绍了河豚在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C ++程序使用标准的blowfish。



我的C#程序使用Blowfish加密算法从这里



这两个应用程序都做同样的事情:接收数据包,加密然后将其发回。如果服务器识别数据包正常 - 它发送另一个数据包,否则关闭套接字。我遵循C ++和C#中的所有函数,除了加密之外,一切都是一样的。



在C ++文件中,我只有一个加密。但是,在C#Blowfish中我有




  • BlowfishCBC

  • BlowfishCFB

  • BlowfishECB

  • BlowfishSimple



我不知道哪一个是在我的C ++项目中,所以我随机选择了 BlowfishECB 。但它不工作,服务器(我没有访问它)不能识别数据包加密。



我的问题:有一个标准Blowfish for C#或者如果这是唯一的,我如何解决这个问题?
EDIT:



C ++ blowfish代码

不,C#没有标准的河豚。它会使用你告诉它的任何一个。
(编辑:我想我误解了,如果你想要一个符合C#标准的blowfish,我会推荐Bouncy Castle Crypto,它是一个来自Java的端口,包含大多数RFC标准。例如如何使用类。每当我使用它最后的文档缺乏,但单元测试是很好的例子,如何适合在一起。)



问题你想知道你的C ++应用程序正在使用的Blowfish的风味。你在C ++应用程序中使用什么库来进行加密?一旦你知道,那么你可以在你的C#应用​​程序中做出正确的选择。



我个人最遇到CBC。 简单可能值得尝试。



你还必须处理一些事情,例如确保你的初始化向量匹配,取决于你使用哪一个。 p>

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.

解决方案

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.

这篇关于河豚在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆