aspnet/DataProtection

Why is key ID not written in big endian order?

Closed this issue · 1 comments

In KeyRingBasedDataProtector.cs, the key ID is written using Write32bitAlignedGuid. Since a Guid is internally 1 int, 2 shorts, and 8 bytes, the Guid

00112233445566778899aabbccddeeff

is thus written

33221100554477668899aabbccddeeff

Whereas, other integers are written in big endian order. Why is a Guid written in this order?

The short answer is "that's just how Windows has always done it." Even on big-endian platforms, the field layout of the GUID structure is modified so that its logical layout in memory continues to be little-endian. This provides compatibility between the data across architectures.