How to solve “gpg: public key decryption failed: Bad passphrase” in batch file

If you are trying to decrypt a file or a bunch of files using batch file in windows you will write something like this:

gpg --pinentry-mode=loopback --batch --yes --passphrase "abc%123" --decrypt-files *.pgp

and you put the above code in a .bat file and run it but you got an error like:

gpg: public key decryption failed: Bad passphrase

You are 1000% sure the passphrase is correct .. well the problem is in the passphrase itself as it contains a special character that needs to be escaped .. in the above example , the passphrase : “abc%123” must be written like this: “abc%%123” as %% is the escape of % … for a complete list of batch file escape characters , check this link

in case if you are wondering about the meaning of
–pinentry-mode=loopback¬†¬†
it is used to prevent the gui from pooping up and asking for the passphrase.

Another important point , to make the batch option work without problem .. you have to make sure that the encrypted file extensions is *.pgp

How to sanitize raw data in Laravel

When doing a raw data query from user input like this:

$someVariable = Input::get("some_variable");

$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = '$someVariable'") );

we are at risk of SQL injection , to avoid that we can bin parameters to our query like this:

$someVariable = Input::get("some_variable");

$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), array(
   'somevariable' => $someVariable,
 ));

 

Another point is that if we want to do a raw that doesn’t return a value, we can do it like this

DB::statement( 'ALTER TABLE HS_Request AUTO_INCREMENT=1111' );

and that way can take parameters as well

DB::statement( 'ALTER TABLE HS_Request AUTO_INCREMENT=:incrementStart', array('incrementStart' => 1111) );