Merge pull request #3935 from paul-elliott-arm/fix_pem_write_2_16

Backport 2.16: Remove Extraneous bytes from buffer post pem write