Private.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Crypt_Rsa_Key
  24. */
  25. require_once 'Zend/Crypt/Rsa/Key.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Crypt
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
  33. {
  34. protected $_publicKey = null;
  35. public function __construct($pemString, $passPhrase = null)
  36. {
  37. $this->_pemString = $pemString;
  38. $this->_parse($passPhrase);
  39. }
  40. /**
  41. * @param string $passPhrase
  42. * @throws Zend_Crypt_Exception
  43. */
  44. protected function _parse($passPhrase)
  45. {
  46. $result = openssl_get_privatekey($this->_pemString, $passPhrase);
  47. if (!$result) {
  48. /**
  49. * @see Zend_Crypt_Exception
  50. */
  51. require_once 'Zend/Crypt/Exception.php';
  52. throw new Zend_Crypt_Exception('Unable to load private key');
  53. }
  54. $this->_opensslKeyResource = $result;
  55. $this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
  56. }
  57. public function getPublicKey()
  58. {
  59. if ($this->_publicKey === null) {
  60. /**
  61. * @see Zend_Crypt_Rsa_Key_Public
  62. */
  63. require_once 'Zend/Crypt/Rsa/Key/Public.php';
  64. $this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']);
  65. }
  66. return $this->_publicKey;
  67. }
  68. }