There's no settled legal answer to this, but there seems to be a general consensus that this would not be legal under the Impeachment Clause, which says:
The President ... shall have Power to grant Reprieves and Pardons for Offenses against the United States, except in Cases of Impeachment.
There would be two main issues here:
1. Can a president pardon himself?
It's never been tried, so it's never been challenged, so the courts have never had a chance to say whether it's legal.
The main argument in favor of self-pardons is that the constitution grants broad pardon authority for any offense against the United States, making an exception for impeachment, but not for self-pardons. The response to that is that the constitution uses all kinds of broad language that everyone agrees is not as broad as it sounds; Congress is not allowed to abridge the freedom of speech, but perjury laws are nonetheless constitutional.
There are several theories as to why the self-pardon would be illegal, but they mostly come down to two main ideas -- that our legal system does not permit anyone to be the arbiter of their own case, and that a person subject to impeachment may not be pardoned.
2. Can a president issue secret pardons?
Again, it's never been tried, so it's never been challenged, so the courts have never had a chance to say whether it's legal.
And again, the primary argument in favor of secret pardons is that the Pardon Clause grants broad pardon authority without requiring that pardons be publicized. The main arguments against are (1) that presidential pardons are inherently public acts, as they have no effect if the justice system doesn't know about them, and (2) that the Presidential Records Act requires official White House records to be transferred to the National Archives.