phpseclib\Crypt\RSA\PKCS1::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 = '')
    {
        $num_primes = count($primes);
        $key = ['version' => $num_primes == 2 ? 'two-prime' : 'multi', 'modulus' => $n, 'publicExponent' => $e, 'privateExponent' => $d, 'prime1' => $primes[1], 'prime2' => $primes[2], 'exponent1' => $exponents[1], 'exponent2' => $exponents[2], 'coefficient' => $coefficients[2]];
        for ($i = 3; $i <= $num_primes; $i++) {
            $key['otherPrimeInfos'][] = ['prime' => $primes[$i], 'exponent' => $exponents[$i], 'coefficient' => $coefficients[$i]];
        }
        $asn1 = new ASN1();
        $key = $asn1->encodeDER($key, RSAPrivateKey);
        return self::wrapPrivateKey($key, 'RSA', $password);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Convert a private key to the appropriate format.
  *
  * @access public
  * @param \phpseclib\Math\BigInteger $n
  * @param \phpseclib\Math\BigInteger $e
  * @param \phpseclib\Math\BigInteger $d
  * @param array $primes
  * @param array $exponents
  * @param array $coefficients
  * @param string $password optional
  * @return string
  */
 static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $primes, $exponents, $coefficients, $password = '')
 {
     $key = PKCS1::savePrivateKey($n, $e, $d, $primes, $exponents, $coefficients);
     $key = ASN1::extractBER($key);
     return self::wrapPrivateKey($key, '1.2.840.113549.1.1.1', [], $password);
 }