:stringToHex @echo off del tmp.hex >nul 2>nul del tmp.str >nul 2>nul if "%~1" equ "" ( echo no string passed exit /b 1 ) echo|set /p=%~1 >tmp.str ::(echo(%~1)>tmp.str rem certutil -dump tmp.str certutil -encodehex tmp.str tmp.hex >nul setlocal enableDelayedExpansion set "hex_str=" for /f "usebackq tokens=2 delims= " %%A in ("tmp.hex") do ( set "line=%%A" set hex_str=!hex_str!!line:~0,48! set hex_str=!hex_str: =! ) set hex_str=%hex_str:~0,-2% echo !hex_str!
!! Note that the stackoverflow editor may mess up the tab character. tokens=2 delims= " after the dividends there should be one TAB .
requires a string passed as an argument. See also the debnham : hexDump function , which you can use instead of certutil.
source share