I have some ASP NET Core middleware which does this, too (great minds and all that). The entire thing is open source and available at GitHub. It even has a default builder which will supply the recommended header values.
Interestingly, I would avoid HPKP as it has been deprecated
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.