This can (technically) be done entirely within Batch, By Creating an encryption\decryption VBS script from within batch that can be called with the name of the Variable whose Data you wish to encrypt\decrypt.
Note: The below scipt is an Independant Subprogram.
Hybrid Batch Vbs Encrypter / Decrypter for passwords or other variables.
Performs the action on data stored in the defined file - does not create the file.
Note: file extension in vbs to match the filetype you save password/text to.
To use this program Call it with the name of the Variable you wish to set and the offset to perform.
However your Main program takes user input:
Set /p YourVariableName=
Store the Input to a File
ECHO %YourVariableName%>YourSaveFile.txt
Call it with a positive offset (IE: +26) to encrypt, and an equivalent Negative offset to Decrypt. (IE: -26)
CALL "Insert Filepath To Encrypter.bat Here" YourVariableName +26
Encrypter.bat
@ECHO OFF
REM :: Do NOT modify the variable names Below, DO INSERT the filepath you used to Store the Data Being Encrypted / Decrypted.
Set "VarName=%~1"
Set "offset=%~2"
Set "SaveLoc=Your Filepath Here"
<"%saveLoc%" (
Set /p encryptData=
)
(
ECHO Dim objFSO 'File System Object
ECHO Set objFSO = CreateObject("Scripting.FileSystemObject"^)
ECHO Dim objTS 'Text Stream Object
ECHO Const ForWriting = 2
ECHO Set objTS = objFSO.OpenTextFile("%SaveLoc%", ForWriting, True^)
ECHO objTS.Write(encode("%encryptData%"^)^)
ECHO wscript.sleep "1000"
ECHO function encode(s^)
ECHO For i = 1 To Len(s^)
ECHO newtxt = Mid( s, i, 1^)
ECHO newtxt = Chr(Asc(newtxt^) %offset%^)
ECHO coded = coded + (newtxt^)
ECHO Next
ECHO encode = coded
ECHO End function
ECHO objTS.Close(^)
ECHO Set bjFSO = Nothing 'Destroy the object.
ECHO Set objTS = Nothing 'Destroy the object.
) >%TEMP%\encrypter.vbs
START /wait %TEMP%\encrypter.vbs
DEL /Q "%TEMP%\encrypter.vbs"
GOTO :EOF
```
>"%TEMP%\EncodeBase64.tmp" echo string
, next encode the temporary file"%TEMP%\EncodeBase64.tmp"
with a utility, then read the encoded string from file withfor /F "usebackq delims=" %%I in ("%TEMP%\EncodeBase64.tmp") do set "StringVariable=%%I"
and finally delete the temporary file withdel "%TEMP%\EncodeBase64.tmp"
? – LumumbaCertUtil.exe
, a native tool of Windows with many useful verbs? for instance,CertUtil -encode
andCertUtil -decode
encode/decode a file to/from Base64; (also helpful:CertUtil -hashfile [{SHA1|MD5}]
computes a hash value over a file...) - with a temporary file you can also process strings... – Unsteadycertutil
solution as an answer. – Mossgrown