Home

# Class goog.crypt.Arc4

ARC4 streamcipher implementation.

Instance Method Summary
| `crypt((Array.<number>|Uint8Array|null) data, number= opt_length)` En- or decrypt (same operation for streamciphers like ARC4)

`discard(number length)`

Discards n bytes of the keystream. These days 1536 is considered a decent amount to drop to get the key state warmed-up enough for secure usage. This is not done in the constructor to preserve efficiency for use cases that do not need this. NOTE: Discard is identical to crypt without actually xoring any data. It's unfortunate to have this code duplicated, but this was done for performance reasons. Alternatives which were attempted: 1. Create a temp array of the correct length and pass it to crypt. This works but needlessly allocates an array. But more importantly this requires choosing an array type (Array or Uint8Array) in discard, and choosing a different type than will be passed to crypt by the client code hurts the javascript engines ability to optimize crypt (7x hit in v8). 2. Make data option in crypt so discard can pass null, this has a huge perf hit for crypt.

| `setKey(?Array.<number> key, number= opt_length)` Initialize the cipher for use with new key.