unify and DRY out PKEy's to_pem impl