src/Security/Crypter.php
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;
	}
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;
	}
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 ; }
decrypts a message

@param string $encrypted
@param string $key

@return string
@throws Exception
decrypts a message