phpseclib\Net\SSH1::_rsa_crypt PHP Method

_rsa_crypt() public method

Returns mod(pow($m, $e), $n), where $n should be the product of two (large) primes $p and $q and where $e should be a number with the property that gcd($e, ($p - 1) * ($q - 1)) == 1. Could just make anything that calls this call modexp, instead, but I think this makes things clearer, maybe...
See also: self::__construct()
public _rsa_crypt ( phpseclib\Math\BigInteger $m, array $key ) : phpseclib\Math\BigInteger
$m phpseclib\Math\BigInteger
$key array
return phpseclib\Math\BigInteger
    function _rsa_crypt($m, $key)
    {
        /*
        $rsa = new RSA();
        $rsa->load($key, 'raw');
        $rsa->setHash('sha1');
        return $rsa->encrypt($m, RSA::PADDING_PKCS1);
        */
        // To quote from protocol-1.5.txt:
        // The most significant byte (which is only partial as the value must be
        // less than the public modulus, which is never a power of two) is zero.
        //
        // The next byte contains the value 2 (which stands for public-key
        // encrypted data in the PKCS standard [PKCS#1]).  Then, there are non-
        // zero random bytes to fill any unused space, a zero byte, and the data
        // to be encrypted in the least significant bytes, the last byte of the
        // data in the least significant byte.
        // Presumably the part of PKCS#1 they're refering to is "Section 7.2.1 Encryption Operation",
        // under "7.2 RSAES-PKCS1-v1.5" and "7 Encryption schemes" of the following URL:
        // ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf
        $modulus = $key[1]->toBytes();
        $length = strlen($modulus) - strlen($m) - 3;
        $random = '';
        while (strlen($random) != $length) {
            $block = Random::string($length - strlen($random));
            $block = str_replace("", '', $block);
            $random .= $block;
        }
        $temp = chr(0) . chr(2) . $random . chr(0) . $m;
        $m = new BigInteger($temp, 256);
        $m = $m->modPow($key[0], $key[1]);
        return $m->toBytes();
    }