Example #1
0
 /**
  * {@inheritdoc}
  */
 public function decrypt(ResourceInterface $resource, BackendInterface $backend, array $options = array())
 {
     $processed = false;
     $metadata = $backend->getMetadata();
     while (!$processed) {
         if ($metadata->needsPassphrase) {
             $metadata->passphrase = $backend->getIo()->askHiddenResponse('Enter passphrase: ');
         } else {
             // there is no way of misstyping, retry will make a infinite loop.
             $processed = true;
         }
         $cipher = new Cipher();
         foreach ($resource as $file) {
             if (!$file->isCrypted()) {
                 $file->setSourceFile($file->getTargetFile());
             }
             try {
                 $file->setTargetContent($cipher->decrypt($file->getSourceContent(), $metadata));
                 $processed = true;
             } catch (\Exception $e) {
             }
         }
     }
     return $resource;
 }
Example #2
0
 public function decrypt(ResourceInterface $resource, BackendInterface $backend, array $options = array())
 {
     foreach ($resource as $file) {
         if (!$file->isCrypted()) {
             $file->setSourceFile($file->getTargetFile());
         }
     }
     $pathEncrypted = $resource->isCrypted() ? $resource->getSourceFile() : $resource->getTargetFile();
     $io = $backend->getIo();
     $metadata = $backend->getMetadata();
     $defaultArguments = $this->getDefaultArguments(isset($options['write']) ? $options['write'] : false, $io->isVerbose());
     if (!$metadata->asymmetric) {
         $isOk = false;
         while (!$isOk) {
             $passphrase = $io->askHiddenResponse('Enter passphrase: ');
             $command = sprintf('gpg --no-use-agent %s --passphrase "%s" -d < %s', $defaultArguments, $passphrase, $pathEncrypted);
             try {
                 $resource->setTargetContent($this->exec($io, 'Decrypt files', $command, null, false));
                 $isOk = true;
             } catch (\Exception $e) {
             }
         }
     } else {
         $command = sprintf('gpg --no-verbose -d < %s', $pathEncrypted);
         $resource->setTargetContent($this->exec($io, 'Decrypt file', $command, null, false));
     }
     return $resource;
 }