Decode base64 encoded string

@param bool $webSafe Web sage decoding (replaces '-' with '+' and '_' with '/' before decoding)

@return $this
9206
public function base64Decode($webSafe = false)
    {
        $this->val(base64_decode($this->val()));

        if ($webSafe) {
            $this->replace('-', '+')->replace('_', '/');
        }

        return $this;
    }
623389
public static function urlsafeB64Decode($input)
    {
        $remainder = strlen($input) % 4;

        if ($remainder) {
            $pad_length = 4 - $remainder;
            $input .= str_repeat('=', $pad_length);
        }

        return base64_decode(strtr($input, '-_', '+/'));
    }
325674
def _DecodeUrlSafe(urlsafe):
  
  if not isinstance(urlsafe, basestring):
    raise TypeError('urlsafe must be a string; received %r' % urlsafe)
  if isinstance(urlsafe, unicode):
    urlsafe = urlsafe.encode('utf8')
  mod = len(urlsafe) % 4
  if mod:
    urlsafe += '=' * (4 - mod)
  # This is 3-4x faster than urlsafe_b64decode()
  return base64.b64decode(urlsafe.replace('-', '+').replace('_', '/'))
903108
def base64_url_decode(str)
      encoded_str = str.tr('-_', '+/')
      encoded_str += '=' while !(encoded_str.size % 4).zero?
      Base64.decode64(encoded_str)
    end
486438
function decode($query)
    {
        if (!$query) {
            return null;
        }

        $message = Auth_OpenID_Message::fromPostArgs($query);

        if ($message === null) {
            /*
             * It's useful to have a Message attached to a
             * ProtocolError, so we override the bad ns value to build
             * a Message out of it.  Kinda kludgy, since it's made of
             * lies, but the parts that aren't lies are more useful
             * than a 'None'.
             */
            $old_ns = $query['openid.ns'];

            $query['openid.ns'] = Auth_OpenID_OPENID2_NS;
            $message = Auth_OpenID_Message::fromPostArgs($query);
            return new Auth_OpenID_ServerError(
                  $message,
                  sprintf("Invalid OpenID namespace URI: %s", $old_ns));
        }

        $mode = $message->getArg(Auth_OpenID_OPENID_NS, 'mode');
        if (!$mode) {
            return new Auth_OpenID_ServerError($message,
                                               "No mode value in message");
        }

        if (Auth_OpenID::isFailure($mode)) {
            return new Auth_OpenID_ServerError($message,
                                               $mode->message);
        }

        $handlerCls = Auth_OpenID::arrayGet($this->handlers, $mode,
                                            $this->defaultDecoder($message));

        if (!is_a($handlerCls, 'Auth_OpenID_ServerError')) {
            return call_user_func_array(array($handlerCls, 'fromMessage'),
                                        array($message, $this->server));
        } else {
            return $handlerCls;
        }
    }
