A key obtaining method, comprising: receiving, by a target access and mobility management function entity, a first message for registering a terminal device; sending, by the target access and mobility management function entity based on the first message, a second message to a source access and mobility management function entity; wherein the second message includes an identifier of the terminal device; obtaining, by the source access and mobility management function entity, a first key through derivation based on a key shared between the source access and mobility management function entity and the terminal device; sending, by the source access and mobility management function entity, a third message to the target access and mobility management function entity; wherein the third message carries the first key; receiving, by the target access and mobility management function entity, the third message from the source access and mobility management function entity; determining, by the target access and mobility management function entity based on security related information, whether to use the first key; and when the target access and mobility management function entity determines to use the first key, determining, by the target access and mobility management function entity, a communication key between the target access and mobility management function entity and the terminal device based on the first key, and sending, to the terminal device, a non access stratum security mode command, NAS SMC, that carries indication information, wherein the indication information is used to indicate the terminal device to derive the first key. receiving, by a target access and mobility management function entity, a first message for registering a terminal device; sending, by the target access and mobility management function entity based on the first message, a second message to a source access and mobility management function entity; wherein the second message includes an identifier of the terminal device; obtaining, by the source access and mobility management function entity, a first key through derivation based on a key shared between the source access and mobility management function entity and the terminal device; sending, by the source access and mobility management function entity, a third message to the target access and mobility management function entity; wherein the third message carries the first key; receiving, by the target access and mobility management function entity, the third message from the source access and mobility management function entity; determining, by the target access and mobility management function entity based on security related information, whether to use the first key; and when the target access and mobility management function entity determines to use the first key, determining, by the target access and mobility management function entity, a communication key between the target access and mobility management function entity and the terminal device based on the first key, and sending, to the terminal device, a non access stratum security mode command, NAS SMC, that carries indication information, wherein the indication information is used to indicate the terminal device to derive the first key.