phpseclib\Crypt\RC2::setKeyLength PHP Method

setKeyLength() public method

Valid key lengths are 8 to 1024. Calling this function after setting the key has no effect until the next \phpseclib\Crypt\RC2::setKey() call.
public setKeyLength ( integer $length )
$length integer in bits
    function setKeyLength($length)
    {
        if ($length < 8 || $length > 1024) {
            throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported');
        }
        $this->default_key_length = $this->current_key_length = $length;
        $this->explicit_key_length = $length >> 3;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @dataProvider engineVectors
  */
 public function testVectors($engine, $engineName, $key, $keyLen, $plaintext, $ciphertext)
 {
     $rc2 = new RC2();
     $rc2->disablePadding();
     $rc2->setKeyLength($keyLen);
     $rc2->setKey(pack('H*', $key));
     // could also do $rc2->setKey(pack('H*', $key), $keyLen)
     if (!$rc2->isValidEngine($engine)) {
         self::markTestSkipped('Unable to initialize ' . $engineName . ' engine');
     }
     $rc2->setPreferredEngine($engine);
     $result = bin2hex($rc2->encrypt(pack('H*', $plaintext)));
     $this->assertEquals($result, $ciphertext, "Failed asserting that {$plaintext} yielded expected output in {$engineName} engine");
 }
All Usage Examples Of phpseclib\Crypt\RC2::setKeyLength