I have the following function:
Code:
public static void Des(byte[] key, byte[] inBuf, byte[] outBuf)
{
if (key.Length != 8 || inBuf.Length != 8 || outBuf.Length != 8)
{
throw new Exception("Des: Buffer or key length incorrect.");
}
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = key;
des.Mode = CipherMode.ECB;
ICryptoTransform encryptor = des.CreateEncryptor();
byte[] tmpBuf = encryptor.TransformFinalBlock(inBuf, 0, 1);
tmpBuf.CopyTo(outBuf, 0);
}
if I call it with some standard test data like so:
Code:
byte[] outBuf;
MyClass.Des(new byte[] { 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
new byte[] { 0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62 },
out outBuf);
I do not get the expected output of
Code:
{ 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 }
instead I get
Code:
{ 0xC6, 0x61, 0x8D, 0x63, 0x0B, 0x39, 0x31, 0xB0 }
am I doing something wrong?
I've even tried reversing the byte order of the test data, and I don't get the right result. I've tested the same data using C++ with CryptoPP on Linux, and I get the expected result, but I'm porting this code to run on .Net, and this is my main stoppage in the process at the moment.