Last active
April 21, 2019 19:05
-
-
Save guifcoelho/46fc6bb1f8a02e53afa0566011aa98a0 to your computer and use it in GitHub Desktop.
Laravel command to encrypt Services credentials file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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