|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
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. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Crypt |
|
17 * @subpackage Rsa |
|
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 |
|
20 * @version $Id: Private.php 22662 2010-07-24 17:37:36Z mabe $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Crypt_Rsa_Key |
|
25 */ |
|
26 require_once 'Zend/Crypt/Rsa/Key.php'; |
|
27 |
|
28 /** |
|
29 * @category Zend |
|
30 * @package Zend_Crypt |
|
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 |
|
33 */ |
|
34 class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key |
|
35 { |
|
36 |
|
37 protected $_publicKey = null; |
|
38 |
|
39 public function __construct($pemString, $passPhrase = null) |
|
40 { |
|
41 $this->_pemString = $pemString; |
|
42 $this->_parse($passPhrase); |
|
43 } |
|
44 |
|
45 /** |
|
46 * @param string $passPhrase |
|
47 * @throws Zend_Crypt_Exception |
|
48 */ |
|
49 protected function _parse($passPhrase) |
|
50 { |
|
51 $result = openssl_get_privatekey($this->_pemString, $passPhrase); |
|
52 if (!$result) { |
|
53 /** |
|
54 * @see Zend_Crypt_Exception |
|
55 */ |
|
56 require_once 'Zend/Crypt/Exception.php'; |
|
57 throw new Zend_Crypt_Exception('Unable to load private key'); |
|
58 } |
|
59 $this->_opensslKeyResource = $result; |
|
60 $this->_details = openssl_pkey_get_details($this->_opensslKeyResource); |
|
61 } |
|
62 |
|
63 public function getPublicKey() |
|
64 { |
|
65 if ($this->_publicKey === null) { |
|
66 /** |
|
67 * @see Zend_Crypt_Rsa_Key_Public |
|
68 */ |
|
69 require_once 'Zend/Crypt/Rsa/Key/Public.php'; |
|
70 $this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']); |
|
71 } |
|
72 return $this->_publicKey; |
|
73 } |
|
74 |
|
75 } |