Vehicular Ad Hoc Networks (VANETs), which have the strategic goal of ensuring service delivery on roads and smart cities, are made up of a number of critical components, including the integration and communication between vehicles, sensors, and stationary road-side components. VANETs have many distinctive characteristics, including quick movable nodes, self-organization, scattered networks, and often changing topologies. Since attack prevention is still a contentious topic, security, data integrity, and user private information continue to be major concerns despite the recent development of VANETs. In particular, detecting Sybil attacks, in which one node attempts to appear as many, seemingly conflicts with the goal of privacy preservation, and existing schemes fail on either one or both accounts. In order to prevent Sybil attacks, VANETs assert that they have security measures in place. A new framework for VANET security and sybil attack detection was developed in this study. It groups the cars together using Kernel k-harmonic means (KKHM). Kernel functions are here included into the k-means problem's cost function via kernelizing in the feature space. Cluster centres are believed to exist in a higher level Hilbert space called the feature space. Using the Floyd-Warshall algorithm (FWA), cluster heads are chosen. The Deep Neural Network (DNN) is used to identify the malicious CH by extracting the necessary information from the CH. For the purpose of optimizing DNN parameters, a new technique known as gradient-based elephant herding optimization (GBEHO) is presented. To initialize the population in the search space, the gradient-based method GBO is paired with the elephant optimization algorithm (EHO). Second, by including Gaussian chaos mapping, the initialized population is enhanced in order to correct the disparity between the first exploration and utilization of the EHO. Additionally, two operators are programmed to modify the agents' position update strategy: the random wandering and variation operators. Last but not least, the Modified Advanced Encryption Standard (MAES) is used to send the data in the CH safely to the cloud. According on experimental findings, the suggested model increases the security rate of 96% and reduces the encryption time of 19(s) for 100 (kb) data which is better when compared to other existing models.