-
Notifications
You must be signed in to change notification settings - Fork 1
/
zCrypt.bat
142 lines (126 loc) · 4.26 KB
/
zCrypt.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@echo off
title zCrypt v1.5
set VaultName=Documents
set password=YOURPASSWORD
set VaultPath=%VaultName%\
set aesKey=7g3f8j2w9
set Authenticated=false
set new=true
if exist %VaultPath% set new=false
if exist %VaultName%.7z set new=false
if %new%==true mkdir %VaultName%
:login
cls
echo ______ __
echo ____ / ____/______ ______ / /_
echo /_ / / / / ___/ / / / __ \/ __/
echo / /_/ /___/ / / /_/ / /_/ / /_
echo /___/\____/_/ \__, / .___/\__/
echo /____/_/ v1.5
echo.
echo Welcome to zCrypt, type "help" to view all commands.
if %Authenticated%==true echo. && goto :sectorAsk
if %new%==true echo \%VaultPath% folder created, files stored inside this folder can now be encrypted.
echo.
:actionask
set/p "action=> "
if %action%==encrypt call :InitForEncrypt
if %action%==decrypt call :InitForDecrypt
if %action%==newkey call :NewKey
if %action%==help call :Help
if %action%==clear goto :login
if %action%==cls goto :login
if %action%==done goto :done
if %action%==exit exit
echo Command "%action%" not recognised, type "help" to view all commands.
goto :actionask
:done
echo This will delete \%VaultPath%, are you sure? (y/n)
set/p "delete=> "
if %delete%==y rmdir %VaultPath% /q /s && goto :actionask
if %delete%==n goto :actionask
goto :done
:InitForEncrypt
if exist %VaultName%.7z echo Files are already encrypted. && goto :actionask
echo Use 1 layer encryption or 2 layer encryption (1/2)?
set/p "layer=> "
if %layer%==1 goto :1layer
if %layer%==2 goto :1layer
echo Invalid choice.
goto :InitForEncrypt
:1layer
echo Encrypting \%VaultPath%, this may take a while.
FOR /f "delims=" %%G IN ('dir /s /b /a-d %VaultPath%') DO if /i "%%~xG" neq ".aes" (call :Encrypt "%%G")
if %layer%==2 goto :2layer
goto :actionask
:2layer
echo Adding \%VaultPath% to %VaultName%.7z, this may take a while.
7z a %VaultName%.7z -pSsvdFxQ3N7Z7 -mhe %VaultPath% >NUL
rmdir %VaultPath% /q /s
goto :actionask
:InitForDecrypt
if exist %VaultName% set name=\%VaultName%\
if exist %VaultName%.7z set name=%VaultName%.7z
if %Authenticated%==true goto :sectorAsk
if %Authenticated%==false echo Enter your decryption password to decrypt %name%.
:GetPass
set /p "pass=> "
if NOT %pass%==%password% echo Decryption password incorrect, please try again. && goto :GetPass
if %pass%==%password% set Authenticated=true && goto :login
:sectorAsk
echo Decrypt specific folder? (y/n)
set/p "sector=> "
if %sector%==y goto :spec
if %sector%==n goto :nospec
echo Invalid choice.
goto :sectorAsk
:spec
echo Enter the name of the folder you want to decrypt.
set/p "specFolder=> "
set specPath=%VaultName%\%specFolder%
if NOT exist %VaultName%.7z echo Decrypting %specPath%, this may take a while. && goto :1layerdspec
echo Extracting %specPath%, this may take a while.
7z e %VaultName%.7z -spf -pSsvdFxQ3N7Z7 %specPath% -r >NUL
echo Decrypting %specPath%, this may take a while.
goto :1layerdspec
:nospec
echo Extracting \%Vaultname%.7z, this may take a while.
if exist %VaultName%.7z 7z x %VaultName%.7z -pSsvdFxQ3N7Z7 >NUL && del /q %VaultName%.7z >NUL
echo Decrypting \%VaultPath%, this may take a while.
:1layerd
FOR /f "delims=" %%G IN ('dir /s /b /a-d %VaultPath%') DO (call :Decrypt "%%G")
goto :actionask
:1layerdspec
FOR /f "delims=" %%G IN ('dir /s /b /a-d %specPath%') DO (call :Decrypt "%%G")
goto :actionask
:Encrypt
aes -e %aesKey% "%~1" "%~1.aes" >NUL
del /f "%~1"
exit /b
:Decrypt
aes -d %aesKey% "%~1" "%~dpn1" >NUL
del /f "%~1"
exit /b
:newkeyfail
echo Can't create new keys when files are encrypted.
goto :actionask
:NewKey
if exist %VaultName%.7z goto :newkeyfail
if exist %VaultPath%*.aes goto :newkeyfail
echo Enter Key Name:
set/p "KeyName=> "
echo Enter Key Content:
set/p "KeyContent=> "
if NOT exist %VaultPath%Keys\ mkdir %VaultPath%Keys\
echo %KeyContent% > "%VaultPath%Keys\%KeyName%.txt"
echo Created %KeyName%.txt
goto :actionask
:Help
echo encrypt - encrypts files stored in \%VaultPath%.
echo decrypt - decrypts all files stored in \%VaultPath%.
echo newkey - create a new text file in \%VaultPath%Keys\.
echo help - displays this text.
echo clear, cls - clears the console.
echo done - delete decrypted files.
echo exit - closes zCrypt.
goto :actionask