CRM-13863 - Civi style for ui dialog buttons
[civicrm-core.git] / CRM / Utils / Crypt.php
index 16d3762fe780aa94cc2dedf4d3229e6197b02425..45ffe44651102c5015dd7d323765406f6d06f9e0 100644 (file)
  */
 class CRM_Utils_Crypt {
 
+  /**
+   * Encrypts a string using AES256 in ECB mode, if encryption is enabled.
+   *
+   * After encrypting the string, it is base64 encoded.
+   *
+   * If encryption is not enabled, either due to CIVICRM_SITE_KEY being
+   * undefined or due to unavailability of the mcrypt module, the string is
+   * merely base64 encoded and is not encrypted at all.
+   *
+   * @param string $string
+   *   Plaintext to be encrypted.
+   * @return string
+   *   Base64-encoded ciphertext, or base64-encoded plaintext if encryption is
+   *   disabled or unavailable.
+   */
   static function encrypt($string) {
     if (empty($string)) {
       return $string;
@@ -56,6 +71,18 @@ class CRM_Utils_Crypt {
     return base64_encode($string);
   }
 
+  /**
+   * Decrypts ciphertext encrypted with AES256 in ECB mode, if possible.
+   *
+   * If the mcrypt module is not available or if CIVICRM_SITE_KEY is not set,
+   * the provided ciphertext is only base64-decoded, not decrypted.
+   *
+   * @param string $string
+   *   Ciphertext to be decrypted.
+   * @return string
+   *   Plaintext, or base64-decoded ciphertext if encryption is disabled or
+   *   unavailable.
+   */
   static function decrypt($string) {
     if (empty($string)) {
       return $string;