Security plays a vital role in communication networks. Since the nodes are mobile in Mobile Ad-hoc Networks (MANET), they are vulnerable to different types of attacks. Because of its mobility nature any node can enter the network at any time based on the coverage of the network. No centralized mechanism is found to verify or authenticate the nodes that are arriving/leaving the network. An algorithm is proposed for secure communication between source and destination based on the QoS parameters is called Modified Device Key Generation Algorithm (MDKGA). This algorithm elects an agent node based on the QoS parameters. Agent node is responsible for secure key generation and distribution of keys among the nodes. The neighboring node selection is based on trust value which acts as a heuristic function to select the node using A* algorithm.Various performance metrics are also analyzed. Comparison study has been carried out between the protocols of MANET.