Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. class proCrypt
  3. {
  4. /**
  5. *
  6. * This is called when we wish to set a variable
  7. *
  8. * @access public
  9. * @param string $name
  10. * @param string $value
  11. *
  12. */
  13. public function __set( $name, $value )
  14. {
  15. switch( $name)
  16. {
  17. case 'key':
  18. case 'ivs':
  19. case 'iv':
  20. $this->$name = $value;
  21. break;
  22.  
  23. default:
  24. throw new Exception( "$name cannot be set" );
  25. }
  26. }
  27.  
  28. /**
  29. *
  30. * Gettor - This is called when an non existant variable is called
  31. *
  32. * @access public
  33. * @param string $name
  34. *
  35. */
  36. public function __get( $name )
  37. {
  38. switch( $name )
  39. {
  40. case 'key':
  41. return 'keee';
  42.  
  43. case 'ivs':
  44. return mcrypt_get_iv_size( MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB );
  45.  
  46. case 'iv':
  47. return mcrypt_create_iv( $this->ivs );
  48.  
  49. default:
  50. throw new Exception( "$name cannot be called" );
  51. }
  52. }
  53.  
  54. /**
  55. *
  56. * Encrypt a string
  57. *
  58. * @access public
  59. * @param string $text
  60. * @return string The encrypted string
  61. *
  62. */
  63. public function encrypt( $text )
  64. {
  65. // add end of text delimiter
  66. $data = mcrypt_encrypt( MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv );
  67. return base64_encode( $data );
  68. }
  69.  
  70. /**
  71. *
  72. * Decrypt a string
  73. *
  74. * @access public
  75. * @param string $text
  76. * @return string The decrypted string
  77. *
  78. */
  79. public function decrypt( $text )
  80. {
  81. $text = base64_decode( $text );
  82. return mcrypt_decrypt( MCRYPT_RIJNDAEL_128, $this->key, $text, MCRYPT_MODE_ECB, $this->iv );
  83. }
  84. }
  85. // end of class
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement