Decrypts (but does not verify) a message

@param string $message - ciphertext message
@param string $key - encryption key (raw binary expected)
@param boolean $encoded - are we expecting an encoded string?
@return string
@throws Exception
978382
public static function decrypt($message, $key, $encoded = false)
    {
        if ($encoded) {
            $message = base64_decode($message, true);
            if ($message === false) {
                throw new Exception('Encryption failure');
            }
        }

        $nonceSize = openssl_cipher_iv_length(self::METHOD);
        $nonce = mb_substr($message, 0, $nonceSize, '8bit');
        $ciphertext = mb_substr($message, $nonceSize, null, '8bit');

        $plaintext = openssl_decrypt(
            $ciphertext,
            self::METHOD,
            $key,
            OPENSSL_RAW_DATA,
            $nonce
        );

        return $plaintext;
    }
111023
public function decrypt($encrypted, $key)
	{
		if (empty($encrypted))
			return null;

		list($identifier, $input) = explode(self::SEPARATOR_ALGORITHM, $encrypted, 2);

		if ($identifier !== self::IDENTIFIER)
			throw new Exception('Encryption can not be decrypted. Unsupported identifier: ' . $identifier);

		// Split the input into its parts
		$cipherSplit = explode(self::SEPARATOR_CRYPTO_PARTS, $input);
		$originalSize = intval($cipherSplit[0]);
		$iv = cryptoHelpers::toNumbers($cipherSplit[1]);
		$cipherText = $cipherSplit[2];

		// Set up encryption parameters
		$cipherIn = cryptoHelpers::toNumbers($cipherText);
		$keyAsNumbers = cryptoHelpers::toNumbers(bin2hex($key));
		$keyLength = count($keyAsNumbers);

		$decrypted = AES::decrypt(
			$cipherIn,
			$originalSize,
			AES::modeOfOperation_CBC,
			$keyAsNumbers,
			$keyLength,
			$iv
		);

		// Byte-array to text.
		$hexDecrypted = cryptoHelpers::toHex($decrypted);
		$retVal = pack("H*", $hexDecrypted);

		return $retVal;
	}
565258
public function decrypt($ciphertxt, $key = '', $ttl = 0)
    {
        if (empty($ciphertxt)) return $ciphertxt;
        if (empty($key)) $key = md5($this->key);
    
        $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
        $ikey ="-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
        $knum = 0;$i = 0;
        $tlen = @strlen($ciphertxt);
        while(isset($key{$i})) $knum +=ord($key{$i++});
        $ch1 = @$ciphertxt{$knum % $tlen};
        $nh1 = strpos($chars,$ch1);
        $ciphertxt = @substr_replace($ciphertxt,'',$knum % $tlen--,1);
        $ch2 = @$ciphertxt{$nh1 % $tlen};
        $nh2 = @strpos($chars,$ch2);
        $ciphertxt = @substr_replace($ciphertxt,'',$nh1 % $tlen--,1);
        $ch3 = @$ciphertxt{$nh2 % $tlen};
        $nh3 = @strpos($chars,$ch3);
        $ciphertxt = @substr_replace($ciphertxt,'',$nh2 % $tlen--,1);
        $nhnum = $nh1 + $nh2 + $nh3;
        $mdKey = substr(md5(md5(md5($key.$ch1).$ch2.$ikey).$ch3),$nhnum % 8,$knum % 8 + 16);
        $tmp = '';
        $j=0; $k = 0;
        $tlen = @strlen($ciphertxt);
        $klen = @strlen($mdKey);
        for ($i=0; $i<$tlen; $i++) {
            $k = $k == $klen ? 0 : $k;
            $j = strpos($chars,$ciphertxt{$i})-$nhnum - ord($mdKey{$k++});
            while ($j<0) $j+=64;
            $tmp .= $chars{$j};
        }
        $tmp = str_replace(array('-','_','.'), array('+','/','='), $tmp);
        $tmp = trim(base64_decode($tmp));
        
        if (preg_match("/\d{10}_/s", substr($tmp,0,11))){
            if ($ttl > 0 && (time() - substr($tmp,0,11) > $ttl)) {
                $tmp = null;
            }else{
                $tmp = substr($tmp, 11);
            }
        }
        return $tmp;
    }
