It needs to be an OEM Subaru key and the dealer will need ALL keys when one is replaced.
Subaru keys have transponders that need to match the immobilizer while programming .
A used fob is possible (if it works) but needs to be opened to access the 8 digit code for programming.
OR
Purchase expensive equipment to program the key. The dealer will need to access the PIN code with the proper credentials.
With the PIN code, keys can be programmed.
Been there, done that.