/** * @param McryptContainer $container */ public function setContainer(McryptContainer $container) { $this->data = $container->getData(); $this->passwordSalt = $container->getPasswordSalt(); $this->initializationVector = $container->getInitializationVector(); $this->cipher = $container->getCipher(); }
/** * Decrypts the container data with the given key * or returns false if the key is not valid. * * @param McryptContainer $container * @param string $key * @return bool|string */ public function decrypt(McryptContainer $container, $key) { $data = rtrim(mcrypt_decrypt($container->getCipher(), $this->getKeyHash($key, $container->getPasswordSalt()), $container->getData(), $this->mode, $container->getInitializationVector()), ""); $checkSum = substr($data, 0, 40); $data = substr($data, 40); if (sha1($data) != $checkSum) { return false; } return $data; }