656762
public function decrypt($encrypted, $privateKey)
    {
        $rsa = new RSA();
        $rsa->loadKey($privateKey);

        return $rsa->decrypt($encrypted);
    }
418438
public static function encrypt($message, $key=NULL)
	{
		if ($key != NULL)
			Yii::log('warning', 'Use of the `$key` parameter is deprecated', 'cii');
		
		$key = self::getEncryptionKey();

		try {
            $ciphertext = Crypto::Encrypt($message, $key);
        } catch (CryptoTestFailedException $ex) {
			Yii::log('Cannot safely perfrom encryption', 'error', 'cii');	
			throw new Exception('Cannot safely perform encryption');
        } catch (CannotPerformOperationException $ex) {
			Yii::log('Cannot safely perfrom encryption', 'error', 'cii');	
			throw new Exception('Cannot safely perform encryption');
        }
		
		return bin2hex($ciphertext);
	}
527734
public function decode($encrypted)
    {

        //$cipher_all = explode("/", $cipher_in);
        //$cipher = $cipher_all[0];

        $blocks = explode("|x", $encrypted);
        $delimiter = array_search("::", $blocks);


        $cipherStream = array_slice($blocks, 0, (int)$delimiter);


        unset($blocks[(int)$delimiter]);
        unset($blocks[(int)$delimiter + 1]);

        $publicKeyArray = array_slice($blocks, (int)$delimiter);

        $publicKey = implode('', $publicKeyArray);
        $privateKey = $this->key;

        $hashKey = sha1($privateKey . "+" . (string)$publicKey);
        $hashArray = str_split($hashKey);

        $counter = 0;
        for ($i = 0; $i < sizeof($cipherStream); $i++) {
            if ($counter > 40)
                $counter = 0;
            $cryptChar = hexdec($cipherStream[$i]) - ord((string)$hashArray[$counter]);
            $cryptChar -= floor($cryptChar / 127) * 127;
            $cipherText[$i] = chr($cryptChar);
            $counter++;
        }

        $plaintext = implode("", $cipherText);

        return $plaintext;
    }
694259
protected function decryptMessage(array $message)
    {
        $encryptor = new Encryptor($message['ToUserName'], $this->app['config']->get('token'), $this->app['config']->get('aes_key'));

        return $message = $encryptor->decrypt(
            $message['Encrypt'],
            $this->app['request']->get('msg_signature'),
            $this->app['request']->get('nonce'),
            $this->app['request']->get('timestamp')
        );
    }
581250
public function decrypt($payload, $unserialize = true)
    {
        $payload = $this->getJsonPayload($payload);

        $iv = base64_decode($payload['iv']);

        // Here we will decrypt the value. If we are able to successfully decrypt it
        // we will then unserialize it and return it out to the caller. If we are
        // unable to decrypt this value we will throw out an exception message.
        $decrypted = \openssl_decrypt(
            $payload['value'], $this->cipher, $this->key, 0, $iv
        );

        if ($decrypted === false) {
            throw new \Exception('Could not decrypt the data.');
        }

        return $unserialize ? unserialize($decrypted) : $decrypted;
    }
302251
public static function decode($encoded)
    {
        // Trying to decode null, eh?
        if (is_null($encoded) || empty($encoded))
        {
            return null;
        }

        // Unpack into array of characters
        $chars = str_split($encoded);

        // Convert the character array to an array of bytes
        $bytes = array();
        foreach ($chars as $char)
        {
            $bytes[] = ord($char);
        }

        $val = self::recursiveDecode($bytes);

        if (!empty($bytes))
        {
            throw new CborException("There are more bytes than expected in the CBOR byte array.");
        }

        return $val;
    }
545245
public function decrypt($crypttext, $key = null) {
        if(null !== $key) {
            $this->_key = md5($key);
        }

        $crypttext = base64_decode($crypttext);
        $plaintext = '';
        $td        = mcrypt_module_open($this->_cypher, '', self::MODE, '');
        $ivsize    = mcrypt_enc_get_iv_size($td);
        $iv        = substr($crypttext, 0, $ivsize);
        $crypttext = substr($crypttext, $ivsize);
        if ($iv) {
            mcrypt_generic_init($td, $this->_key, $iv);
            $plaintext = mdecrypt_generic($td, $crypttext);
        }
        return trim($plaintext);
    }
