Skip to content

Instantly share code, notes, and snippets.

@guifcoelho
Last active April 21, 2019 19:05
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/46fc6bb1f8a02e53afa0566011aa98a0 to your computer and use it in GitHub Desktop.
Save guifcoelho/46fc6bb1f8a02e53afa0566011aa98a0 to your computer and use it in GitHub Desktop.
Laravel command to encrypt Services credentials file
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Defuse\Crypto\File;
use Dotenv\Dotenv;
class EncryptServiceKeys extends Command
{
protected $signature = 'encrypt-service-keys {serviceName} {inputFileName} {outputFileName} {encryptPassword}';
public function __construct(){
parent::__construct();
}
public function handle(){
$service = $this->argument('serviceName');
$inputFile = $this->argument('inputFileName');
$pathInputFile = app_path("Services/{$service}/Keys/{$inputFile}");
$outputFile = dirname($pathInputFile)."/{$this->argument('outputFileName')}";
$encryptPassword = $this->argument('encryptPassword');
File::encryptFileWithPassword($pathInputFile, $outputFile, $encryptPassword);
return $this->info("File '{$pathInputFile}' encrypted into '{$outputFile}'");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment