/** * XOR two-way encryption/decryption, with a base64 wrapper. * * @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 xdecrypt($base64 = FALSE, $key = FALSE) { $base64 = is_string($base64) ? $base64 : ""; $e = strlen($base64) ? c_ws_plugin__optimizemember_utils_strings::base64_url_safe_decode($base64) : ""; /**/ if (strlen($e) && preg_match("/^~xe(?:\\:([a-zA-Z0-9]+))?\\|(.*?)\$/s", $e, $md5_e)) { $key = c_ws_plugin__optimizemember_utils_encryption::key($key); /**/ if (strlen($md5_e[2]) && (!$md5_e[1] || $md5_e[1] === md5($md5_e[2]))) { /**/ for ($i = 1, $d = ""; $i <= strlen($md5_e[2]); $i++) { $char = substr($md5_e[2], $i - 1, 1); $keychar = substr($key, $i % strlen($key) - 1, 1); $d .= chr(ord($char) - ord($keychar)); } } if (isset($d) && is_string($d) && strlen($d)) { /**/ if (strlen($d = preg_replace("/^~xe\\|/", "", $d, 1, $xe)) && $xe) { $d = $d; } else { /* Else we need to empty this out. */ $d = ""; } } /**/ return isset($d) && is_string($d) && strlen($d) ? $string = $d : ""; } else { /* Otherwise we must fail here with an empty string value. */ return ""; } }