• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/security/cipher.php
  • Класс: BitrixMainSecurityCipher
  • Вызов: Cipher::decrypt
public function decrypt($data, $key)
{
	// Extract the initialisation vector and encrypted data
	$iv = substr($data, 0, $this->ivLength);
	$raw = substr($data, $this->ivLength);

	// Hash the key
	$keyHash = openssl_digest($iv.$key, $this->hashAlgorithm, true);

	// Decrypt
	$result = openssl_decrypt($raw, $this->cipherAlgorithm, $keyHash, OPENSSL_RAW_DATA, $iv);
	if($result === false)
	{
		throw new SecurityException("Decryption failed: ".openssl_error_string());
	}

	if($this->calculateHash)
	{
		//extract the hash and decrypted data
		$length = strlen($keyHash);
		$hash = substr($result, 0, $length);
		$result = substr($result, $length);

		//check the hash: may be the crypto key has changed? It shouldn't.
		$dataHash = openssl_digest($result, $this->hashAlgorithm, true);
		if($dataHash !== $hash)
		{
			throw new SecurityException("The hash is incorrect: the data was corrupted or a wrong key was supplied.");
		}
	}
	return $result;
}