小编use*_*247的帖子

加密功能在Windows和unix上提供不同的输出

我有一个用C#编写的加密工具,它以字符串作为输入.当我在我的Windows机器上运行已编译的exe文件时,我获得的输出与使用mono在远程UNIX服务器上运行时的输出不同.

这是一个例子:

视窗:

"encrypt.exe 01/01"
Output:
eR4et6LR9P19BfFnhGwPfA==
Run Code Online (Sandbox Code Playgroud)

Unix的:

"mono encrypt.exe 01/01"
Output:
Pa8pJCYBN7+U+R705TFq7Q==
Run Code Online (Sandbox Code Playgroud)

我甚至试图将输入值放在脚本中,然后再次编译并运行它,我得到了相同的结果.

decrypt函数位于远程Web服务上,使用硬编码密钥和IV值(我使用这些值进行加密),解密输出:

Input (String generated on windows):
eR4et6LR9P19BfFnhGwPfA==
Output:
01/01

Input (String generated on Unix):
Pa8pJCYBN7+U+R705TFq7Q==
Output:
????1
Run Code Online (Sandbox Code Playgroud)

这是加密功能:

string text = args[0];
byte[] clearData = Encoding.Unicode.GetBytes(text);
PasswordDeriveBytes bytes = new PasswordDeriveBytes(password, new byte[] { 0x19, 0x76, 0x61, 110, 0x20, 0x4d, 0x65, 100, 0x76, 0x65, 100, 0x65, 0xf6 });
string a = Convert.ToBase64String(Encrypt(clearData, bytes.GetBytes(0x20), bytes.GetBytes(0x10)));
Console.Write(a);

public static byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)
{
    MemoryStream …
Run Code Online (Sandbox Code Playgroud)

.net c# encryption mono rijndael

7
推荐指数
1
解决办法
1372
查看次数

标签 统计

.net ×1

c# ×1

encryption ×1

mono ×1

rijndael ×1