Passwords Secured Using PKzip


By: nbrane
August 3, 2014

Here's a batchfile I just wrote. I tested most of the features and it seemed to work, but it's a "beta" prototype! you may need to tinker with it, and you will need PKZIP and PKUNZIP utilities: http://pkzip.soft32.com/free-download/ (My version is OLD, so newer version you may need to tweak, especially "getname" subroutine).

::======= PASS.BAT
@echo off & setlocal
:: set your zipped-filename here. It has no relation to your primary text
:: file name! I'm just using the batchfile name for the zipfile.
:: pkzip may be found at: http://pkzip.soft32.com/free-download/
:: among others
set zipfile=%~n0
set pass=%1
if not defined pass (
echo usage: %~n0 password [search-string]
echo If no search-string is given, the original textfile will be
echo restored to allow editing. If search-string is %~n0, and the
echo file exists, it will be re-zipped using the given password.
goto :eof
)

call :getname
echo.
echo primary (text) filename: "%primary%", zipfilename: "%zipfile%"
if /i "%~n2" equ "%~n0" goto :rezip

set s=%*
for /f "tokens=1*" %%a in ("%s%") do set string=%%b
if not defined string (
if exist %primary% (
echo %primary% is about to be overwritten!
set z=
set /p z=any key aborts
if defined z goto :eof
echo.
echo.
)
pkunzip -o -s%pass% %zipfile%>nul&&echo %primary% Unzip success||(
echo %primary% Unzip failed
goto :eof
)
echo CAUTION! primary text file "%primary%" has been restored UNPROTECTED
) else (
echo.
echo.
echo searching for "%string%" in %zipfile%
:: first verify the zipfile and password are valid
pkunzip -s%pass% -c %zipfile%>nul||(echo zipfile or pass bad&goto :eof)
:: now do the search
echo ------------------------------------------------------------------
pkunzip -s%pass% -c %zipfile%| find /i "%string%"||echo "%string%" not found in %zipfile%
)
goto :Eof


:rezip
set ok=
if not defined primary (
echo no primary file yet established
set ok=y
set primary=
set /p primary=filename to be secured with pass %pass%:
if not defined primary goto :eof
)

if not exist %primary% echo no file %primary%&goto :eof
if not defined ok (
echo.
echo ===============================
echo preparing to re-zip your primary file. The primary file will be
echo removed and the previous zip contents overwritten with %primary%!
set /p ok=ok to proceed? y or Y for yes:
echo.
echo.
)
if /i "%ok:~0,1%" equ "y" (
pkzip -s%pass% -m %zipfile% %primary%>nul&&echo Rezip success||echo Rezip failed!
) else (
echo "%primary%" not re-zipped
)
goto :eof

:getname
for /f "tokens=9" %%a in ('pkunzip -v %zipfile%^| find /i "deflat"') do set primary=%%a
goto :eof
::========= end batch


The textfile can be any format, but it's best to put the password on the same line with the string that you can use to recognize it. f/e:

programmiing forum http:/www.computing.net compute_THIS username NBRANE
sarah's (ex-girlfriends) new phone# 222-3333 ssn: 888-99-1111 d.o.b: 1/1/90
visa card: 0000-9999-8888-7777 exp 3/18 security code 111
mastercard 1234-5678-8765-4321
vin# of the mercedes 8888888888888888 plate# 2L8-2H8
dairyland insurance policy# 0000 agent: jake drake


so in the above

PASS mypwd CARD
will give you any lines that have "card" in the line (upper or lower case no matter)

PASS mypwd

unzips the file for editing

PASS mypwd pass

rezips (and removes the primary text) file after editing.


Need more help?
Describe your Problem
Example: Hard Drive Not Detected on My PC

Ask Question