如何在C ++中使用河豚作为C#中的外部dll [英] How to use blowfish in C++ as an external dll in C#

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

问题描述

似乎C#中没有河豚可以和这一个一样.所以我决定将其用作外部对象,如果不能再次使用,则将整个河豚用C#转换. 但是首先,我将尝试用作外部对象.

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.

您能看看 C ++河豚并告诉我是否必须更改函数参数(其中一些是LPBYTE,不包含在C#中.)

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#).

此外,如果您告诉我如何将它们用作外部dll(我已经将其编译为dll)表示感谢,但是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.

修改: 我只需要调用Initialize,Encode和Decode.

I need to call only Initialize,Encode and Decode.

提前谢谢!

推荐答案

在上一个项目中,我遇到了与此类似的问题. 看完C ++代码后,它正在使用ECB,就像您在上一篇文章中所怀疑的那样. 我想我明白了使用Blowfish.NET(Arkain的建议)获得不同结果的原因. C ++代码在加密时将输入转换为两个DWORD.我相信Blowfish.NET将通过在其内部用于加密的DWORD中保留字节顺序来做正确的事.

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.

例如: 在C ++代码中,字节0102030405060708变为0x04030201和0x08070605. .NET实现将变为0x01020304和0x05060708.

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

这篇关于如何在C ++中使用河豚作为C#中的外部dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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