> For the complete documentation index, see [llms.txt](https://akushwarrior2.gitbook.io/pointycastle-a-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://akushwarrior2.gitbook.io/pointycastle-a-guide/internals/stream-ciphers.md).

# Stream Ciphers

Everything you need to know about PointyCastle's stream ciphers.

PointyCastle, as of now, supports three stream ciphers: ChaCha20 (original implementation), ChaCha20 (RFC-7539 implementation), and Salsa20. The parameters each needs are below in table form.

| Cipher     | IV? (Length)  | Key Length |
| ---------- | ------------- | ---------- |
| Salsa20    | Yes, 8 bytes  | 32 bytes   |
| ChaCha20   | Yes, 8 bytes  | 32 bytes   |
| ChaCha7539 | Yes, 12 bytes | 32 bytes   |

Because these are stream ciphers, no padding is necessary; each cipher can process any amount of data.

Constructing these algorithms is done either via the registry or via the class itself (see [External API ](/pointycastle-a-guide/external-api/registry-vs.-classes.md)for more):

```dart
var salsa20 = StreamCipher('Salsa20'); //With registry
var chacha20 = ChaCha20Engine();
```

&#x20;If you are using one of the ChaCha ciphers, you may also select the number of rounds.

```dart
var chacha20 = ChaCha20Engine.fromRounds(8); //8-round
var chacha7539 = StreamCipher('ChaCha7539/12') //12-round
```

*Note: to use one of the ChaCha ciphers with the registry, you must append a /(rounds) to the end of the registry string. If you are unsure how many rounds to use, use 20.*

Initializing looks pretty much the same with all these machines. Note the pattern of introducing parameters through the init method:

{% code title="initialization.dart" %}

```dart
var key = KeyParameter([]); //Replace [] with a 32 length Uint8List
var iv = []; //Replace [] with a 8 length Uint8List
var params = ParametersWithIV<KeyParameter>(key, iv);
var chacha20 = ChaCha20Engine();

// The bool below is inherited and represents whether this is for 
// encryption or decryption. Since stream ciphers have a symmetric 
// encryption process, it doesn't matter here.
chacha20.init(true, params);  

// Now, we can either encrypt or decrypt using this instance of
// ChaCha20Engine.
```

{% endcode %}

Finally, encryption (continuing from initialization.dart):

```dart
var encrypted = chacha20.process(data); // data is a Uint8List
```

Decryption looks the same as encryption, but you pass the encrypted data and get back the original data. (This also continues from initialization.dart):

```dart
// encrypted is a Uint8List returned from encryption
var data = chacha20.process(encrypted);
```

Isn't that simple? Most PointyCastle algorithms boil down like this: construct, initialize, and use.
