<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Zend\Stdlib\Exception;

/**
 * Extension not loaded exception
 */
class ExtensionNotLoadedException extends RuntimeException
{
}
ta is not encoded.
     *
     * @
param  string          $data
     
* @param  Rsa\AbstractKey $key
     
* @param  int             $mode Input encoding
     
* @return string
     
* @throws Rsa\Exception\InvalidArgumentException
     
* @see Rsa::MODE_AUTO
     
* @see Rsa::MODE_BASE64
     
* @see Rsa::MODE_RAW
     
*/
    public function 
decrypt(
        
$data,
        
Rsa\AbstractKey $key = null,
        
$mode = self::MODE_AUTO
    
) {
        if (
null === $key) {
            
$key = $this->options->getPrivateKey();
        }

        if (
null === $key) {
            throw new 
Exception\InvalidArgumentException('No key specified for the decryption');
        }

        switch (
$mode) {
            case 
self::MODE_AUTO:
                
// check if data is encoded in Base64
                
$output = base64_decode($data, true);
                if ((
false !== $output) && ($data === base64_encode($output))) {
                    
$data = $output;
                }
                break;
            case 
self::MODE_BASE64:
                
$data = base64_decode($data);
                break;
            case 
self::MODE_RAW:
            default:
                break;
        }

        return 
$key->decrypt($data);
    }

    
/**
     * Generate new private/public key pair
     * @see RsaOptions::generateKeys()
     *
     * @param  array $opensslConfig
     * @return Rsa
     * @throws Rsa\Exception\RuntimeException
     */
    
public function generateKeys(array $opensslConfig = array())
    {
        
$this->options->generateKeys($opensslConfig);
        return 
$this;
    }
}