EncryptorInterface.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Encryption;
  7. /**
  8. * Encryptor interface
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. interface EncryptorInterface
  14. {
  15. /**
  16. * Generate a [salted] hash.
  17. *
  18. * $salt can be:
  19. * false - salt is not used
  20. * true - random salt of the default length will be generated
  21. * integer - random salt of specified length will be generated
  22. * string - actual salt value to be used
  23. *
  24. * @param string $password
  25. * @param bool|int|string $salt
  26. * @return string
  27. */
  28. public function getHash($password, $salt = false);
  29. /**
  30. * Hash a string
  31. *
  32. * @param string $data
  33. * @return string
  34. */
  35. public function hash($data);
  36. /**
  37. * Validate hash against hashing method (with or without salt)
  38. *
  39. * @param string $password
  40. * @param string $hash
  41. * @return bool
  42. * @throws \Exception
  43. */
  44. public function validateHash($password, $hash);
  45. /**
  46. * Validate hash against hashing method (with or without salt)
  47. *
  48. * @param string $password
  49. * @param string $hash
  50. * @return bool
  51. * @throws \Exception
  52. */
  53. public function isValidHash($password, $hash);
  54. /**
  55. * Validate hashing algorithm version
  56. *
  57. * @param string $hash
  58. * @param bool $validateCount
  59. * @return bool
  60. */
  61. public function validateHashVersion($hash, $validateCount = false);
  62. /**
  63. * Encrypt a string
  64. *
  65. * @param string $data
  66. * @return string
  67. */
  68. public function encrypt($data);
  69. /**
  70. * Decrypt a string
  71. *
  72. * @param string $data
  73. * @return string
  74. */
  75. public function decrypt($data);
  76. /**
  77. * Return crypt model, instantiate if it is empty
  78. *
  79. * @param string $key
  80. * @return \Magento\Framework\Encryption\Crypt
  81. */
  82. public function validateKey($key);
  83. }