Due to the lack of end to end connection in Opportunistic networks (OppNets), messages are sent from a node to another, from a source to a destination, opportunistically. The methodology of selecting the next intermediate nodes and providing security and privacy for nodes are the main challenging issues in designing an opportunistic network. In this paper, we propose a secure structure for OppNets wherein nodes can decide to carry a message without knowledge about the sender, destination, and intermediate nodes. While all nodes are not truthful in the network, a trust structure, a cooperation method, and a sharing public key approach are proposed. Furthermore, a routing algorithm is introduced to choose the best available nodes for forwarding messages. The proposed routing algorithm provides identity and location privacy for all nodes. The proposed structure offers messages confidentiality, data integrity, and privacy protection. Also, it resists against selfish and selective dropping attacks, and could prevent Sybil attacks. The simulation results illustrate that the proposed algorithm improves the performance of the network in terms of better message delivery and less network overhead, latency, and messages drop.