<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @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;
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;