/**
  * RIJNDAEL 256: two-way encryption/decryption, with a URL-safe base64 wrapper.
  *
  * Falls back on XOR encryption/decryption when mcrypt is not available.
  *
  * @package optimizeMember\Utilities
  * @since 3.5
  *
  * @param str $base64 A string of data to decrypt. Should still be base64 encoded.
  * @param str $key Optional. Key used originally for encryption. Defaults to the one configured for optimizeMember. Short of that, defaults to: ``wp_salt()``.
  * @return str Decrypted string.
  */
 public static function decrypt($base64 = FALSE, $key = FALSE)
 {
     $base64 = is_string($base64) ? $base64 : "";
     $e = strlen($base64) ? c_ws_plugin__optimizemember_utils_strings::base64_url_safe_decode($base64) : "";
     /**/
     if (function_exists("mcrypt_decrypt") && in_array("rijndael-256", mcrypt_list_algorithms()) && in_array("cbc", mcrypt_list_modes()) && strlen($e) && preg_match("/^~r2\\:([a-zA-Z0-9]+)(?:\\:([a-zA-Z0-9]+))?\\|(.*?)\$/s", $e, $iv_md5_e)) {
         $key = c_ws_plugin__optimizemember_utils_encryption::key($key);
         $key = substr($key, 0, mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC));
         /**/
         if (strlen($iv_md5_e[3]) && (!$iv_md5_e[2] || $iv_md5_e[2] === md5($iv_md5_e[3]))) {
             $d = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $iv_md5_e[3], MCRYPT_MODE_CBC, $iv_md5_e[1]);
         }
         /**/
         if (isset($d) && is_string($d) && strlen($d)) {
             /**/
             if (strlen($d = preg_replace("/^~r2\\|/", "", $d, 1, $r2)) && $r2) {
                 $d = rtrim($d, "");
             } else {
                 /* Else we need to empty this out. */
                 $d = "";
             }
         }
         /**/
         return isset($d) && is_string($d) && strlen($d) ? $string = $d : "";
     } else {
         /* Fallback on XOR decryption. */
         return c_ws_plugin__optimizemember_utils_encryption::xdecrypt($base64, $key);
     }
 }
Beispiel #2
0
 function optimizemember_xdecrypt($base64 = FALSE, $key = FALSE)
 {
     return c_ws_plugin__optimizemember_utils_encryption::xdecrypt($base64, $key);
 }