7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
24 * @see Zend_Crypt_Rsa_Key
26 require_once 'Zend/Crypt/Rsa/Key.php';
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
34 class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
37 protected $_publicKey = null;
39 public function __construct($pemString, $passPhrase = null)
41 $this->_pemString = $pemString;
42 $this->_parse($passPhrase);
46 * @param string $passPhrase
47 * @throws Zend_Crypt_Exception
49 protected function _parse($passPhrase)
51 $result = openssl_get_privatekey($this->_pemString, $passPhrase);
54 * @see Zend_Crypt_Exception
56 require_once 'Zend/Crypt/Exception.php';
57 throw new Zend_Crypt_Exception('Unable to load private key');
59 $this->_opensslKeyResource = $result;
60 $this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
63 public function getPublicKey()
65 if ($this->_publicKey === null) {
67 * @see Zend_Crypt_Rsa_Key_Public
69 require_once 'Zend/Crypt/Rsa/Key/Public.php';
70 $this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']);
72 return $this->_publicKey;