Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Drag-n-drop BASE64 encoder/decoder

Without going into much detail I was required to encode a decent amount of files in Base64. The script below encodes/decodes either one file or many (from a directory). The script determines if a file has been encoded by looking at the header. If present, the script decodes the file, and if not, encodes it. This code isn't fool-proof however. It uses string manipulation to trim off the last three or last four characters from the object name. If what was trimmed starts with a period then the script assumes it's a file. If not, it assumes the object is a directory. This only functions for two or three character file extensions. Feel free to post any suggestions or possible upgrades to improve the functionality. Cheers!

Code
@echo off >NUL
Set "file=%~1"

REM [CHECK FOR FILE EXTENSION]
If "%file:~-4,1%"=="." goto :FILE
If "%file:~-3,1%"=="." goto :FILE
REM [IF NOT FILE, DECRYPT/ENCRYPT DIRECTORY]
goto :DIR
exit

:FILE
If "%file%"=="" GOTO:EOF
REM [CHECKS FOR BASE64 HEADER]
>nul find "-----BEGIN CERTIFICATE-----" "%file%" && (
  certutil -f -v -decode "%file%" "%file%"
) || (
  certutil -f -v -encode "%file%" "%file%"
)
exit

:DIR
REM [CATALOGS FILE(S) FROM DIRECTORY]
DIR /B /S "%file%" >"%temp%\list.ini"
Set "content=%temp%\list.ini"

REM [CHECKS FOR BASE64 HEADER IN FILE(S)]
Setlocal EnableDelayedExpansion
FOR /F "delims=" %%K IN (%content%) DO (
set "obj=%%K"

>nul find "-----BEGIN CERTIFICATE-----" "!obj!" && (
  certutil -f -v -decode "!obj!" "!obj!"
) || (
  certutil -f -v -encode "!obj!" "!obj!"
)

)
Del /F /Q "%content%"
exit


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Release] by MutatedArm0964Sep 24, 2026 09:51 AM 1 248 Sep 24, 2026 09:51 AM
Last Post: Anonynuk
[Source] by QismonNov 27, 2024 04:29 AM 2 307 Nov 27, 2024 04:29 AM
Last Post: mikeyp
[C#] by SmokyOct 28, 2022 11:17 AM 3 254 Oct 28, 2022 11:17 AM
Last Post: m0rty.