A method for networking between devices, comprising: establishing, by a router A, a WiFi connection to a device C to constitute a WiFi network; sending, by the router A, information about a detected nearby device B to the device C, wherein the information about the device B comprises a Service Set Identifier, SSID, of the device B; receiving, by the router A, a first message sent by the device C, wherein the first message carries the information about the device B, and the first message is used to instruct the router A to add the device B to the WiFi network; obtaining, by the router A, a public key of the device B; and sending, by the router A, a second message to the device B after receiving the first message sent by the device C, wherein the second message carries an SSID and a password of the router A, and the second message is used to instruct the device B to use the SSID and the password of the router A to connect to the router A, so as to join the WiFi network, wherein the password carried in the second message is encrypted by using the public key of the device B; wherein the obtaining, by the router A, a public key of the device B comprises: receiving, by the router A, a beacon frame that is broadcast by the device B, wherein a Vendor Specific field of the beacon frame carries the public key of the device B; or sending, by the router A, a probe request frame to the device B, to request to obtain the public key of the device B, and receiving, by the router A, a probe response frame returned by the device B after the device B receives the probe request frame, wherein a Requested information elements field of the probe response frame carries the public key of the device B. establishing, by a router A, a WiFi connection to a device C to constitute a WiFi network; sending, by the router A, information about a detected nearby device B to the device C, wherein the information about the device B comprises a Service Set Identifier, SSID, of the device B; receiving, by the router A, a first message sent by the device C, wherein the first message carries the information about the device B, and the first message is used to instruct the router A to add the device B to the WiFi network; obtaining, by the router A, a public key of the device B; and sending, by the router A, a second message to the device B after receiving the first message sent by the device C, wherein the second message carries an SSID and a password of the router A, and the second message is used to instruct the device B to use the SSID and the password of the router A to connect to the router A, so as to join the WiFi network, wherein the password carried in the second message is encrypted by using the public key of the device B; wherein the obtaining, by the router A, a public key of the device B comprises: receiving, by the router A, a beacon frame that is broadcast by the device B, wherein a Vendor Specific field of the beacon frame carries the public key of the device B; or sending, by the router A, a probe request frame to the device B, to request to obtain the public key of the device B, and receiving, by the router A, a probe response frame returned by the device B after the device B receives the probe request frame, wherein a Requested information elements field of the probe response frame carries the public key of the device B.