File indexing completed on 2024-12-29 05:27:32

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Crypt
0017  * @subpackage Rsa
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Crypt_Rsa_Key
0025  */
0026 // require_once 'Zend/Crypt/Rsa/Key.php';
0027 
0028 /**
0029  * @category   Zend
0030  * @package    Zend_Crypt
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
0035 {
0036 
0037     protected $_publicKey = null;
0038 
0039     public function __construct($pemString, $passPhrase = null)
0040     {
0041         $this->_pemString = $pemString;
0042         $this->_parse($passPhrase);
0043     }
0044 
0045     /**
0046      * @param string $passPhrase
0047      * @throws Zend_Crypt_Exception
0048      */
0049     protected function _parse($passPhrase)
0050     {
0051         $result = openssl_get_privatekey($this->_pemString, $passPhrase);
0052         if (!$result) {
0053             /**
0054              * @see Zend_Crypt_Exception
0055              */
0056             // require_once 'Zend/Crypt/Exception.php';
0057             throw new Zend_Crypt_Exception('Unable to load private key');
0058         }
0059         $this->_opensslKeyResource = $result;
0060         $this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
0061     }
0062 
0063     public function getPublicKey()
0064     {
0065         if ($this->_publicKey === null) {
0066             /**
0067              * @see Zend_Crypt_Rsa_Key_Public
0068              */
0069             // require_once 'Zend/Crypt/Rsa/Key/Public.php';
0070             $this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']);
0071         }
0072         return $this->_publicKey;
0073     }
0074 
0075 }