web/lib/Zend/InfoCard/Cipher.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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_InfoCard
       
    17  * @subpackage Zend_InfoCard_Cipher
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Cipher.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * Provides an abstraction for encryption ciphers used in an Information Card
       
    25  * implementation
       
    26  *
       
    27  * @category   Zend
       
    28  * @package    Zend_InfoCard
       
    29  * @subpackage Zend_InfoCard_Cipher
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 class Zend_InfoCard_Cipher
       
    34 {
       
    35     /**
       
    36      * AES 256 Encryption with CBC
       
    37      */
       
    38     const ENC_AES256CBC      = 'http://www.w3.org/2001/04/xmlenc#aes256-cbc';
       
    39 
       
    40     /**
       
    41      * AES 128 Encryption with CBC
       
    42      */
       
    43     const ENC_AES128CBC      = 'http://www.w3.org/2001/04/xmlenc#aes128-cbc';
       
    44 
       
    45     /**
       
    46      * RSA Public Key Encryption with OAEP Padding
       
    47      */
       
    48     const ENC_RSA_OAEP_MGF1P = 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p';
       
    49 
       
    50     /**
       
    51      * RSA Public Key Encryption with no padding
       
    52      */
       
    53     const ENC_RSA            = 'http://www.w3.org/2001/04/xmlenc#rsa-1_5';
       
    54 
       
    55     /**
       
    56      * Constructor (disabled)
       
    57      *
       
    58      * @return void
       
    59      * @codeCoverageIgnoreStart
       
    60      */
       
    61     protected function __construct()
       
    62     {
       
    63     }
       
    64     // @codeCoverageIgnoreEnd
       
    65     /**
       
    66      * Returns an instance of a cipher object supported based on the URI provided
       
    67      *
       
    68      * @throws Zend_InfoCard_Cipher_Exception
       
    69      * @param string $uri The URI of the encryption method wantde
       
    70      * @return mixed an Instance of Zend_InfoCard_Cipher_Symmetric_Interface or Zend_InfoCard_Cipher_Pki_Interface
       
    71      *               depending on URI
       
    72      */
       
    73     static public function getInstanceByURI($uri)
       
    74     {
       
    75         switch($uri) {
       
    76             case self::ENC_AES256CBC:
       
    77                 include_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Aes256cbc.php';
       
    78                 return new Zend_InfoCard_Cipher_Symmetric_Adapter_Aes256cbc();
       
    79 
       
    80             case self::ENC_AES128CBC:
       
    81                 include_once 'Zend/InfoCard/Cipher/Symmetric/Adapter/Aes128cbc.php';
       
    82                 return new Zend_InfoCard_Cipher_Symmetric_Adapter_Aes128cbc();
       
    83 
       
    84             case self::ENC_RSA_OAEP_MGF1P:
       
    85                 include_once 'Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php';
       
    86                 return new Zend_InfoCard_Cipher_Pki_Adapter_Rsa(Zend_InfoCard_Cipher_Pki_Adapter_Rsa::OAEP_PADDING);
       
    87                 break;
       
    88 
       
    89             case self::ENC_RSA:
       
    90                 include_once 'Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php';
       
    91                 return new Zend_InfoCard_Cipher_Pki_Adapter_Rsa(Zend_InfoCard_Cipher_Pki_Adapter_Rsa::NO_PADDING);
       
    92                 break;
       
    93 
       
    94             default:
       
    95                 require_once 'Zend/InfoCard/Cipher/Exception.php';
       
    96                 throw new Zend_InfoCard_Cipher_Exception("Unknown Cipher URI");
       
    97         }
       
    98     }
       
    99 }