phpseclib\Crypt\RC4::setKey PHP Method

setKey() public method

Keys can be between 1 and 256 bytes long.
public setKey ( $key )
    function setKey($key)
    {
        $length = strlen($key);
        if ($length < 1 || $length > 256) {
            throw new \LengthException('Key size of ' . $length . ' bytes is not supported by RC4. Keys must be between 1 and 256 bytes long');
        }
        parent::setKey($key);
    }

Usage Example

Example #1
0
 /**
  * @dataProvider engineVectors
  */
 public function testVectors($engine, $engineName, $key, $offset, $expected)
 {
     $rc4 = new RC4();
     $rc4->setPreferredEngine($engine);
     $rc4->setKey($key);
     if ($rc4->getEngine() != $engine) {
         self::markTestSkipped('Unable to initialize ' . $engineName . ' engine for ' . strlen($key) * 8 . '-bit key');
     }
     $result = $rc4->encrypt(str_repeat("", $offset + 16));
     $this->assertEquals(bin2hex(substr($result, -16)), $expected, "Failed asserting that key {$key} yielded expected output at offset {$offset} in {$engineName} engine");
 }
All Usage Examples Of phpseclib\Crypt\RC4::setKey