Decrypt string container crypt text

@param string $hash
@param string $crypt_text
@param string $method
@param string $iv
@return null|string
490668
private static function decryptStandard(
        $hash,
        $crypt_text,
        $method,
        $iv
    ) {
        if (substr($iv, 0, strlen($method)) !== $method) {
            return null;
        }

        /**
         * ------------------------------------
         * Doing convert encrypted string
         * ------------------------------------
         */
        /**
         * Doing decode of input encryption
         */
        $crypt_text = self::safeBase64Decode($crypt_text);
        $enc_arr  = str_split($crypt_text);
        $add = 0;
        $div = strlen($crypt_text) / strlen($hash);
        $new_pass = '';
        while ($add <= $div) {
            $new_pass .= $hash;
            $add++;
        }
        $pass_arr = str_split($new_pass);
        $ascii ='';
        foreach ($enc_arr as $key => $asc) {
            $pass_int = ord($pass_arr[$key]);
            $enc_int = ord($asc);
            $str_int = $enc_int - $pass_int;
            $ascii .= chr(($str_int-strlen($crypt_text)));
        }

        /* --------------------------------
         * reversing
         * ------------------------------ */
        // unpack
        $unpack     = unpack('a*', trim($ascii));

        /**
         * if empty return here
         */
        if (empty($unpack)) {
            return null;
        }

        // implode the unpacking array
        $unpack = implode('', (array) $unpack);
        $iv     = substr($iv, strlen($method));
        if (strlen($hash) < strlen($unpack)) {
            $sub_iv = substr($unpack, strlen($hash), strlen($iv));
        } else {
            $sub_iv = substr($unpack, -strlen($iv));
        }
        if ($sub_iv !== $iv) {
            return null;
        }
        $crypt_text = substr_replace($unpack, '', strlen($hash), strlen($iv));
        return self::rotate($crypt_text, -(strlen($hash) % 13));
    }
527158
public static function decrypt($encrypted_text, $key)
    {
        $md5Key = md5($key);
        
        $decrypted_text = mcrypt_decrypt(
            MCRYPT_RIJNDAEL_256, 
             $md5Key, 
             base64_decode($encrypted_text), 
             MCRYPT_MODE_CBC, 
             md5($md5Key)
        );
        
        $trimmed_decryption = rtrim($decrypted_text, "\0");
        return $trimmed_decryption;
    }
160233
public static function decrypt(RSAKey $key, $ciphertext, $hash_algorithm)
    {
        Assertion::greaterThan($key->getModulusLength(), 0);
        $hash = Hash::$hash_algorithm();
        $ciphertext = str_split($ciphertext, $key->getModulusLength());
        $ciphertext[count($ciphertext) - 1] = str_pad($ciphertext[count($ciphertext) - 1], $key->getModulusLength(), chr(0), STR_PAD_LEFT);
        $plaintext = '';
        foreach ($ciphertext as $c) {
            $temp = self::getRSAESOAEP($key, $c, $hash);
            $plaintext .= $temp;
        }

        return $plaintext;
    }
783241
public function decrypt($data, $key = null, $iv = null)
    {
        $data = base64_decode($data);

        if (!$iv) {
            $ivSize = $this->getIVSize();

            $iv = substr($data, 0, $ivSize);

            $data = substr($data, $ivSize);
        } else {
            $ivSize = $this->getIVSize();

            if (substr($data, 0, $ivSize) === $iv) {
                $data = substr($data, $ivSize);
            }
        }

        $key = CryptHelper::repeatToLength($key, 24, true);

        // Decrypt the data.
        $decrypted = trim(mcrypt_decrypt($this->type, $key, $data, $this->mode, $iv));

        return $decrypted;
    }
