我有一个用 C# 编写的加密工具,它以字符串作为输入。当我在我的 windows 机器上运行编译的 exe 文件时,我得到的输出与我在远程 UNIX 服务器上使用单声道运行它时不同。
这是一个例子:
视窗:
"encrypt.exe 01/01"
Output:
eR4et6LR9P19BfFnhGwPfA==
Unix:
"mono encrypt.exe 01/01"
Output:
Pa8pJCYBN7+U+R705TFq7Q==
我什至尝试将输入值放入脚本中,然后再次编译并运行它,我得到了相同的结果。
解密函数位于远程 Web 服务上,并使用硬编码的密钥和 IV 值(我正在使用这些值进行加密),解密输出:
Input (String generated on windows):
eR4et6LR9P19BfFnhGwPfA==
Output:
01/01
Input (String generated on Unix):
Pa8pJCYBN7+U+R705TFq7Q==
Output:
????1
这是加密函数:
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 stream = new MemoryStream();
Rijndael rijndael = Rijndael.Create();
rijndael.Key = Key;
rijndael.IV = IV;
CryptoStream stream2 = new CryptoStream(stream, rijndael.CreateEncryptor(), CryptoStreamMode.Write);
stream2.Write(clearData, 0, clearData.Length);
stream2.Close();
return stream.ToArray();
}
这是解密函数(我无法对此进行更改):
byte[] cipherData = Convert.FromBase64String(encryptedString);
PasswordDeriveBytes bytes2 = new PasswordDeriveBytes(password, new byte[] { 0x19, 0x76, 0x61, 110, 0x20, 0x4d, 0x65, 100, 0x76, 0x65, 100, 0x65, 0xf6 });
byte[] buffer2 = Decrypt(cipherData, bytes2.GetBytes(0x20), bytes2.GetBytes(0x10));
string output = Encoding.Unicode.GetString(buffer2);
Console.Write(output);
public static byte[] Decrypt(byte[] cipherData, byte[] Key, byte[] IV)
{
MemoryStream stream = new MemoryStream();
Rijndael rijndael = Rijndael.Create();
rijndael.Key = Key;
rijndael.IV = IV;
CryptoStream stream2 = new CryptoStream(stream, rijndael.CreateDecryptor(), CryptoStreamMode.Write);
stream2.Write(cipherData, 0, cipherData.Length);
stream2.Close();
return stream.ToArray();
}