This also solves the mystery of the redundant code from Bouncy Castle. Bouncy Castle's RSA decryption method returns a new array and the code then copied it into a new block. Pointy Castle creates a block and passes it into the RSA decryption method to populate, so no copying was/is required. But the Bouncy Castle code does more than just copying the bytes: it is also taking care of the situation when the decrypted bytes is shorter than expected.
Note: the encryption code was correct. Only the decryption code had a bug.
Bug fix for "RSA with OAEP fails nondeterministically" https://github.com/PointyCastle/pointycastle/issues/177 issue.
This also solves the mystery of the redundant code from Bouncy Castle. Bouncy Castle's RSA decryption method returns a new array and the code then copied it into a new block. Pointy Castle creates a block and passes it into the RSA decryption method to populate, so no copying was/is required. But the Bouncy Castle code does more than just copying the bytes: it is also taking care of the situation when the decrypted bytes is shorter than expected.
Note: the encryption code was correct. Only the decryption code had a bug.