We consider a cooperative wireless network, and exploit node cooperation for achieving physical layer based security. The case of one source, multiple cooperating nodes and one eavesdropper is considered. Two different cooperation schemes are considered. In the first scheme, cooperating nodes transmit a weighted version of the source signal in a decode and forward fashion (DF). In the second scheme, while the source is transmitting, cooperating nodes transmit weighted noise to confound the eavesdropper (cooperative jamming (CJ)). The objective is to select the node weights and the source transmit power so that the total transmit power (source transmission power plus cooperating nodes power) under a secrecy capacity constraint is minimized. Previous works related to this problem introduced additional constraints in order to reduce the degree of difficulty, thus resulting in suboptimal solutions. In this paper, the optimal solution is considered. In particular, the closed form solution is obtained for the DF scheme, while for the CJ scheme, the problem is reduced to a univariate optimization one. For the latter problem a convergent algorithm for obtaining the solution is provided.