ddn.crypto.legacy.cipher.rc4

RC4 Stream Cipher.

WARNING: DEPRECATED ALGORITHM

RC4 is cryptographically broken due to biases in its keystream. It has been prohibited in TLS since RFC 7465. Use ChaCha20 or AES-CTR for new encryption.

Standards

RFC 6229 (test vectors)
class RC4

Types 1

classRC4

RC4 stream cipher implementation.

DEPRECATED: Do not use for new encryption.

RC4 is a stream cipher that generates a pseudo-random keystream which is XORed with plaintext to produce ciphertext. The same operation decrypts ciphertext back to plaintext.

This implementation supports key sizes from 5 to 256 bytes (40 to 2048 bits).

Example:

auto rc4 = new RC4(key);  // 5-256 byte key
ubyte[] ciphertext = new ubyte[plaintext.length];
rc4.process(plaintext, ciphertext);

// To decrypt, reset and process again (or create new instance)
rc4.reset();
ubyte[] decrypted = new ubyte[ciphertext.length];
rc4.process(ciphertext, decrypted);

Fields
private ubyte[256] _S
private ubyte[256] _initialS
private ubyte _i
private ubyte _j
Methods
void process(const(ubyte)[] input, ubyte[] output)Processes input data by XORing it with the keystream.
void reset()Resets the cipher to its initial state.
Constructors
this(const(ubyte)[] key)Constructs an RC4 cipher with the given key.