Defuse\Crypto\File::encryptFile PHP Method

encryptFile() public static method

Encrypts the input file, saving the ciphertext to the output file.
public static encryptFile ( string $inputFilename, string $outputFilename, Defuse\Crypto\Key $key )
$inputFilename string
$outputFilename string
$key Defuse\Crypto\Key
    public static function encryptFile($inputFilename, $outputFilename, Key $key)
    {
        self::encryptFileInternal($inputFilename, $outputFilename, KeyOrPassword::createFromKey($key));
    }

Usage Example

 /**
  * @param \File $file
  * @param null|Key $key
  * @return bool|\File
  * @throws InvalidInput
  * @throws CryptoException
  */
 public function encryptFile($file, $key = null)
 {
     $key = $this->getKey($key);
     $encryptedFilename = $file->getFullPath() . '.enc';
     try {
         File::encryptFile($file->getFullPath(), $encryptedFilename, $key);
         unlink($file->getFullPath());
         $file->Filename = $file->Filename . '.enc';
         $file->write();
         return $file;
     } catch (Exception $e) {
         print_r($e->getMessage());
         SS_Log::log(sprintf('Encryption exception while parsing "%s": %s', $file->Name, $e->getMessage()), SS_Log::ERR);
         return false;
     }
 }