0

I decided to make a batch file that encrypts files using OpenSSL's AES-256-CBC.

I made it so that the first argument is the file path to be encrypted.

The batch file then copies the file and encrypts it adding the extension `.encw to its name.

Here is the script:

echo off
set file=%1
echo s
echo %file%
echo e
if [%1]==[] (
    echo Missing file parameter.
    exit /B
)
if exist %file% (
    echo %file%
    for %%a in (%file%) do set "p_dir=%%~dpa"
    for %%F in (%file%) do set "fname=%%~nxF"
    echo %p_dir%
    echo %fname%
    set encfile="%p_dir%%fname%.enc"
    echo openssl aes-256-cbc -a -salt -in %file% -out %encfile%
    echo %encfile%
) else (
echo File does not exist.
)
pause

This works when you open a command prompt and enter the path of the batch file and the path of the file to be encrypted.

Here's the output

But when someone were to open that file with it (dragging a file onto the batch in File Explorer) the new .enc copy is not created because of some reason the parent file and the file name are blank .

Here's the output

Why is this happening?

I made it so it would print the OpenSSL command instead of executing it to avoid issues.

Compo
  • 36,585
  • 5
  • 27
  • 39
Ethernet
  • 1
  • 5

0 Answers0