352532
function base64urlsafe(hash){
    // replace some chars
    hash = hash.replace(/\//g, '_').replace(/\+/g, '-').replace(/=/g, '');

    return hash;
}
847436
public static function chooseEncoder($chosen, bool $decode = false)
    {
        if ($chosen === true) {
            return null;
        } elseif ($chosen === false) {
            return \implode(
                '::',
                [
                    Hex::class,
                    $decode ? 'decode' : 'encode'
                ]
            );
        } elseif ($chosen === self::ENCODE_BASE32) {
            return \implode(
                '::',
                [
                    Base32::class,
                    $decode ? 'decode' : 'encode'
                ]
            );
        } elseif ($chosen === self::ENCODE_BASE32HEX) {
            return \implode(
                '::',
                [
                    Base32Hex::class,
                    $decode ? 'decode' : 'encode'
                ]
            );
        } elseif ($chosen === self::ENCODE_BASE64) {
            return \implode(
                '::',
                [
                    Base64::class,
                    $decode ? 'decode' : 'encode'
                ]
            );
        } elseif ($chosen === self::ENCODE_BASE64URLSAFE) {
            return \implode(
                '::',
                [
                    Base64UrlSafe::class,
                    $decode ? 'decode' : 'encode'
                ]
            );
        } elseif ($chosen === self::ENCODE_HEX) {
            return \implode(
                '::',
                [
                    Hex::class,
                    $decode ? 'decode' : 'encode'
                ]
            );
        }
        throw new InvalidType(
            'Illegal value for encoding choice.'
        );
    }
439301
protected function decode($string)
    {
        // decode if specified
        if (($pos = strpos($string, ':')) !== false) {
            if (!strncmp($string, 'base64', 6)) {
                return base64_decode(substr($string, 7));
            } elseif (!strncmp($string, 'urlencode', 9)) {
                return urldecode(substr($string, 10));
            }
        }

        return $string;
    }
142992
public function decode()
    {
        // Fix plus to space conversion issue
        $this->data = str_replace(' ', '+', $this->data);

        // Do decoding
        $this->data = base64_decode($this->data);

        return $this;
    }
668494
private function decode($text) {
		$pad = ord(substr($text, -1));
		if ($pad < 1 || $pad > 32) {
			$pad = 0;
		}

		return substr($text, 0, (strlen($text) - $pad));
	}
373218
public function base64Decode(string $base64Encoded): string
    {
        if ($remainder = strlen($base64Encoded) % 4) {
            $base64Encoded .= str_repeat('=', 4 - $remainder);
        }

        return base64_decode(strtr($base64Encoded, '-_', '+/'));
    }
1055303
public static function decodeUtf8($strValue = '', $strEncoding = 'iso-8859-1', $booSafemode = false)
    {
        return decode_utf8($strValue = '', $strEncoding = 'iso-8859-1', $booSafemode = false);
    }
637651
public static function safe_b64decode($string)
    {
        $data = str_replace(array('-', '_'), array('+', '/'), $string);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }
        return base64_decode($data);
    }
706061
public function base32_decode($hash)
    {
        $lookup = $this->getLookup();

        if (preg_match('/^['.implode('', array_keys($lookup)).']+$/', $hash) == false) {
            throw new \InvalidArgumentException('Invalid base32 hash!');
        }

        $hash = strtoupper($hash);
        $buffer = 0;
        $length = 0;
        $binary = '';

        for ($i = 0; $i < strlen($hash); $i++) {
            $buffer = $buffer << 5;
            $buffer += $lookup[$hash[$i]];
            $length += 5;

            if ($length >= 8) {
                $length -= 8;
                $binary .= chr(($buffer & (0xFF << $length)) >> $length);
            }
        }

        return $binary;
    }
998066
public static function decodeQueryString($source, $rfc = self::RFC_3986)
    {
        $ret = [];
        if ($source !== '') {
            $decode = self::getQueryStringDecoder($rfc);
            $queryPairs = explode('&', $source);
            foreach ($queryPairs as $pair) {
                $parts = explode('=', $pair, 2);
                $key = $decode($parts[0]);
                $value = (count($parts) === 1) ? true : $decode($parts[1]);
                Arr::addValue($ret, $key, $value);
            }
        }

        return $ret;
    }
1041362
public static String decodeCookie(String string) {
        if (string == null) {
            return null;
        }
        string = string.replaceAll("%2C", ",");
        string = string.replaceAll("%3B", ";");
        string = string.replaceAll("%25", "%");
        return string;
    }
30065
private function decodeMatchedEntity($matches)
    {
        $body = $matches[4];
        if (strtoupper($matches[3]) === 'Q') {
            $body = quoted_printable_decode(str_replace('_', '=20', $body));
        } else {
            $body = base64_decode($body);
        }
        $language = $matches[2];
        $decoded = $this->convertEncoding($body, $matches[1], true);
        $this->addToLanguage($decoded, $language);
        return $decoded;
    }