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_Public extends Zend_Crypt_Rsa_Key
0035 {
0036 
0037     protected $_certificateString = null;
0038 
0039     public function __construct($string)
0040     {
0041         $this->_parse($string);
0042     }
0043 
0044     /**
0045      * @param string $string
0046      * @throws Zend_Crypt_Exception
0047      */
0048     protected function _parse($string)
0049     {
0050         if (preg_match("/^-----BEGIN CERTIFICATE-----/", $string)) {
0051             $this->_certificateString = $string;
0052         } else {
0053             $this->_pemString = $string;
0054         }
0055         $result = openssl_get_publickey($string);
0056         if (!$result) {
0057             /**
0058              * @see Zend_Crypt_Exception
0059              */
0060             // require_once 'Zend/Crypt/Exception.php';
0061             throw new Zend_Crypt_Exception('Unable to load public key');
0062         }
0063         //openssl_pkey_export($result, $public);
0064         //$this->_pemString = $public;
0065         $this->_opensslKeyResource = $result;
0066         $this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
0067     }
0068 
0069     public function getCertificate()
0070     {
0071         return $this->_certificateString;
0072     }
0073 
0074 }