The NXP microcontroller stores it in encrypted eeprom.
Electronics Forums get a lot of requests for help to find the code in keys and key fobs of luxury cars. I've never figured out why people don't ask how to find the code for a Chevy, Ford or Citroen or Honda. The luxury car keys and key fobs cost the same at a dealer for a luxury car as a they do for a mid-priced car. I'd assume that people who truly own luxury cars can better afford a key replacement than those who buy chevys and fords. Right? It seems to me that something nefarious is behind these requests because it is always a Mercedes, BMW, Audi or Land Rover "owner" that that needs key help.