Public.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_Public extends Zend_Crypt_Rsa_Key
  33. {
  34. protected $_certificateString = null;
  35. public function __construct($string)
  36. {
  37. $this->_parse($string);
  38. }
  39. /**
  40. * @param string $string
  41. * @throws Zend_Crypt_Exception
  42. */
  43. protected function _parse($string)
  44. {
  45. if (preg_match("/^-----BEGIN CERTIFICATE-----/", $string)) {
  46. $this->_certificateString = $string;
  47. } else {
  48. $this->_pemString = $string;
  49. }
  50. $result = openssl_get_publickey($string);
  51. if (!$result) {
  52. /**
  53. * @see Zend_Crypt_Exception
  54. */
  55. require_once 'Zend/Crypt/Exception.php';
  56. throw new Zend_Crypt_Exception('Unable to load public key');
  57. }
  58. //openssl_pkey_export($result, $public);
  59. //$this->_pemString = $public;
  60. $this->_opensslKeyResource = $result;
  61. $this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
  62. }
  63. public function getCertificate()
  64. {
  65. return $this->_certificateString;
  66. }
  67. }