Hier ist ein Powershell Einzeiler Sie von einer cmd-Konsole ausführen können thatll Base64 codiert einen String G.
powershell "[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"Hello world!\"))"
Es ist wahrscheinlich nicht so schnell wie Lösung des npocmaka, aber man kann set a console macro with it.
doskey btoa=powershell "[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"$*\"))"
doskey atob=powershell "[Text.Encoding]::UTF8.GetString([convert]::FromBase64String(\"$*\"))"
btoa Hello world!
btoa This is fun.
btoa wheeeeee!
atob SGVsbG8gd29ybGQh
Beachten Sie, dass doskey
nicht in Batch-Skripten funktioniert - nur die Konsole. Wenn Sie dies in einem Batch-Skript verwenden möchten, nehmen Sie eine Funktion vor.
@echo off
setlocal
call :btoa b64[0] "Hello world!"
call :btoa b64[1] "This is fun."
call :btoa b64[2] "wheeeeee!"
call :atob b64[3] SGVsbG8gd29ybGQh
set b64
goto :EOF
:btoa <var_to_set> <str>
for /f "delims=" %%I in (
'powershell "[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"%~2\"))"'
) do set "%~1=%%I"
goto :EOF
:atob <var_to_set> <str>
for /f "delims=" %%I in (
'powershell "[Text.Encoding]::UTF8.GetString([convert]::FromBase64String(\"%~2\"))"'
) do set "%~1=%%I"
goto :EOF
Oder wenn Sie würde eine Charge + JScript Hybrid bevorzugen:
@if (@[email protected]) @then
@echo off & setlocal
call :btoa b64[0] "Hello world!"
call :btoa b64[1] "This is fun."
call :btoa b64[2] "wheeeeee!"
call :atob b64[3] SGVsbG8gd29ybGQh
set b64
goto :EOF
:btoa <var_to_set> <str>
:atob <var_to_set> <str>
for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0" %0 "%~2"') do set "%~1=%%I"
goto :EOF
@end // end batch/begin JScript hybrid code
var htmlfile = WSH.CreateObject('htmlfile');
htmlfile.write('<meta http-equiv="x-ua-compatible" content="IE=10" />');
WSH.Echo(htmlfile.parentWindow[WSH.Arguments(0).substr(1)](WSH.Arguments(1)));
Edit: Batch + VBScript-Hybrid für @Hackoo:
<!-- : batch portion
@echo off & setlocal
call :btoa b64[0] "Hello world!"
call :btoa b64[1] "This is fun."
call :btoa b64[2] "wheeeeee!"
call :atob b64[3] SGVsbG8gd29ybGQh
set b64
goto :EOF
:btoa <var_to_set> <str>
:atob <var_to_set> <str>
for /f "delims=" %%I in ('cscript /nologo "%~f0?.wsf" %0 "%~2"') do set "%~1=%%I"
goto :EOF
: VBScript -->
<job>
<script language="VBScript">
Set htmlfile = WSH.CreateObject("htmlfile")
htmlfile.write("<meta http-equiv='x-ua-compatible' content='IE=10' />")
if WSH.Arguments(0) = ":btoa" then
WScript.Echo htmlfile.parentWindow.btoa(WSH.Arguments(1))
else
WScript.Echo htmlfile.parentWindow.atob(WSH.Arguments(1))
end if
</script>
</job>
Was ist mit dem Schreiben der Zeichenfolge in eine temporäre Datei mit '>"% TEMP% \ EncodeBase64.tmp "Echo-String', als nächstes kodieren Sie die temporäre Datei '"% TEMP% \ EncodeBase64.tmp "' mit einem Dienstprogramm, dann lesen die codierte Zeichenfolge aus Datei mit 'for/F" usebackq delims = "%% Ich in ("% TEMP% \ EncodeBase64.tmp ") setze" StringVariable = %% I "' und lösche schließlich die temporäre Datei mit 'del" % TEMP% \ EncodeBase64.tmp "'? – Mofi
Hast du jemals von 'CertUtil.exe' gehört, einem nativen Tool von Windows mit vielen nützlichen Verben?zum Beispiel, 'CertUtil -encode' und' CertUtil-decode' kodieren/dekodieren eine Datei zu/von Base64; (auch hilfreich: 'CertUtil -hashfile [{SHA1 | MD5}]' berechnet einen Hash-Wert über eine Datei ...) - mit einer temporären Datei können Sie auch Strings bearbeiten ... – aschipfl
Einer von euch muss schreiben die "Certutil" -Lösung als Antwort. – rojo