/**
  * @param \File $file
  * @param null|Key $key
  * @return bool|\File
  * @throws InvalidInput
  * @throws CryptoException
  */
 public function decryptFile($file, $key = null)
 {
     $key = $this->getKey($key);
     $decryptedFilename = str_replace('.enc', '', $file->getFullPath());
     try {
         File::decryptFile($file->getFullPath(), $decryptedFilename, $key);
         unlink($file->getFullPath());
         $file->Filename = str_replace('.enc', '', $file->Filename);
         $file->Name = str_replace('.enc', '', $file->Name);
         $file->write();
         return $file;
     } catch (Exception $e) {
         SS_Log::log(sprintf('Decryption exception while parsing "%s": %s', $file->Name, $e->getMessage()), SS_Log::ERR);
         return false;
     }
 }
 /**
  * Returns a stream representation of a string.
  *
  * @param string $contents The string
  *
  * @return resource The stream with the string contents.
  */
 private function getStreamFromString($contents)
 {
     $resource = fopen('php://memory', 'r+b');
     File::writeBytes($resource, $contents);
     rewind($resource);
     return $resource;
 }
 /**
  * Encrypts a string.
  *
  * @param string $contents The string to encrypt.
  *
  * @return string The encrypted string.
  */
 protected function encrypt($contents)
 {
     $resource = fopen('php://memory', 'r+b');
     File::writeBytes($resource, $contents);
     rewind($resource);
     $out = fopen('php://memory', 'r+b');
     File::encryptResource($resource, $out, $this->key);
     rewind($out);
     return stream_get_contents($out);
 }