1170092
function hash($text)
    {
        $mode = is_array($this->hash) ? self::MODE_INTERNAL : CRYPT_HASH_MODE;

        if (!empty($this->key) || is_string($this->key)) {
            switch ($mode) {
                case self::MODE_MHASH:
                    $output = mhash($this->hash, $text, $this->key);
                    break;
                case self::MODE_HASH:
                    $output = hash_hmac($this->hash, $text, $this->key, true);
                    break;
                case self::MODE_INTERNAL:
                    /* "Applications that use keys longer than B bytes will first hash the key using H and then use the
                        resultant L byte string as the actual key to HMAC."

                        -- http://tools.ietf.org/html/rfc2104#section-2 */
                    $key = strlen($this->key) > $this->b ? call_user_func($this->hash, $this->key) : $this->key;

                    $key    = str_pad($key, $this->b, chr(0));      // step 1
                    $temp   = $this->ipad ^ $key;                   // step 2
                    $temp  .= $text;                                // step 3
                    $temp   = call_user_func($this->hash, $temp);   // step 4
                    $output = $this->opad ^ $key;                   // step 5
                    $output.= $temp;                                // step 6
                    $output = call_user_func($this->hash, $output); // step 7
            }
        } else {
            switch ($mode) {
                case self::MODE_MHASH:
                    $output = mhash($this->hash, $text);
                    break;
                case self::MODE_HASH:
                    $output = hash($this->hash, $text, true);
                    break;
                case self::MODE_INTERNAL:
                    $output = call_user_func($this->hash, $text);
            }
        }

        return substr($output, 0, $this->l);
    }
161261
public function decrypt($data, $key = null, $iv = null)
    {
        include_once __DIR__ . '/../lib/aes.class.php';

        return \AesCtr::decrypt(base64_decode($data), $key, $this->keyLength);
    }
223923
function Crypt_Hash($hash = 'sha1')
    {
        if ( !defined('CRYPT_HASH_MODE') ) {
            switch (true) {
                case extension_loaded('hash'):
                    define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
                    break;
                case extension_loaded('mhash'):
                    define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_MHASH);
                    break;
                default:
                    define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);
            }
        }

        $this->setHash($hash);
    }
1081601
private static String decode_password(String encoded_string, String crypto_algorithm) {
        /*
         * decoding process:
         * 
         * -- check for empty algorithm tag
         * -- convert input String to byte[] using base64 decoding
         * -- decipher byte[]
         * -- convert byte[] to String using UTF8 conversion code
         */

        StringBuilder buffer = new StringBuilder();

        if (crypto_algorithm.length() == 0) {
            // crypto algorithm is empty ... don't decode password
            buffer.append(encoded_string);
        } else {
            // decode password with specified crypto algorithm
            String decoded_string = null;
            if (encoded_string.length() > 0) {
                // convert viewable string to encrypted password byte[]
                byte[] encrypted_bytes = convert_viewable_to_bytes(encoded_string);
                logger.logp(Level.FINEST, PasswordUtil.class.getName(), "decode_password", "byte array before decoding\n" + PasswordHashGenerator.hexDump(encrypted_bytes));

                if (encrypted_bytes == null) {
                    // base64 decoding failed
                    logger.logp(Level.SEVERE, PasswordUtil.class.getName(), "decode_password", "PASSWORDUTIL_INVALID_BASE64_STRING");
                    return null;
                }

                if (encrypted_bytes.length > 0) {
                    // decrypt encrypted password byte[] with specified crypto algorithm

                    byte[] decrypted_bytes = null;

                    try {
                        decrypted_bytes = PasswordCipherUtil.decipher(encrypted_bytes, crypto_algorithm);
                    } catch (InvalidPasswordCipherException e) {
                        logger.logp(Level.SEVERE, PasswordUtil.class.getName(), "decode_password", "PASSWORDUTIL_CYPHER_EXCEPTION", e);
                        return null;
                    } catch (UnsupportedCryptoAlgorithmException e) {
                        logger.logp(Level.SEVERE, PasswordUtil.class.getName(), "decode_password", "PASSWORDUTIL_UNKNOWN_ALGORITHM_EXCEPTION", e);
                        return null;
                    }

                    if ((decrypted_bytes != null) && (decrypted_bytes.length > 0)) {
                        // convert decrypted password byte[] to string
                        decoded_string = convert_to_string(decrypted_bytes);
                    }
                }
            }

            if ((decoded_string != null) && (decoded_string.length() > 0)) {
                // append decoded string
                buffer.append(decoded_string);
            }
        }

        return buffer.toString();
    }
777230
public static function encryptOpenssl($textToEncrypt, string $secretHash = null, string $password = ''): ? string
  {
    if ( !$secretHash ){
      $secretHash = self::$salt;
    }
    if ( $length = openssl_cipher_iv_length(self::$method) ){
      $iv = substr(md5(self::$prefix.$password), 0, $length);
      return openssl_encrypt($textToEncrypt, self::$method, $secretHash, true, $iv);
    }
    return null;
  }
