I have an encryption tool written in C# that take a string as input. When i run the compiled exe file on my windows machine i get an output that is different from when i run it on the remote UNIX server using mono.
Here is an example:
Windows:
"encrypt.exe 01/01"
Output:
eR4et6LR9P19BfFnhGwPfA==
Unix:
"mono encrypt.exe 01/01"
Output:
Pa8pJCYBN7+U+R705TFq7Q==
I even tried to put the input value in the script and then compile and run it again, and i got the same results.
The decrypt function is located on a remote web service and uses hard coded key and IV values (I'm using those values to encrypt), Decryption output:
Input (String generated on windows):
eR4et6LR9P19BfFnhGwPfA==
Output:
01/01
Input (String generated on Unix):
Pa8pJCYBN7+U+R705TFq7Q==
Output:
????1
This is the encryption function:
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();
}
This is the decryption function (i cannot make changes to this):
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();
}
clearData
is the same on both platform. Are you sure it is the case? Also I hope you don't use a constant IV outside of your examples... – Elastomer