The secrecy rate represents the amount of information per unit time that can be securely sent on a communication link. In this work, we investigate the achievable secrecy rates in an energy harvesting communication system composed of a transmitter, a receiver and a malicious eavesdropper. In particular, because of the energy constraints and the channel conditions, it is important to understand when a device should transmit and to optimize how much power should be used to improve security. Both full knowledge and partial knowledge of the channel are considered under a Nakagami fading scenario. We show that high secrecy rates can be obtained only with power and coding rate adaptation. Moreover, we highlight the importance of optimally dividing the transmission power in the frequency domain, and note that the optimal scheme provides high gains in secrecy rate over the uniform power splitting case. Analytically, we explain how to find the optimal policy and prove some of its properties. In our numerical evaluation, we discuss how the maximum achievable secrecy rate changes according to the various system parameters. Furthermore, we discuss the effects of a finite battery on the system performance and note that, in order to achieve high secrecy rates, it is not necessary to use very large batteries