From d65b58305e0cc78b3a3f169d8ab4237a58d7df0b Mon Sep 17 00:00:00 2001 From: "Robert C. Sheets" Date: Fri, 28 Mar 2014 01:26:40 -0700 Subject: [PATCH] Adds docstrings to the methods of class CRM_Utils_Crypt. --- CRM/Utils/Crypt.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/Crypt.php b/CRM/Utils/Crypt.php index dd5e284b8f..42df3310ff 100644 --- a/CRM/Utils/Crypt.php +++ b/CRM/Utils/Crypt.php @@ -28,12 +28,27 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2013 + * @copyright CiviCRM LLC (c) 2004-2014 * $Id$ * */ 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; -- 2.25.1