The embodiment of the invention discloses a key agreement method, which comprises sending a client calling message to a server, receiving information returned by the server, including key agreement mode of a code mechanism based on user's identity, receiving a server key exchange message sent by the server, obtaining a master key, and sending a client key exchange message to the server. The embodiment of the invention further discloses an another key agreement method, which comprises receiving a client calling message sent by a client terminal, selecting ciphertex family using the key agreement mode of the code mechanism based on user's identity from a ciphertext family list, and then sending to a client, sending a server key exchange message to the client, receiving a client key exchange message sent by the client, and obtaining a master key according to information carried in the client key exchange message. The invention further discloses a system used for the key agreement, and a relative client and a server, which can make the process of the key agreement more rapid, safer and more highly-effective.