如何在 Windows 中编码/解码文件?

如何在 Windows 中编码/解码文件?

我想编写一个简单的 Java 程序来反转文件的所有字节。它应该通过编码破坏文件,并在解码后使其可访问。我需要注意什么吗?

我之所以问这个问题,是因为我以前写过类似的程序,但它没用,因为解码后文件仍然损坏。我需要记住什么吗,比如文件的头部部分之类的?

答案1

如果我理解了这个问题,你可以尝试:certutil.exe

  • 解码十六进制:

    certutil -f -decodehex some_file.hex some_file_out.ext

  • 编码十六进制:

    certutil -f -decodehex some_file.ext some_file_out.hex

  • 解码 Base64:

    certutil -f -decode some_file.b64 some_file_out.ext

  • Base64 编码:

    certutil -f -encode some_file.ext some_file_out.b64


  • 对于解码 base64:

@echo off 

rem :: do some task #1 ::
rem :: do some task #2 ::
rem :: do some task #3 ::
rem :: ............... ::
rem :: do some task #n ::
rem :: ----------------::
rem :: decode (itself = %~f0) file in runtime 

2>nul >nul ( 
"%__appdir__%certutil.exe" -f -decode "%~f0" "%temp%\some_file_out_sample.txt"
) || goto :^(

rem :: do some another task #1 ::
rem :: do some another task #2 ::
rem :: do some another task #3 ::
rem :: ....................... ::
rem :: do some another task #n ::
rem :: ------------------------::

rem :: when finished :: 
exit /b

:^(
echo/Error decoding file & exit /b

-----BEGIN CERTIFICATE-----
IFRoaXMgaXMgZm9yIHNhbXBsZSBmaWxlIHRvIGVuY29kZS9kZWNvZGUNCg==
-----END CERTIFICATE-----

  • 对于解码十六进制:

@echo off 

rem :: do some task #1 ::
rem :: do some task #2 ::
rem :: do some task #3 ::
rem :: ............... ::
rem :: do some task #n ::
rem :: ----------------::
rem :: echo/ hexdecimal string to file in runtime and decode 

(
   echo/0000 20 54 68 69 73 20 69 73  20 66 6f 72 20 73 61 6d
   echo/0010 70 6c 65 20 66 69 6c 65  20 74 6f 20 65 6e 63 6f
   echo/0020 64 65 2f 64 65 63 6f 64  65 0d 0a

) > "%temp%\some_file.hex" && ( 
2>nul >nul %__appdir__%certutil.exe -f -decodehex "%temp%\some_file.hex" "%temp%\some_file_out_sample.log"
) || goto :^(

rem :: do some another task #1 ::
rem :: do some another task #2 ::
rem :: do some another task #3 ::
rem :: ....................... ::
rem :: do some another task #n ::
rem :: -----------------------::

rem :: when finished :: 
exit /b

:^(
echo/Error decoding file & exit /b

笔记:base64 字符串将解码文件:“some_file_out_sample.txt/.log”并将其解码为文件:

“这是用于编码/解码的示例文件”

相关内容