<div class="codetitle"> <span><a style="CURSOR: pointer" data="27579" class="copybut" id="copybut27579" onclick="doCopy('code27579')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다.</div> <div class="codebody" id="code27579"> <br><!DOCTYPE HTML PUBLIC "-//W3C/ /DTD HTML 4.0 Transitional//EN"> <br> <br> <br><title> XMLDOM 및 ADODB.Stream을 사용하여 base64 인코딩 및 디코딩 구현</title> <br><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <br><style type="text/css" title=""> <br>#textarea1 ,#textarea3, #textarea5 { 배경색: #EEEEEE } <br></style> <br><br><body> ; XMLDOM 및 ADODB.Stream을 사용하여 base64 인코딩 및 디코딩<br><h5>By: CuiXiPing(无心)</h5> <br><br><h4>1. ;/ h4> <br><br><input type=file name="file1" id="file1" size="50"> <br><input type="button" value="base64 인코딩" onclick= "if(!file1.value){alert('파일을 선택하세요')}else{textarea1.value=Base64EncodeFile(file1.value)}"> <br><br> id="textarea1"row="6" cols="80" readOnly></textarea> <br><br><h4>2. 텍스트의 Base64 인코딩<br><br>< 입력 유형="버튼" 값="base64 인코딩" onclick="textarea3.value=Base64EncodeText(textarea2.value)"> <br><br><br><textarea id="textarea2"rows="4 " cols="40">일본상품 단호히 불매운동</textarea> <br><textarea id="textarea3"rows="4" cols="40" readOnly></textarea> <br><br> <h4>3. 텍스트의 Base64 디코딩<br><br><input type="button" value="base64 decodering" onclick="textarea5.value=Base64DecodeText(textarea4.value)" > <br><br> <br><textarea id="textarea4"rows="4" cols="40">vOG 9rXW1sbI1bv1</textarea> <br><textarea id="textarea5"row =" 4" cols="40" readOnly></textarea> <br><br><script 언어="javaScript"> <br><!-- <BR>function Base64EncodeFile(fileSpec){ <br> var xml_dom = new ActiveXObject("MSXML2.DOMDocument"); <br>var ado_stream = new ActiveXObject("ADODB.Stream") <BR>var tmpNode = xml_dom.createElement("tmpNode"); .dataType = "bin.base64"; <BR><BR>ado_stream.Type = 1; // 1=adTypeBinary <BR>if(ado_stream.state==0){ // 0=adStateClosed 1=adStateOpen <BR> ado_stream.Open(); <BR>} <br>ado_stream.LoadFromFile(fileSpec); <br>tmpNode.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll <BR>ado_stream.Close(); <BR><BR>return tmpNode.text; <BR>} <BR>function Base64EncodeText(TextStr){ <BR>var xml_dom = new ActiveXObject("MSXML2.DOMDocument") <br>var ado_stream = new ActiveXObject(" ADODB.Stream"); <br>var tmpNode = xml_dom.createElement("tmpNode"); <BR>tmpNode.dataType = "bin.base64"; <BR><BR>ado_stream.Charset = "gb2312"; <BR>ado_stream.Type = 2; // 1=adTypeBinary 2=adTypeText <BR>if(ado_stream.state==0){ // 0=adStateClosed 1=adStateOpen <BR>ado_stream.Open(); } <br>ado_stream.WriteText(TextStr); <br>ado_stream.Position = 0; <BR>ado_stream.Type = 1; // 1=adTypeBinary 2=adTypeText <BR>tmpNode.nodeTypedValue = ado_stream.Read(-1 ); // -1=adReadAll <BR>ado_stream.Close(); <BR><BR>return tmpNode.text; <BR>} <BR>function Base64DecodeText(Base64Str){ <BR>var xml_dom = new ActiveXObject( "MSXML2 .DOMDocument"); <BR>var ado_stream = new ActiveXObject("ADODB.Stream"); <br>var tmpNode = xml_dom.createElement("tmpNode") <br>tmpNode.dataType = "bin. base64"; <BR>tmpNode.text = Base64Str; <BR><BR>ado_stream.Charset = "gb2312"; <BR>ado_stream.Type = 1; // 1=adTypeBinary 2=adTypeText <BR>ado_stream.Open( ); <BR>ado_stream.Write(tmpNode.nodeTypedValue); <BR>ado_stream.Position = 0; <br>ado_stream.Type = 2; // 1=adTypeBinary 2=adTypeText <br>var str = ado_stream.ReadText( -1); // -1=adReadAll <BR>ado_stream.Close() <BR><BR>return str <BR>} <BR></script> 🎜>< /body> <br></html></h4> </div>