ãããã§ï¼BASE64ã®ã¨ã³ã³ã¼ãï¼ãã³ã¼ãããæ¹æ³ãï¼WSH/JScriptã§ï¼ãã¤ããªã®ãã¡ã¤ã«ãããã¹ã符å·åï¼
BASE64ã使ãã°ï¼ãã¤ããªã®ãã¡ã¤ã«ãããã¹ããã¼ã¿ï¼è±æ°åï¼ã«å¤æã§ããã
ãã¡ããï¼å ã®ãã¡ã¤ã«ã«æ»ãäºãã§ããã
ã ããï¼
- ããã¡ã¤ã«ã®ã¢ãããã¼ããã¯ä¸è¦ã«ãªãã ï¼ãã¡ã¤ã«ã§ã¯ãªãï¼æååãæ¸ãè¾¼ãã§ã©ããã«ä¿åããã°ãããï¼
- ããã¡ã¤ã«ã®æ·»ä»ãã¯ä¸è¦ã«ãªãã ï¼ããã¹ãæååãã³ããããã ãã§ï¼ãã¡ã¤ã«ãéåä¿¡ã§ãããï¼
Base64ã¨ã¯
http://ja.wikipedia.org/wiki/Base64
- ãã¤ããªãè±æ°åæååã«å¤æããã
- ã¡ã¼ã«ã®æ·»ä»ãã¡ã¤ã«éä¿¡ãªã©ã®éã«ä½¿ããã¦ããæè¡ã
- ãã¼ã¿éã¯ç´138%ã¨ãªãã
以ä¸ã¯ï¼Windowsã®ãããï¼WSHï¼ã§
- ãã¤ããªã®ãã¡ã¤ã«ãï¼BASE64ã®æååã«å¤æããã
- BASE64ã®æååãï¼ãã¤ããªã®ãã¡ã¤ã«ã«å¤æããã
ããã®ãµã³ãã«ã³ã¼ãã
ã¨ã³ã³ã¼ãã»ãã³ã¼ãã®ä¸¡æ¹ã¨ãï¼ã³ãã³ãããã³ããããå®è¡ã§ããã
base64.js
/* BASE64ã®èªã¿æ¸ããè¡ãªãããã ã¨ã³ã³ã¼ãæ¹æ³ï¼ cscript //nologo base64.js encode ã¨ã³ã³ã¼ãããããã¡ã¤ã«ã®ãã¹ > hoge.txt ãã³ã¼ãæ¹æ³ï¼ cscript //nologo base64.js decode hoge.txt 復å ããããã¡ã¤ã«ã®ä¿åãã¹ */ // ----------------- ã³ãã³ãã©ã¤ã³å¼æ° -------------- var action_type = WScript.Arguments.Unnamed(0); // encode or decode //log( action_type ); // ----------------- é¢æ° -------------- function log(s){ WScript.Echo( s ); } // ã¨ã³ã³ã¼ãå®è¡ function base64encode( target_file_path ) { // ãã¡ã¤ã«ããã¤ããªãã¼ã¿ã¨ãã¦èªã¿åã var stream = new ActiveXObject('ADODB.Stream'); stream.Type = 1; // binary stream.Open(); stream.LoadFromFile( target_file_path ); var binary_data = stream.Read( -1 ); // -1:read all // æ°è¦XMLãã¼ã¿ãä½æ var xml = new ActiveXObject("Microsoft.XMLDOM"); xml.loadXML('<?xml version="1.0" ?> <root/>'); xml.documentElement.setAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes"); // ãã¤ããªãã¼ã¿ãæ ¼ç´ããããã®ãã¼ããä½æ var node = xml.createElement("file-node"); node.dataType = "bin.base64"; // ãã¤ããªãã¼ã¿ãæ ¼ç´ node.nodeTypedValue = binary_data; xml.documentElement.appendChild( node ); // ãã®ãã¼ãããBASE64ã¨ã³ã³ã¼ãæ¸ã¿æååãåãåºã var base64encoded_text = node.text; return base64encoded_text; }; // ãã³ã¼ãå®è¡ function base64decode( encoded_text_path, binary_file_save_path ) { // BASE64æååãåå¾ var fso_r = WScript.CreateObject( "Scripting.FileSystemObject" ); var base64str = fso_r.OpenTextFile( encoded_text_path, 1 ).ReadAll(); // æ°è¦XMLãã¼ã¿ãä½æ var xml = WScript.CreateObject("Microsoft.XMLDOM"); // BASE64æååãæ ¼ç´ããããã®ãã¼ããä½æ var node = xml.createElement("base64-node"); node.dataType = "bin.base64"; // ãã¤ããªãã¼ã¿ãåå¾ node.text = base64str; var binary_data = node.nodeTypedValue; // æ¸ã込㿠var sw = new ActiveXObject("ADODB.Stream"); sw.Type = 1; // binary sw.Open(); sw.Write( binary_data ); sw.SaveToFile( binary_file_save_path ); sw.Close(); }; // ----------------- ã¡ã¤ã³å¦ç -------------- if( action_type == "encode" ) { var target_file_path = WScript.Arguments.Unnamed(1); //log( target_file_path ); var ret = base64encode( target_file_path ); // ã¨ã³ã³ã¼ãçµæãåºå log( ret ); } else if( action_type == "decode" ) { var encoded_text_path = WScript.Arguments.Unnamed(1); var binary_file_save_path = WScript.Arguments.Unnamed(2); // ãã³ã¼ãçµæãä¿å base64decode( encoded_text_path, binary_file_save_path ); }
使ãæ¹ã¯ï¼åé ã®ã³ã¡ã³ãã«æ¸ãã¦ããéãã
符å·åã®ã¢ã«ã´ãªãºã ãã¾ã¨ãã«å®è£ ããäºã«åãæããã®ã§ã¯ãªãã¦ï¼
XMLãå¦çããããã®APIã«ä¸¸æããã¦ãããã¦ããï¼ã¨ããç¹ãé¢ç½ãã
å®è£ ä¸ã®åèï¼
JavaScriptã§Base64ã¨ã³ã³ã¼ãããã
http://d.hatena.ne.jp/takuya_1st/2009...
Microsoft.XMLDOMã§BASE64ãã³ã¼ã
http://apis.jpn.ph/fswiki/wiki.cgi?pa...
ã