Encryption of data traffic in a network is essential since it is vulnerable to eavesdropping. The security of data traffic becomes important since the communications over open network occur frequently. This paper focuses on encryption of plain text using a stream cipher method. However, the keys for encryption are generated using a swarm intelligence approach. Swarm intelligence is the emergent collective intelligence of groups of simple autonomous agents. The Ant Colony Optimization key Generation Algorithm (AKGA) is a novel approach to generate keystream for encrypting the plain text. The advantage of this approach is that it reduces the number of keys to be distributed. Experimental results demonstrating AKGA's encrypting plain text of different lengths and the comparison of its performance with other stream cipher methods are presented. Copyright © 2009 John Wiley & Sons, Ltd.