642052
public static function _decryptRijndael256 ($str, $key, $iv)
	{
		
		// If the string is empty
		
		if (empty ($str))
		{
			return '';
		}
		
		// Open the cypher
		
		$cypher		= mcrypt_module_open ('rijndael-256', '', 'ofb', '');
		
		// Set Key
		
		$key		= substr ($key, 0, mcrypt_enc_get_key_size ($cypher));
		
		// Initialise decryption
		
		mcrypt_generic_init ($cypher, $key, $iv);
		
		// Decrypt String
		
		$decrypted	= mdecrypt_generic ($cypher, $str);
		
		// Terminate encryption hander
		
		mcrypt_generic_deinit ($cypher);
		
		// Close Module
		
		mcrypt_module_close ($cypher);
		
		// Return decrypted string
		
		return $decrypted;
		
	}
190708
function (text /*:String*/) /*:Object*/ {
        
        var hashParts /*:Array*/ = text.split("&"),
            hashPart /*:Array*/ = null,
            hash /*:Object*/ = {};
        
        if (text.length > 0){
            for (var i=0, len=hashParts.length; i < len; i++){
                hashPart = hashParts[i].split("=");
                hash[decodeURIComponent(hashPart[0])] = decodeURIComponent(hashPart[1]);
            }
        }
        
        return hash;
    }
760076
private function load()
	{
		if(strlen($this->_method) == 0 || strlen($this->_key) == 0)
			return null;
		$m = mcrypt_module_open($this->_type, '', $this->_mode, '');
		if($m === false)
			return null;
		// This check is performed by mcrypt_generic_init, but it's better
		// to do it now, because mcrypt_generic_init does not return a
		// negative or false value if it fails.
		$ivsize = mcrypt_enc_get_iv_size($m);
		if(strlen($this->_iv) != $ivsize)
		{
			// In ECB (and some other modes), the IV is not used but still
			// required to have the this size by mcrypt_generic_init, so
			// let's make a fake one.
			if(strtolower($this->_mode) == "ecb")
				$ivsize = str_repeat("\0", $ivsize);
			else
				return null;
		}
		$r = @mcrypt_generic_init($m, $this->_key, $this->_iv);
		if($r < 0 || $r === false)
			return null;
		return $m;
	}
409472
private function checkModeBcrypt($password, $hash)
    {
        $this->cwsDebug->titleH2('Check password hash in BCRYPT mode');
        $this->cwsDebug->labelValue('Password', $password);
        $this->cwsDebug->labelValue('Hash', $hash);

        $checkHash = crypt($password, $hash);
        $this->cwsDebug->labelValue('Check hash', $checkHash);

        $result = $this->slowEquals($hash, $checkHash);
        $this->cwsDebug->labelValue('Valid?', ($result ? 'YES!' : 'NO...'));

        return $result;
    }
200001
public function decrypt($data, $key = null, $iv = null)
    {
        $data = base64_decode($data);

        if (!$iv) {
            $iv = substr($data, 0, static::DEFAULT_RANDOM_BYTE_LENGTH);

            $data = substr($data, static::DEFAULT_RANDOM_BYTE_LENGTH);
        } else {
            if (substr($data, 0, strlen($iv)) === $iv) {
                $data = substr($data, strlen($iv));
            }
        }

        $key = sha1($iv . $key);

        return $this->doDecrypt($data, $key);
    }
747145
public static function useFileEncryptionDriver(string $key, string $method = null): void
    {
        static::throwExceptionIfHasStarted();

        $driver = new FileEncryption();
        static::setKeyAndMethod($driver, $key, $method);

        static::$driver = $driver;
    }
922154
public function decodeMethod($crypt)
	{
		$string = $this->decrypt($crypt);

		return $this->encoder->decodeMethod($string);
	}
14842
public static function encrypt($text, $key, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
        {
            // Create IV for encryption
            $iv = mcrypt_create_iv(
                mcrypt_get_iv_size(
                    $algo,
                    $mode
                ),
                MCRYPT_RAND
            );

            // Encrypt text and append IV so it can be decrypted later
            $text = mcrypt_encrypt(
                $algo,
                hash('sha256', $key, true),
                $text,
                $mode,
                $iv
            ) . $iv;

            // Prefix text with HMAC so that IV cannot be changed
            return hash(
                'sha256',
                $key . $text
            ) . $text;
        }