You are here

API.txt in AES encryption 8.2

Same filename and directory in other branches
  1. 6 API.txt
Here's a brief and simple run-through of the functions which might be
interesting from a developers point of view. Most (see exceptions below) of
the functions are implementation independent, so behaviour should be consistent
regardless of which implementation (mcrypt, phpseclib or custom) is used.

Implementation independence exceptions:

1. AES::make_iv is mute when using phpseclib since that implementation handle
its own IV internally.

2. The $custom_cipher and $custom_iv arguments to AES::encrypt and AES::decrypt
are ignored when using phpseclib, since that implementation doesn't support
changing these values. Passing these arguments as anything else than null will
generate warnings when using phpseclib.

--------------------------------------------------------------------------------
Function:
string|false AES::encrypt($string, $base64encode = true, $custom_key = null,
  $custom_cipher = null, $custom_iv = null, $custom_implementation = null)

Description:
Encrypts a string.

Arguments:
string $string The string to encrypt.
(optional) bool $base64encode Whether to return the string base64 encoded
  (recommended for database insertion).
(optional) string $custom_key Use this as the key rather than the stored
  one for this operation.
(optional) string $custom_cipher Use this cipher rather than the default one.
  (only with Mcrypt - ignored with phpseclib)
(optional) string $custom_iv Use this initialization vector instead of the
  default one.
(optional) string $force_implementation Can be "phpseclib", "mcrypt" or name
  of plugin implementing own algorithm.

  Warning: The function does not check if the requested implementation actually
  exists.

Returns:
The encrypted string on success, false on error.

--------------------------------------------------------------------------------
Function:
string|false AES::decrypt($string, $base64encoded = true, $custom_key = null,
  $custom_cipher = null, $custom_iv = null, $force_implementation = null)

Description:
Decrypts a string of encrypted data.

Arguments:
string $string The string to decrypt.
(optional) bool $base64encode Whether this encrypted string is base64 encoded
  or not.
(optional) string $custom_key Use this as the key rather than the stored one
  for this operation.
(optional) string $custom_cipher Use this cipher rather than the default one.
  (only with Mcrypt - ignored with phpseclib)
(optional) string $custom_iv Use this initialization vector instead of the
  default one.
(optional) string $force_implementation Can be "phpseclib", "mcrypt" or name
  of plugin implementing own algorithm.

  Warning: The function does not check if the requested implementation actually
  exists.

Returns:
The decrypted string on success, false on error.

---------------------------------------------------------------------------------
Function:
string AES::get_key()

Description:
Gets the current key used for the encryption system. If there's currently no key
defined, this function will generate one, store it, and return it.

Arguments:
none

Returns:
The key.

---------------------------------------------------------------------------------
Function:
string AES::make_key()

Description:
Generates a new key.

Arguments:
none

Returns:
The newly generated key.

--------------------------------------------------------------------------------
Function:
void AES::make_iv($ignore_implementation = false)

Description:
Generates a new initialization vector and stores it (overwrites old IV!).
NOTE: Only use this with the Mcrypt implementation, phpseclib has its own IV
management.

Arguments:
(optional) bool $ignore_implementation Forces aes_make_iv to create and store
a new IV even if the phpseclib implementation is used.

Returns:
nothing

--------------------------------------------------------------------------------
Custom encryption mechanism.
To use the module with own AES implementation or even custom encryption
algorithm a plugin should be created.

An example plugin is available in the file src/Plugin/AES/Reverse.php

File

API.txt
View source
  1. Here's a brief and simple run-through of the functions which might be
  2. interesting from a developers point of view. Most (see exceptions below) of
  3. the functions are implementation independent, so behaviour should be consistent
  4. regardless of which implementation (mcrypt, phpseclib or custom) is used.
  5. Implementation independence exceptions:
  6. 1. AES::make_iv is mute when using phpseclib since that implementation handle
  7. its own IV internally.
  8. 2. The $custom_cipher and $custom_iv arguments to AES::encrypt and AES::decrypt
  9. are ignored when using phpseclib, since that implementation doesn't support
  10. changing these values. Passing these arguments as anything else than null will
  11. generate warnings when using phpseclib.
  12. --------------------------------------------------------------------------------
  13. Function:
  14. string|false AES::encrypt($string, $base64encode = true, $custom_key = null,
  15. $custom_cipher = null, $custom_iv = null, $custom_implementation = null)
  16. Description:
  17. Encrypts a string.
  18. Arguments:
  19. string $string The string to encrypt.
  20. (optional) bool $base64encode Whether to return the string base64 encoded
  21. (recommended for database insertion).
  22. (optional) string $custom_key Use this as the key rather than the stored
  23. one for this operation.
  24. (optional) string $custom_cipher Use this cipher rather than the default one.
  25. (only with Mcrypt - ignored with phpseclib)
  26. (optional) string $custom_iv Use this initialization vector instead of the
  27. default one.
  28. (optional) string $force_implementation Can be "phpseclib", "mcrypt" or name
  29. of plugin implementing own algorithm.
  30. Warning: The function does not check if the requested implementation actually
  31. exists.
  32. Returns:
  33. The encrypted string on success, false on error.
  34. --------------------------------------------------------------------------------
  35. Function:
  36. string|false AES::decrypt($string, $base64encoded = true, $custom_key = null,
  37. $custom_cipher = null, $custom_iv = null, $force_implementation = null)
  38. Description:
  39. Decrypts a string of encrypted data.
  40. Arguments:
  41. string $string The string to decrypt.
  42. (optional) bool $base64encode Whether this encrypted string is base64 encoded
  43. or not.
  44. (optional) string $custom_key Use this as the key rather than the stored one
  45. for this operation.
  46. (optional) string $custom_cipher Use this cipher rather than the default one.
  47. (only with Mcrypt - ignored with phpseclib)
  48. (optional) string $custom_iv Use this initialization vector instead of the
  49. default one.
  50. (optional) string $force_implementation Can be "phpseclib", "mcrypt" or name
  51. of plugin implementing own algorithm.
  52. Warning: The function does not check if the requested implementation actually
  53. exists.
  54. Returns:
  55. The decrypted string on success, false on error.
  56. ---------------------------------------------------------------------------------
  57. Function:
  58. string AES::get_key()
  59. Description:
  60. Gets the current key used for the encryption system. If there's currently no key
  61. defined, this function will generate one, store it, and return it.
  62. Arguments:
  63. none
  64. Returns:
  65. The key.
  66. ---------------------------------------------------------------------------------
  67. Function:
  68. string AES::make_key()
  69. Description:
  70. Generates a new key.
  71. Arguments:
  72. none
  73. Returns:
  74. The newly generated key.
  75. --------------------------------------------------------------------------------
  76. Function:
  77. void AES::make_iv($ignore_implementation = false)
  78. Description:
  79. Generates a new initialization vector and stores it (overwrites old IV!).
  80. NOTE: Only use this with the Mcrypt implementation, phpseclib has its own IV
  81. management.
  82. Arguments:
  83. (optional) bool $ignore_implementation Forces aes_make_iv to create and store
  84. a new IV even if the phpseclib implementation is used.
  85. Returns:
  86. nothing
  87. --------------------------------------------------------------------------------
  88. Custom encryption mechanism.
  89. To use the module with own AES implementation or even custom encryption
  90. algorithm a plugin should be created.
  91. An example plugin is available in the file src/Plugin/AES/Reverse.php