PKCS.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * PKCS Formatted Key Handler
  4. *
  5. * PHP version 5
  6. *
  7. * @category Crypt
  8. * @package Common
  9. * @author Jim Wigginton <terrafrost@php.net>
  10. * @copyright 2015 Jim Wigginton
  11. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  12. * @link http://phpseclib.sourceforge.net
  13. */
  14. namespace phpseclib\Crypt\Common\Keys;
  15. /**
  16. * PKCS1 Formatted Key Handler
  17. *
  18. * @package RSA
  19. * @author Jim Wigginton <terrafrost@php.net>
  20. * @access public
  21. */
  22. abstract class PKCS
  23. {
  24. /**
  25. * Auto-detect the format
  26. */
  27. const MODE_ANY = 0;
  28. /**
  29. * Require base64-encoded PEM's be supplied
  30. */
  31. const MODE_PEM = 1;
  32. /**
  33. * Require raw DER's be supplied
  34. */
  35. const MODE_DER = 2;
  36. /**#@-*/
  37. /**
  38. * Is the key a base-64 encoded PEM, DER or should it be auto-detected?
  39. *
  40. * @access private
  41. * @param int
  42. */
  43. protected static $format = self::MODE_ANY;
  44. /**
  45. * Require base64-encoded PEM's be supplied
  46. *
  47. * @access public
  48. */
  49. public static function requirePEM()
  50. {
  51. self::$format = self::MODE_PEM;
  52. }
  53. /**
  54. * Require raw DER's be supplied
  55. *
  56. * @access public
  57. */
  58. public static function requireDER()
  59. {
  60. self::$format = self::MODE_DER;
  61. }
  62. /**
  63. * Accept any format and auto detect the format
  64. *
  65. * This is the default setting
  66. *
  67. * @access public
  68. */
  69. public static function requireAny()
  70. {
  71. self::$format = self::MODE_ANY;
  72. }
  73. }