equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Crypt |
16 * @package Zend_Crypt |
17 * @subpackage Rsa |
17 * @subpackage Rsa |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: Rsa.php 23439 2010-11-23 21:10:14Z alexander $ |
20 * @version $Id: Rsa.php 24808 2012-05-17 19:56:09Z rob $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_Crypt_Rsa_Key_Private |
24 * @see Zend_Crypt_Rsa_Key_Private |
25 */ |
25 */ |
31 require_once 'Zend/Crypt/Rsa/Key/Public.php'; |
31 require_once 'Zend/Crypt/Rsa/Key/Public.php'; |
32 |
32 |
33 /** |
33 /** |
34 * @category Zend |
34 * @category Zend |
35 * @package Zend_Crypt |
35 * @package Zend_Crypt |
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
36 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
38 */ |
38 */ |
39 class Zend_Crypt_Rsa |
39 class Zend_Crypt_Rsa |
40 { |
40 { |
41 |
41 |
69 */ |
69 */ |
70 public function __construct(array $options = null) |
70 public function __construct(array $options = null) |
71 { |
71 { |
72 if (!extension_loaded('openssl')) { |
72 if (!extension_loaded('openssl')) { |
73 require_once 'Zend/Crypt/Rsa/Exception.php'; |
73 require_once 'Zend/Crypt/Rsa/Exception.php'; |
74 throw new Zend_Crypt_Rsa_Exception('Zend_Crypt_Rsa requires openssl extention to be loaded.'); |
74 throw new Zend_Crypt_Rsa_Exception('Zend_Crypt_Rsa requires openssl extension to be loaded.'); |
75 } |
75 } |
76 |
76 |
77 // Set _hashAlgorithm property when we are sure, that openssl extension is loaded |
77 // Set _hashAlgorithm property when we are sure, that openssl extension is loaded |
78 // and OPENSSL_ALGO_SHA1 constant is available |
78 // and OPENSSL_ALGO_SHA1 constant is available |
79 $this->_hashAlgorithm = OPENSSL_ALGO_SHA1; |
79 $this->_hashAlgorithm = OPENSSL_ALGO_SHA1; |
199 } |
199 } |
200 $function($data, $decrypted, $key->getOpensslKeyResource()); |
200 $function($data, $decrypted, $key->getOpensslKeyResource()); |
201 return $decrypted; |
201 return $decrypted; |
202 } |
202 } |
203 |
203 |
|
204 /** |
|
205 * @param array $configargs |
|
206 * |
|
207 * @throws Zend_Crypt_Rsa_Exception |
|
208 * |
|
209 * @return ArrayObject |
|
210 */ |
204 public function generateKeys(array $configargs = null) |
211 public function generateKeys(array $configargs = null) |
205 { |
212 { |
206 $config = null; |
213 $config = null; |
207 $passPhrase = null; |
214 $passPhrase = null; |
208 if ($configargs !== null) { |
215 if ($configargs !== null) { |
213 $config = $this->_parseConfigArgs($configargs); |
220 $config = $this->_parseConfigArgs($configargs); |
214 } |
221 } |
215 $privateKey = null; |
222 $privateKey = null; |
216 $publicKey = null; |
223 $publicKey = null; |
217 $resource = openssl_pkey_new($config); |
224 $resource = openssl_pkey_new($config); |
|
225 if (!$resource) { |
|
226 require_once 'Zend/Crypt/Rsa/Exception.php'; |
|
227 throw new Zend_Crypt_Rsa_Exception('Failed to generate a new private key'); |
|
228 } |
218 // above fails on PHP 5.3 |
229 // above fails on PHP 5.3 |
219 openssl_pkey_export($resource, $private, $passPhrase); |
230 openssl_pkey_export($resource, $private, $passPhrase); |
220 $privateKey = new Zend_Crypt_Rsa_Key_Private($private, $passPhrase); |
231 $privateKey = new Zend_Crypt_Rsa_Key_Private($private, $passPhrase); |
221 $details = openssl_pkey_get_details($resource); |
232 $details = openssl_pkey_get_details($resource); |
222 $publicKey = new Zend_Crypt_Rsa_Key_Public($details['key']); |
233 $publicKey = new Zend_Crypt_Rsa_Key_Public($details['key']); |
310 } |
321 } |
311 |
322 |
312 protected function _parseConfigArgs(array $config = null) |
323 protected function _parseConfigArgs(array $config = null) |
313 { |
324 { |
314 $configs = array(); |
325 $configs = array(); |
|
326 if (isset($config['private_key_bits'])) { |
|
327 $configs['private_key_bits'] = $config['private_key_bits']; |
|
328 } |
315 if (isset($config['privateKeyBits'])) { |
329 if (isset($config['privateKeyBits'])) { |
316 $configs['private_key_bits'] = $config['privateKeyBits']; |
330 $configs['private_key_bits'] = $config['privateKeyBits']; |
317 } |
331 } |
318 if (!empty($configs)) { |
332 if (!empty($configs)) { |
319 return $configs; |
333 return $configs; |