Certutil-decode/encode Base64/hex strings. Print symbols by HEX Code_dos/bat

Source: Internet
Author: User
Tags base64

1. The thing I used this for wad to decode and encode BASE64. (-decode and-encode command switches). It has two annoying features here-for decode and encode it needs
-----End Certificate-----and-----BEGIN certificate-----at begining and at Base64 file. And it prints decoded file in lines with max length of symbols.
So this is are two very very very simple scripts. Certutil to decode and encode base64 a string (and dealing with begin and end tags) (there are No. checks for file existence and if the parameters-are-correct-i on rely error certutil ES):

Decode

@echo off
setlocal
for/f "delims== Tokens=1"%%a in (' type%1 ') do (
	set encoded=%%a
)
rem two Additi Onal lines are needed by certutil
echo-----BEGIN Certificate----->%2.tmp
echo%encoded%>>%2.tmp
Echo-----End Certificate----->>%2.tmp


certutil/decode%2.tmp%2
del/s/q%2.tmp
endlocal

Encode

@echo off
setlocal
certutil/encode%1%1.encoded
rem Create a empty file break
>%2

setlocal enabledelayedexpansion
(
	for/f "eol=-"%%a in (' Type%1.encoded ') does (rem This is not
		Works-lef T an empty spaxes after the typed file
		rem null< (set/p #=%%a) >>%1.encoded
		
		set Result=!res Ult!%%a
	)
endlocal & Set result=%result%
echo%result%>>%2%
del/s/q
Endlocal

The bad thing is this base64 strings are stored in a variable and there ' a limitations for it ' s size. But for a small strings it wokrs.

2. Much more interesting. In the help it shows that there ' s an-decodehex switch. And I is surprised to find that there ' s also a undocumentes Switch-encodehex (Strange-decodehex looks more dangerous , because it can be used to produce binaries). Here's an example structure of encoded file:

Copy Code code as follows:

0000 3d 0d 0a-X=...set 3d set y= in the same.
0010 0d 0a--6f-2a 2a (2a). Echo **%x%%y%*
0020 2a

(Just as every hex editor)
This is my attempt to create file, set LF and CR to variables Smile-and I still don ' t know why it is unsuccessful It prints "§↕" (any help here would be welcomed-i don t know what goes).
Edit:i ' ve set DEC codes instead HEX. Anyway still not works.
In fact the data this is behind the hexes are not Necessary-it's only for visualisation.
To decode the "sample just use" This (if this above be saved in Sample.hex):

certutil -decodehex sample.hex not.working.bat

Any way it works for creation of the famous beep.bat:

0000 65 63 68 6f 20 07
This pattern can is used for creation of the bat that echoes a random symbols by hex. Just edit the last character.
And this is a pattern for setting a symbol by hex to%#% variable (just edit the last character):
0000 73 65 74 20 78 3d 15 0d
Anyway there are few more things ' I want to try with this smile

Here's a how forfiles can is used for hex symbols

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.