<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBS: Простой способ декодирования base64]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=6957</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6957&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBS: Простой способ декодирования base64».]]></description>
		<lastBuildDate>Tue, 10 Apr 2012 08:40:55 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=59091#p59091</link>
			<description><![CDATA[<p>Не удержался, позволил себе немного оптимизировать код. ) Уж очень идея понравилась.<br /></p><div class="codebox"><pre><code>
Function base64encode(data)
    With CreateObject(&quot;CDO.Message&quot;).BodyPart
        .Charset = &quot;utf-8&quot;
        .ContentTransferEncoding = &quot;base64&quot;
        With .GetDecodedContentStream
            .WriteText data
            .Flush
        End With
        With .GetEncodedContentStream
            base64encode = .ReadText(.Size - 2) &#039;Отрезаем перевод строки на хвосте
        End With
    End With
End Function

Function base64decode(data)
    With CreateObject(&quot;CDO.Message&quot;).BodyPart
        .ContentTransferEncoding = &quot;base64&quot;
        .Charset = &quot;windows-1251&quot;
        With .GetEncodedContentStream
            .WriteText data
            .Flush
        End With
        With .GetDecodedContentStream
            .Charset = &quot;utf-8&quot;
            base64decode = .ReadText
        End With
    End With
End Function</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Xameleon)]]></author>
			<pubDate>Tue, 10 Apr 2012 08:40:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=59091#p59091</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=59035#p59035</link>
			<description><![CDATA[<p>Супер ! ) А я и забыл совсем что у CDO есть такая возможность !</p>]]></description>
			<author><![CDATA[null@example.com (Xameleon)]]></author>
			<pubDate>Sun, 08 Apr 2012 17:33:38 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=59035#p59035</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=59034#p59034</link>
			<description><![CDATA[<p><strong>smaharbA</strong>, супер :-)</p>]]></description>
			<author><![CDATA[null@example.com (JSmаn)]]></author>
			<pubDate>Sun, 08 Apr 2012 17:33:36 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=59034#p59034</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=59030#p59030</link>
			<description><![CDATA[<div class="codebox"><pre><code>set cdo=CreateObject(&quot;CDO.Message&quot;)
set bp=cdo.BodyPart
bp.ContentTransferEncoding = &quot;base64&quot;
Set s=bp.GetEncodedContentStream
bp.Fields.Item(&quot;urn:schemas:mailheader:content-type&quot;).Value=&quot;text/plain; charset=&quot;&quot;windows-1251&quot;&quot;&quot;
bp.Fields.Update
s.WriteText &quot;wuDx/yDP8+/q6O0=&quot;
s.Flush
Set s = bp.GetDecodedContentStream
s.charset = &quot;windows-1251&quot;
msgbox s.ReadText</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Sun, 08 Apr 2012 14:59:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=59030#p59030</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58518#p58518</link>
			<description><![CDATA[<p>Посмотрел. Да, видел эту статью. ) И при чём тут корректность base64 ? И что такое классический base64 ? На сколько я понимаю, он всегда классический. base64 всегда кодируется байтовые массивы. ) Я спрашивал о корректности кодируемых данных. А т.к кодируется в этом случае именно байтовый массив, то о какой корректности может быть речь ? ) А сам метод кодирования заложен в объектную модель MSXML. Поэтому его я никак нарушить не могу. В моём случае он чёрный ящик. ) Поэтому кодирование, как бы я не изголялся, будет срабатывать всегда одинаково. ) Меняется лишь интерпретация данных, с которыми мы работаем.</p>]]></description>
			<author><![CDATA[null@example.com (Xameleon)]]></author>
			<pubDate>Wed, 28 Mar 2012 17:14:53 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58518#p58518</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58517#p58517</link>
			<description><![CDATA[<p>Вообще то - <a href="http://ru.wikipedia.org/wiki/Base64">да</a>.</p>]]></description>
			<author><![CDATA[null@example.com (mozers)]]></author>
			<pubDate>Wed, 28 Mar 2012 16:51:38 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58517#p58517</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58481#p58481</link>
			<description><![CDATA[<p>А стандарты корректности где то определены ? <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (Xameleon)]]></author>
			<pubDate>Tue, 27 Mar 2012 18:29:03 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58481#p58481</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58480#p58480</link>
			<description><![CDATA[<p>2<strong>Xameleon</strong><br />Наверное стоит упомянуть о том в какой кодировке конвертируется текст.<br />И о том, что результат резко отличается от классического base64 кодирования.<br />И хотя закодированный утилитой текст все таки может быть декодирован в строку utf-16le, но можно ли его считать корректным base64 кодом?</p>]]></description>
			<author><![CDATA[null@example.com (mozers)]]></author>
			<pubDate>Tue, 27 Mar 2012 18:17:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58480#p58480</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58471#p58471</link>
			<description><![CDATA[<p>Переправил код. Неправильно работали функции <strong>hexToStr</strong> и <strong>strToHex</strong>. Собрал функции в класс модуль <strong>clsEncoder</strong>. Сделал класс совместимым с HTA / WSH / WSF и т.п.</p><p>Оставил функции <br /><strong>encode(data, enctype)</strong> - функция кодирования byte() массива в hex / base64. enctype (0 - base64, 1-hex)<br /><strong>decode(data, enctype)</strong> - функция декодирования hex / base64 строки в byte() массив. enctype (0 - base64, 1-hex)<br /><strong>strToBin(data)</strong> - конвертация String в byte()<br /><strong>binToStr(data)</strong> - конвертация byte() в String<br /><strong>strToHex(srcstr)</strong> - кодирование String в Hex строку<br /><strong>hexToStr(ByVal hexstr)</strong> - декодирование Hex строки в исходный текст.<br /></p><div class="codebox"><pre><code>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;encoder / decoder&lt;/title&gt;
        &lt;meta charset=&quot;windows-1251&quot;&gt;
        &lt;style&gt;
        *{font-family:Tahoma;font-size:14px;}
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;table width=100% height=100%&gt;
            &lt;tr&gt;
                &lt;td colspan=4&gt;
                    Кодировщик
                    &lt;select id=&quot;selEncoder&quot;&gt;
                        &lt;option value=&quot;0&quot;&gt;base64&lt;/option&gt;
                        &lt;option value=&quot;1&quot;&gt;hex&lt;/option&gt;
                    &lt;/select&gt;
                    &lt;hr&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align=left&gt;Исходные данные&lt;/td&gt;
                &lt;td align=right&gt;&lt;button id=&quot;btnEncode&quot;&gt;Encode &gt;&lt;/button&gt;&lt;/td&gt;
                &lt;td align=left&gt;&lt;button id=&quot;btnDecode&quot;&gt;&lt; Decode&lt;/button&gt;&lt;/td&gt;
                &lt;td align=right&gt;Закодированные данные&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan=2 height=100% &gt;&lt;textarea id=&quot;txtDecoded&quot; style=&quot;width:100%;height:100%;&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;
                &lt;td colspan=2&gt;&lt;textarea id=&quot;txtEncoded&quot; style=&quot;width:100%;height:100%;&quot;&gt;&lt;/textarea&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
        &lt;script language=VBScript&gt;
            Option Explicit
            
            Dim encoder
            Set encoder = new clsEncoder

            Sub btnEncode_onclick()
                On Error Resume Next
                Select Case selEncoder.value
                Case 0
                    txtEncoded.value = encoder.encode(encoder.strToBin(txtDecoded.value),0)
                Case 1
                    txtEncoded.value = encoder.strToHex(txtDecoded.value)
                End Select
                if Err.Number &lt;&gt; 0 Then MsgBox Err.Description, vbCritical, document.title
            End Sub

            Sub btnDecode_onclick()
                On Error Resume Next
                Select Case selEncoder.value
                Case 0
                    txtDecoded.value = encoder.binToStr(encoder.decode(txtEncoded.value,0))
                Case 1
                    txtDecoded.value = encoder.hexToStr(txtEncoded.value)
                End Select
                if Err.Number &lt;&gt; 0 Then MsgBox Err.Description, vbCritical, document.title
            End Sub

            Class clsEncoder
                Private xmldoc, encTypes
                Private Sub Class_Initialize()
                    On Error Resume Next
                    encTypes = Array(&quot;bin.base64&quot;,&quot;bin.hex&quot;)
                    if isObject(document) then 
                        Set xmldoc = document.createElement(&quot;xml&quot;)
                    Else
                        Set xmldoc = CreateObject(&quot;htmlfile&quot;).createElement(&quot;xml&quot;)
                    End if
                End Sub
                 
                Function encode(data, enctype)
                    With xmldoc.createElement(&quot;enc&quot;)
                        .dataType = encTypes(enctype)
                        .nodeTypedValue = data
                        encode = Replace(.Text,vbLf,&quot;&quot;)
                    End With
                End Function

                Function decode(data, enctype)
                    With xmldoc.createElement(&quot;enc&quot;)
                        .dataType = encTypes(enctype)
                        .Text = data
                        decode = .nodeTypedValue
                    End With
                End Function

                Function strToBin(data)
                    With xmldoc.createElement(&quot;enc&quot;)
                        .dataType = &quot;bin.hex&quot;
                        .Text = strToHex(data)
                        strToBin = .nodeTypedValue
                    End With
                End Function

                Function binToStr(data)
                    With xmldoc.createElement(&quot;enc&quot;)
                        .dataType = &quot;bin.hex&quot;
                        .nodeTypedValue = data
                        binToStr = hexToStr(.Text)
                    End With
                End Function

                Function strToHex(srcstr)
                    Dim i: For i = 1 To LenB(srcstr)
                        strToHex = strToHex &amp; Right(&quot;0&quot; &amp; Hex(AscB(MidB(srcstr, i, 1))), 2)
                    Next
                End Function

                Function hexToStr(ByVal hexstr)
                    Dim i: For i = 1 To Len(hexstr) Step 2
                        hexToStr = hexToStr &amp; ChrB(&quot;&amp;H&quot; &amp; Mid(hexstr, i, 2))
                    Next
                End Function

            End Class

        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Xameleon)]]></author>
			<pubDate>Tue, 27 Mar 2012 16:17:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58471#p58471</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58273#p58273</link>
			<description><![CDATA[<p>Опубликовал оба HTA приложения уважаемого <strong>Xameleon</strong> в <a href="http://forum.script-coding.com/viewtopic.php?pid=58272#p58272">Коллекции</a>.<br />Позволил себе немного подправить код.<br />И если <strong>Base64EncoderDecoder.hta</strong> может пригодится искателям новых алгоритмов, то из <strong>XMLCodeTester.hta</strong> получился настоящий настольный инструмент для тестирования как кода так и установленных на машине версий MSXML.</p>]]></description>
			<author><![CDATA[null@example.com (mozers)]]></author>
			<pubDate>Thu, 22 Mar 2012 19:27:41 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58273#p58273</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58261#p58261</link>
			<description><![CDATA[<p>2<strong>badik</strong><br />Спасибо. Получил. Проверил.<br />Действительно файлик прекрасно парсится с помощью MSXML 3.0, 4.0, 5.0.<br />C MSXML 6.0 выдает ошибку разбора.<br />Факт весьма печальный <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (mozers)]]></author>
			<pubDate>Thu, 22 Mar 2012 16:36:06 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58261#p58261</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58198#p58198</link>
			<description><![CDATA[<div class="quotebox"><cite>mozers пишет:</cite><blockquote><p>2<strong>badik</strong></p><div class="quotebox"><blockquote><p>msxml6.dll: Ошибка разбора</p></blockquote></div><p>А можно взглянуть на эту строку целиком?</p></blockquote></div><p>Выслал вам на mail.ru</p>]]></description>
			<author><![CDATA[null@example.com (badik)]]></author>
			<pubDate>Thu, 22 Mar 2012 05:19:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58198#p58198</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58156#p58156</link>
			<description><![CDATA[<p>2<strong>badik</strong></p><div class="quotebox"><blockquote><p>msxml6.dll: Ошибка разбора</p></blockquote></div><p>А можно взглянуть на эту строку целиком?</p>]]></description>
			<author><![CDATA[null@example.com (mozers)]]></author>
			<pubDate>Wed, 21 Mar 2012 10:23:51 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58156#p58156</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58149#p58149</link>
			<description><![CDATA[<p>Про версии парсеров:<br />Ошибку выдал парсер версии 6.0.<br />Разбор парсером версии&nbsp; 5.0 прошёл (раньше не проходил ?!).</p><p>msxml6.dll: Ошибка разбора &#039;&#039;PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iV0lORE9XUy0xMjUxIj8+CjxQYWNrZXRF<br />UEQgeG1sbnM9InVybjpjYnItcnU6ZWQ6djIuMCIgRURObz0iND...&#039;&#039; как типа данных bin.base64.<br />код ошибки -2147467259</p><p>FIX: MSXML Does Not Parse Slash Mark Character with Base64 Encoded Data<br /><a href="http://support.microsoft.com/kb/301356/en-us">http://support.microsoft.com/kb/301356/en-us</a></p><br /><p>P.S <br />msxml6.dll <br />версия: 6.20.1076.0<br />название продукта: Microsoft(R) MSXML 6.0 SP2 <br />Из реестра<br /></p><div class="codebox"><pre><code>Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{88d96a05-f192-11d4-a65f-0040963251e5}\InProcServer32]
@=&quot;C:\\WINDOWS\\system32\\msxml6.dll&quot;
&quot;ThreadingModel&quot;=&quot;Both&quot;
&quot;Class&quot;=&quot;Microsoft.SqlServer.MSXML6.DOMDocument60Class&quot;
&quot;Assembly&quot;=&quot;Microsoft.SqlServer.msxml6_interop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91&quot;
&quot;RunTimeVersion&quot;=&quot;v2.0.50727&quot;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (badik)]]></author>
			<pubDate>Wed, 21 Mar 2012 06:03:41 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58149#p58149</guid>
		</item>
		<item>
			<title><![CDATA[Re: VBS: Простой способ декодирования base64]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=58141#p58141</link>
			<description><![CDATA[<p>2<strong>Xameleon</strong><br />Развитие первоначальной идеи пошло совсем в другом направлении <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />И хотя предложенное решение &quot;простым способом&quot; не назовешь, однако это действительно - новинка!<br />Такого способа, без привлечения ADODB.Stream, или замудренных математических вычислений, с использованием только функционала XML, я (да и все присутствующие) еще не видели.<br />Класс!</p>]]></description>
			<author><![CDATA[null@example.com (mozers)]]></author>
			<pubDate>Tue, 20 Mar 2012 19:27:48 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=58141#p58141</guid>
		</item>
	</channel>
</rss>
