# Stream ciphering

This chapter is dedicated to the stream ciphering, which is a subpart of the standard security module.

## Stream cipher

A stream cipher is an object that encodes an input stream into an output stream. The data are read from the input stream, encoded and transmitted onto the output stream. There are basically two types of stream ciphers known as symmetric cipher and asymmetric cipher.

## Symmetric cipher

A symmetric cipher is a cipher that encodes and decode data with the same key. Normally, the key is kept secret, and the data are encoded by block. For this reason, symmetric cipher are also called block cipher. In normal mode, a symmetric cipher is created with key and the data are encoded from an input stream as long as they are available. The block size depends on the nature of the cipher. As of today, the recommended symmetric cipher is the Advanced Encryption Standard or AES, also known as Rijndael.

## Asymmetric cipher

An asymmetric cipher is a cipher that encodes and decode data with two keys. Normally, the data are encoded with a public key and decoded with a private key. In this model, anybody can encode a data stream, but only one person can read them. Obviously, the model can be reverse to operate in a kind of signature mode, where only one person can encode the data stream and anybody can read them. Asymmetric cipher are particularly useful when operating on unsecured channels. In this model, one end can send its public key as a mean for other people to crypt data that can only be read by the sender who is supposed to have the private key. As of today, the recommended asymmetric ciphers are RSA and DH.

## Cipher base class

The `Cipher` base class is an abstract class that supports both symmetric and asymmetric cipher models. A cipher object has a name and is bound to a key that is used by the cipher. The class provides some base methods that can be used to retrieve some information about the cipher. The `get-name` method returns the cipher name. The `set-key` and `get-key` methods are both used to set or retrieve the cipher key.

The cipher operating mode can be found with the `get-reverse` method. If the `get-reverse` method returns true, the cipher is operating in decoding mode. Note that a `set-reverse` method also exists.