C ++河豚工作与较少的字母,但C#河豚不 [英] C++ blowfish works with fewer letters,but C# blowfish doesn't

查看:235
本文介绍了C ++河豚工作与较少的字母,但C#河豚不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++ blowfish支持加密小于< 8个字母,而.NET没有。为什么?



- > C#NET Blowfish < -
- > C ++ Blowfish < - p>

在C ++和C#应用程序中,我加密以下数组

  byte response [6] = 
{
0x00,0x80,0x01,0x61,0x05,0x06
};

在C ++和C#应用程序中,我使用相同的参数调用Encrypt函数。

  C ++ 
Blowfish.Encrypt((LPBYTE)responce + 2,(LPBYTE)responce + 2,4);

C#
Blowfish.Encrypt(responce,2,responce,2,responce.Length - 2);但是,在C ++中,我得到的数据是加密的,但不是在C#中。








C#NET Blowfish 中的第45,47和49行是有问题的行,在第45行的计算 - 结果变为0.线47变成2 + 0 = 2,线49 2不小于2,所以没有循环。





我的问题是,在C#中,填充必须与C ++完全相同,所以我得到一个有效的答案。我不能使用随机填充,然后删除无用的字节解密后,因为服务器我发送加密的数组不是我的。



你能指出我在C ++中使用padding的方法,以及如何在C#NET中实现。



//注意我需要

解决方案



您粘贴的代码(不推荐使用SO,顺便说一下,因为你的粘贴会被删除,如果没有人读了一段时间,从而留下这个问题)在其标题注释说:

  ///请注意,字节数必须调整为算法的块大小。 

(第3和4行)。



这个C ++代码似乎填充了空字节,注释说:

  //用空字节填充数据结束以完成加密

这将有助于看到C ++函数 GetOutputLength(),看看它如何处理大小不足的输入。我想它向上舍入,但很高兴验证。


a C++ blowfish supports encrypting a block with less than < 8 letters,while .NET doesn't.Why?

-->C# NET Blowfish<-- -->C++ Blowfish<--

In both C++ and C# applications,I encrypt the following array

    byte response[6] = 
	{
		0x00, 0x80, 0x01, 0x61, 0x05, 0x06
	};

In both C++ and C# applications,I call the Encrypt function with same parameters.

C++
Blowfish.Encrypt((LPBYTE)responce + 2,(LPBYTE)responce + 2, 4);

C#
Blowfish.Encrypt(responce, 2, responce, 2, responce.Length - 2);

However,In C++ I get the data encrypted,but not in C#.

Line 45,47 and 49 in C# NET Blowfish are the problematic lines,after the calculation at line 45 - the result becomes 0. line 47 becomes 2 + 0 = 2 and line 49 2 is not less than 2,so there's no loop.

There's some padding in C++ blowfish,but I get lost when I try to understand it.

My problem is that in C#, the padding must be exactly the same as in C++,so I get a valid answer.I can't use random padding and then remove the useless bytes after decryption,because the server I send the encrypted array is not mine.

Could you point me to what padding is used in the C++ blowfish and how it should be implemented in C# NET.

//Note I need not send this packet multiple times,only one time.

Thanks in advance!

解决方案

The code you pastebinned (not recommended for SO by the way, as your paste will be removed if noone reads it in a while, thereby leaving this question broken) says in its header comment:

/// Note that the number of bytes must be adjusted to the block size of the algorithm.

(lines 3 and 4). So it seems to be behaving to spec, if it ignores your undersized data.

The C++ code seems to be padding with null bytes, the comment says:

// pad end of data with null bytes to complete encryption

It would be helpful to see the C++ function GetOutputLength(), to see how it handles undersized inputs. I guess it rounds upwards, but it would be nice to verify.

这篇关于C ++河豚工作与较少的字母,但C#河豚不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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