Skip to content

Instantly share code, notes, and snippets.

@guifcoelho
Created April 21, 2019 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guifcoelho/2779791b09502df7a2b5e3c494fef94f to your computer and use it in GitHub Desktop.
Save guifcoelho/2779791b09502df7a2b5e3c494fef94f to your computer and use it in GitHub Desktop.
Laravel command to download and decrypt service keys
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Defuse\Crypto\File;
use Dotenv\Dotenv;
class DecryptServiceKeys extends Command{
protected $signature = 'decrypt-service-keys {serviceName} {outputFileName}';
public function __construct(){
parent::__construct();
}
public function handle(){
$service = $this->argument('serviceName');
$encryptedFile = app_path("Services/{$service}/Keys/credentials.encrypt");
$downloadUrl = config('services.'.strtolower($service).'.credentials_file_url');
$password = config('services.'.strtolower($service).'.encryption_password');
file_put_contents($encryptedFile, fopen($downloadUrl, 'r'));
$outputFile = dirname($encryptedFile)."/{$this->argument('outputFileName')}";
File::decryptFileWithPassword($encryptedFile, $outputFile, $password);
return $this->info("File '{$encryptedFile}' decrypted into '{$outputFile}'");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment