A method of generating a key for Device-to-Device (D2D) communication between a first user equipment and a second user equipment, characterized in that the method comprises: receiving, by a first radio access node a request for D2D key generation from the first user equipment which is served by the first radio access node; determining, by the first radio access node, whether the second user equipment is served by the first radio access node; when it is determined that the second user equipment is served by the first radio access node, generating, by the first radio access node, a first random number and a second random number; generating, by the first radio access node, a first D2D key based on the first random number and a second D2D key based on the second random number; sending, by the first radio access node, the first D2D key and the second random number to the second user equipment, wherein the second random number is used by the second user equipment to generate the second D2D key, and the first D2D key is used together with the generated second D2D key to generate a third D2D key; and sending, by the first radio access node, the second D2D key and the first random number to the first user equipment, wherein the first random number is used by the first user equipment to generate the first D2D key, and the second D2D key is used together with the generated first D2D key to generate the third D2D key; and when it is determined that the second user equipment is not served by the first radio access node, determining, by the first radio access node, a second radio access node which serves the second user equipment; generating, by the first radio access node, a first random number; generating, by the first radio access node, a first D2D key based on the first random number; sending, by the first radio access node, the first D2D key to the second radio access node; receiving, by the first radio access node, a second D2D key from the second radio access node; and sending, by the first radio access node, the second D2D key and the first random number to the first user equipment, wherein the first random number is used by the first user equipment to generate the first D2D key, and the second D2D key is used together with the generated first D2D key to generate a third D2D key. receiving, by a first radio access node a request for D2D key generation from the first user equipment which is served by the first radio access node; determining, by the first radio access node, whether the second user equipment is served by the first radio access node; when it is determined that the second user equipment is served by the first radio access node, generating, by the first radio access node, a first random number and a second random number; generating, by the first radio access node, a first D2D key based on the first random number and a second D2D key based on the second random number; sending, by the first radio access node, the first D2D key and the second random number to the second user equipment, wherein the second random number is used by the second user equipment to generate the second D2D key, and the first D2D key is used together with the generated second D2D key to generate a third D2D key; and sending, by the first radio access node, the second D2D key and the first random number to the first user equipment, wherein the first random number is used by the first user equipment to generate the first D2D key, and the second D2D key is used together with the generated first D2D key to generate the third D2D key; and when it is determined that the second user equipment is not served by the first radio access node, determining, by the first radio access node, a second radio access node which serves the second user equipment; generating, by the first radio access node, a first random number; generating, by the first radio access node, a first D2D key based on the first random number; sending, by the first radio access node, the first D2D key to the second radio access node; receiving, by the first radio access node, a second D2D key from the second radio access node; and sending, by the first radio access node, the second D2D key and the first random number to the first user equipment, wherein the first random number is used by the first user equipment to generate the first D2D key, and the second D2D key is used together with the generated first D2D key to generate a third D2D key.