Private.php 937 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. require_once 'Zend/Crypt/Rsa/Key.php';
  3. class Zend_Crypt_Rsa_Key_Private extends Zend_Crypt_Rsa_Key
  4. {
  5. protected $_publicKey = null;
  6. public function __construct($pemString, $passPhrase = null)
  7. {
  8. $this->_pemString = $pemString;
  9. $this->_parse($passPhrase);
  10. }
  11. protected function _parse($passPhrase)
  12. {
  13. $result = openssl_get_privatekey($this->_pemString, $passPhrase);
  14. if (!$result) {
  15. require_once 'Zend/Crypt/Exception.php';
  16. throw new Zend_Crypt_Exception('Unable to load private key');
  17. }
  18. $this->_opensslKeyResource = $result;
  19. $this->_details = openssl_pkey_get_details($this->_opensslKeyResource);
  20. }
  21. public function getPublicKey()
  22. {
  23. if (is_null($this->_publicKey)) {
  24. $this->_publicKey = new Zend_Crypt_Rsa_Key_Public($this->_details['key']);
  25. }
  26. return $this->_publicKey;
  27. }
  28. }