phpseclib\Crypt\RSA\MSBLOB::savePrivateKey PHP Method

savePrivateKey() static public method

Convert a private key to the appropriate format.
static public savePrivateKey ( phpseclib\Math\BigInteger $n, phpseclib\Math\BigInteger $e, phpseclib\Math\BigInteger $d, array $primes, array $exponents, array $coefficients, string $password = '' ) : string
$n phpseclib\Math\BigInteger
$e phpseclib\Math\BigInteger
$d phpseclib\Math\BigInteger
$primes array
$exponents array
$coefficients array
$password string optional
return string
    static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
    {
        $n = strrev($n->toBytes());
        $e = str_pad(strrev($e->toBytes()), 4, "");
        $key = pack('aavV', chr(self::PRIVATEKEYBLOB), chr(2), 0, self::CALG_RSA_KEYX);
        $key .= pack('VVa*', self::RSA2, 8 * strlen($n), $e);
        $key .= $n;
        $key .= strrev($primes[1]->toBytes());
        $key .= strrev($primes[2]->toBytes());
        $key .= strrev($exponents[1]->toBytes());
        $key .= strrev($exponents[2]->toBytes());
        $key .= strrev($coefficients[1]->toBytes());
        $key .= strrev($d->toBytes());
        return Base64::encode($key);
    }