One well-known technological advancement that significantly impacts many things is the Internet of Things (IoT). These include connectivity, work, healthcare, and the economy. IoT can improve life in many situations, including classrooms and smart cities, through work automation, increased output, and decreased worry. However, cyberattacks and other risks significantly impact intelligent Internet of Things applications. Key generation is essential in information security and the various applications that use a distributed system, networks, or Internet of Things (IoT) systems. Several algorithms have been developed to protect IoT applications from malicious attacks; since IoT devices usually have small memory resources and limited computing and power resources, traditional key generation methods are inappropriate because they require high computational power and memory usage. This paper proposes a method of Dynamic Key Generation Method (DKGM) to overcome the difficulty using a specific chaotic map called the Zaslavskii Map and a swarm intelligent algorithm for optimization called Grey Wolf Optimizer (GWO). DKGM's ability to generate several groups-seed numbers using the Zaslavskii map depends on various initial parameters. GWO selects strong generated numbers depending on the randomness test as a fitness function. Three wolfs GWα, GWβ, and GWΩ, are used to simulate the behavior of a pack of grey wolves when attacking prey. The speed and position of each wolf are updated depending on the best three wolves. Finally, use the sets GWα in the round, GWβ in the subkey, and GWΩ in shifting operations of the Chacha20 hash function. The dynamic procedure was used to improve the high-security analysis of the DKGM approach over earlier methods. Simulations show that the suggested method is preferable for IoT applications.