977210
public static final String decrypt(String secretKey, String encryptedText) {
        if (encryptedText == null) {
            return null;
        }
        if (encryptedText.startsWith("$CRYPT::")) { //$NON-NLS-1$
            byte[] decoded = Base64.decodeBase64(encryptedText.substring(8));
            Cipher cipher;
            try {
                SecretKeySpec skeySpec = keySpecFromSecretKey(secretKey);
                
                cipher = Cipher.getInstance("AES"); //$NON-NLS-1$
                cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) {
                throw new RuntimeException(e);
            }
            try {
                return new String(cipher.doFinal(decoded));
            } catch (IllegalBlockSizeException | BadPaddingException e) {
                throw new RuntimeException(e);
            }
        } else {
            return encryptedText;
        }
    }
1347710
public static function encrypt($message, $key)
    {
        $md5Key = md5($key);
        
        $encrypted = mcrypt_encrypt(
            MCRYPT_RIJNDAEL_256, 
            $md5Key, 
            $message, 
            MCRYPT_MODE_CBC, 
            md5($md5Key)
        );
        
        $encoded_encryption = base64_encode($encrypted);
        return $encoded_encryption;
    }
1328321
public static function decrypt($data, $key = null)
    {
        is_null($key) && $key = Config::get('auth_key');
        return unserialize(self::cry($data, 2, $key));
    }
1036893
function decrypt($ciphertext)
    {
        if ($this->k <= 0) {
            return false;
        }

        $ciphertext = str_split($ciphertext, $this->k);
        $ciphertext[count($ciphertext) - 1] = str_pad($ciphertext[count($ciphertext) - 1], $this->k, chr(0), STR_PAD_LEFT);

        $plaintext = '';

        switch ($this->encryptionMode) {
            case self::ENCRYPTION_NONE:
                $decrypt = '_raw_encrypt';
                break;
            case self::ENCRYPTION_PKCS1:
                $decrypt = '_rsaes_pkcs1_v1_5_decrypt';
                break;
            //case self::ENCRYPTION_OAEP:
            default:
                $decrypt = '_rsaes_oaep_decrypt';
        }

        foreach ($ciphertext as $c) {
            $temp = $this->$decrypt($c);
            if ($temp === false) {
                return false;
            }
            $plaintext.= $temp;
        }

        return $plaintext;
    }
1332533
public String decrypt(String encrypted) throws Exception {

        byte[] decodedValue = Base64Coder.decode(encrypted.toCharArray());

        Cipher c = getCipher(Cipher.DECRYPT_MODE);
        byte[] decValue = c.doFinal(decodedValue);

        return new String(decValue);
    }
112536
public function encrypt($message)
    {

        $salt = \openssl_random_pseudo_bytes(8, $cryptStrong);

        if (false === $cryptStrong || false === $salt)
        {
            throw new Exceptions\Runtime('IV generation failed');
        }

        $salted = '';
        $dx     = '';

        while (strlen($salted) < 48)
        {
            $dx     = md5($dx . $this->password . $salt, true);
            $salted .= $dx;
        }

        list($key, $iv) = $this->salted($salted);
        $encryptedData = openssl_encrypt($message, $this->method, $key, OPENSSL_RAW_DATA, $iv);

        return base64_encode($salt . $encryptedData);
    }
6208
public function decrypt($cipher_string, $cipher_key)
    {
        $cipher_key = $this->_genKey($cipher_key);

        $hmacSize = 64;
        $hmacString = mb_substr($cipher_string, 0, $hmacSize, "8bit");
        $cipher_text = mb_substr($cipher_string, $hmacSize, null, "8bit");

        if(!$this->validHmac($hmacString, $this->_genHmac($cipher_text, $cipher_key)))
            return false;

        $ivSize = openssl_cipher_iv_length('AES-256-CBC');
        $iv = mb_substr($cipher_text, 0, $ivSize, '8bit');
        $cipher_text = mb_substr($cipher_text, $ivSize, null, '8bit');

        return openssl_decrypt($cipher_text, 'AES-256-CBC', $cipher_key, OPENSSL_RAW_DATA, $iv);
    }