The recent advances in integrated circuit technologies, microprocessor hardware, wireless communications, embedded systems and technologies as well as the emergence of Ad-hoc networking, made up the concept of wireless sensor networks. Regarding the nature of sensors and the nature of the environment of deployment sensor networks are exposed to many attacks more than any other networks, therefore new strategies and protocols of security must be defined for these networks taking into consideration the characteristics of sensors as well as the architecture of the network. In this paper we propose a lightweight implementation of public key infrastructure called cluster based public infrastructure (CBPKI), CBPKI is based on the security and the authenticity of the base station for executing a set of handshakes intended to establish session keys between the base station and sensors over the network used for ensuring data confidentiality and integrity.