1

I am trying to do the following regarding my specification:

The sales counter with the number of bytes N is starting with byte 0 in the BIG ENDIAN format stored as a two's complement representation ("signed"). N corresponds the number of bytes required to encode the sales counter. To have to At least 5 bytes / 40 bits are used for the revenue counter.

and for this i have created the following code in C#

private static byte[] EncodeUmsatz(long umsatz)
{
    // This gives an 8-byte array
    byte[] umsatzBytes = BitConverter.GetBytes(umsatz);
    // Pad with zeroes to get 16 bytes
    int length = 16 * ((umsatzBytes.Length + 15) / 16);
    Array.Resize(ref umsatzBytes, length);
    // reverse to get big-endian array
    Array.Reverse(umsatzBytes, 0, umsatzBytes.Length);
    return umsatzBytes;
}

The Property IsLittleEndian of the BitConverter is false. So this should be right, or?

But the Test with an external tool says

"The calculated sales counter does not match the encrypted sales counter (see the DECRYPTED_TURNOVER_VALUE parameter), please check the sales counter encoding (BIG endian, two's complement) or the AES key used."

What I do not know if my code makes a two's complement representation?

I am not the specialist with bytes so has someone an idea what I can try

Aria
  • 3,724
  • 1
  • 20
  • 51

1 Answers1

0

so the problem is solved - the c# code is correct for big endian - the problem was the value for the input parameter was wrong