Key shr 8 should be portable because it refers to a value in a register not in memory. Compare with C-syntax: i>>8 always shifts out the lowest bits regardless of endianess.

I would try to track down the error by adding logging messages to see exactly where it crashes. Maybe try a version that bypasses encryption and see if it works. Else you might risk keep guessing forever where the problem is