Cipher.php 3.3 KB

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