0

I wanna use a batch-File to generate a SHA1-Key from user input(online-tools are not allowed) and show it on the console. For hashing I use certutil. Following my code:

@ECHO OFF
TITLE MyBatchFile
ECHO Please enter the value
ECHO ===========================================
SET /p var=
ECHO %var%>temp_file.tmp
certutil -hashfile temp_file.tmp SHA1
PAUSE
DEL temp_file.tmp
EXIT

It works everything, except writing into the file temp_file.temp. There I always have a carriage return and a space and I really don't get it how to remove those. For Hashing I need the exact string and no additional spaces and carriage returns. I was looking for sevaral solutions in the web(e.g. following code) but I didn't found anyone that worked.

if exist "temp_file.tmp" findstr /R "^." "temp_file.tmp" >"file.tmp"
if exist "file.tmp" for %%I in ("file.tmp") do if %%~zI == 0 (del "file.tmp") else move /Y "file.tmp" "temp_file.tmp"

How can I write into the temp-File without any additional spaces, carriage returns, etc. or how can I remove these in the file? Thank you for your answers

Phil

double-beep
  • 5,031
  • 17
  • 33
  • 41
Phil
  • 9
  • 2
  • try https://stackoverflow.com/questions/38771114/saving-result-of-certutil-hashfile-to-a-variable-and-remove-spaces-of-the-hash/38772234#38772234 – elzooilogico Sep 07 '20 at 09:40
  • Tried that one out but also didn't work :( – Phil Sep 07 '20 at 12:05
  • replace your line `ECHO %var%>temp_file.tmp` with `echo|set /P ="%var%">temp_file.tmp` – Gerhard Sep 07 '20 at 13:51
  • @Gerhard: Thank you, your answer solved the problem. I suppose the carriage return comes from the enter button when you finish the typing. – Phil Sep 08 '20 at 07:50

0 Answers0