This is from the NH state website:
Can I vote in a primary if I am an undeclared voter?
Yes. An undeclared voter may vote in a state primary or a presidential primary. You will be required to choose either a Democratic or Republican ballot when you go to vote. The last day a registered voter can change their party affiliation before the 2024 Presidential Primary is October 6, 2023. The last day a registered voter can change their party affiliation before the 2024 State Primary is June 4, 2024. Supervisors are required to meet on that day at least between 7:00 - 7:30 p.m. to accept party changes.
I know that you said a demonrat can't vote in the republican primary in NH. It seems to be a growing practice, at least in some states, for folks to temporarily change to unaffiliated or to the other party to vote in the other party's primary, and then to change back to their party of choice.
www.sos.nh.gov
In Alaska, as a registered "unaffiliated", I was able to choose to vote in the Republican primary. Because I never desired to, I'm not sure if I could have chosen to vote in the demonrat primary there.
Here in Cowboy Country, as an unaffiliated voter, I can't vote in the primary of any party.