示例#1
0
 /**
  * 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;
 }
示例#2
0
 /**
  * @return McryptContainer
  */
 public function getContainer()
 {
     $container = new McryptContainer();
     $container->setData($this->data);
     $container->setPasswordSalt($this->passwordSalt);
     $container->setInitializationVector($this->initializationVector);
     $container->setCipher($this->cipher);
     return $container;
 }