There is an APDU command just for that: PUT KEY
PUT KEY
You can read up all the details in the GlobalPlatform Card Specification, https://globalplatform.org/specs-library/