ã¾ããã¿ã¤ãã«éãã
ä½ã®å½¹ã«ç«ã¤ãã§ãããããã¾ãããã£ãã調ã¹ãã®ã§ã
- æ¦è¦
- OpenSSL ã®ã¤ã³ã¹ãã¼ã«
- æ¿å ¥ããã HTML ã½ã¼ã¹ã®ä½æ
- OpenSSL 㧠HTML ã½ã¼ã¹ãæå·å
- æ¿å ¥å¯¾è±¡ã® HTML ãä½æ
- Javascript ãä½æ
- æçµç㪠index.html
- ãã¾ã
æ¦è¦
ç®çã¨ãã¦ã¯ã HTML ã½ã¼ã¹ãè¦ãããã¨ãã«ã ã½ã¼ã¹ã³ã¼ããæå·åããã¦ãã¦ã ä¸ç®ã§ã¯ä¸èº«ãè¦ããªãããã«ãããã ä¸æ¹ããã¹ã¯ã¼ããç¥ã£ã¦ããç¹å®ã®äººã¯è¦ããããã«ãããã
ã¤ã¡ã¼ã¸ã¨ãã¦ã¯ã以ä¸ã®ãããªæµãã
- æ¿å ¥ãã HTML ã½ã¼ã¹ input.html ãä½æããæå·åãããã¼ã¿ (CIPHER_HTML ã¨è¡¨è¨) ãä½æããã
- æ¬æã® HTML ã® JavaScript å¤æ°çã« CIPHER_HTML ãä»£å ¥ããã
- å ¥åããã¯ã¹çãéãã¦ãã¹ã¯ã¼ããèªã¿è¾¼ã¿ã CIPHER_HTML ã復å·åãã¦ãæ¬æä¸ã« input.html ã表示ããã
ã¾ãããå¯ãã®éãã大ãã¦ã»ãã¥ã¢ã§ã¯ãªãã®ã§æ³¨æã§ãã ããã¾ã§ä¸è¬äººããé ãããç¨åº¦ã®ç®çã«ãã使ãã¾ããã æ®éã¯å ¨é¨ãµã¼ãã¼å´ã®å¦çã«ä»»ãã¾ãããã *1
OpenSSL ã®ã¤ã³ã¹ãã¼ã«
ã¾ã OpenSSL ãã¤ã³ã¹ãã¼ã«ããã ãããªè¨äºãèªãã§ã Windows ã¦ã¼ã¶ã¼ãªã chocolatey å ¥ãã¦ããã (ãåè¦)ã
choco install openssl
æ¿å ¥ããã HTML ã½ã¼ã¹ã®ä½æ
ããã input.html ãç¨æãããã å 容ã¯ä»¥ä¸ã®ããã«ãã¦ã¿ãã
<ul> <li>ç®æ¬¡</li> <li>OpenSSL ã®ã¤ã³ã¹ãã¼ã«</li> <li>æ¿å ¥ããã HTML ã½ã¼ã¹ã®ä½æ <ul> <li>ul/li ã ãã使ã£ãç°¡å㪠HTML</li> <li>ãããæ¿å ¥ããã HTML ãã§ãã</li> </ul> </li> <li>OpenSSL 㧠HTML ã½ã¼ã¹ãæå·å <ul> <li>æå·å</li> <li>ãªãã·ã§ã³è§£èª¬</li> <li>復å·åãã¹ã</li> </ul> </li> <li>æ¿å ¥å¯¾è±¡ã® HTML ãä½æ</li> <li>Javascript ãä½æ <ul> <li>CryptoJS ãç¨ãã¦å¾©å·</li> <li>復å·æã® HTML ã¸ã®æ¿å ¥</li> </ul> </li> </ul>
ãï¼ãHello World ã¨ããã£ã¨ç°¡åãªã®ã§ããã ããï¼
ã¾ãããããããã§ãããã§ãã æ¢ãã¦çç±ä»ããããªããè¤éã«å ¥ãåã«ãªã£ã¦ã HTML ææ¸ã§ãããã£ã¦ãããã¨ãåãã£ãæ¹ãè¯ãããªã¨ã
OpenSSL 㧠HTML ã½ã¼ã¹ãæå·å
æå·å
次ã¯ããã® input.html ã openssl ã§æå·åããã
openssl enc -e -aes-256-cbc -in input.html -out cipher.txt -pass pass:"password" -base64 -A -md md5
password
ã«ã¯ãã¹ã¯ã¼ããå
¥ããã
åºåçµæ㯠cipher.txt ã«åºåãããã
ä¸ã®ãããªæã (é·ãããã®ã§çç¥)ã
U2FsdGVkX18Fj3ws/[..]YGi5kqUV5499MizKUEk/LuA==
ãªãã·ã§ã³è§£èª¬
-e
: ã¨ã³ã³ã¼ãã¢ã¼ããã¤ã¾ããopenssl enc
ã§æå·åãããã¨ãæ示ããã-aes-256-cbc
: AAES-256-CBC æ¹å¼ã§æå·åãããæ£ç´ããç¥ããªãããå¾è¿°ã®å¾©å·å·¥ç¨ã¨åãå¿ è¦ããã-in <filename>
: å ¥åãã¡ã¤ã«åãæå®ããã-out <filename>
: åºåãã¡ã¤ã«åãæå®ããã-pass pass:<password>
: ãã¹ã¯ã¼ããæå®ããã-base64
: åºåã Base64 å½¢å¼ã«ããã (ããã©ã«ãã¯ãã¤ããªå½¢å¼)-A
:-base64
ã¨ä¸ç·ã«ä½¿ãã¨ãåºåã1è¡ã«ãªãã (åºå®å¹ ã§æ¹è¡ããªããªã)-md md5
: ãã¹ã¯ã¼ãããéµãä½ãéã®ãã¤ã¸ã§ã¹ãã¢ã«ã´ãªãºã ã MD5 ã«ããã- ããã©ã«ãã§ã¯ SHA256ãå¾è¿°ã® CryptoJS ããããã対å¿ãã¦ããªãã®ã§æå®ã
復å·åãã¹ã
ã¨ãããããããã®æå·åæãã¡ããã¨å¾©å·ã§ãããã¨ãã openssl ã§ç¢ºèªãã¦ãããã
ã³ãã³ãã¯ä»¥ä¸ã
openssl enc -d -aes-256-cbc -in cipher.txt -out decode.html -pass pass:"password" -base64 -A -md md5
-e
ã -d
ã«ãªã£ãã ãã§ã»ã¼åããããã¯ãã³ã¼ãã¢ã¼ãã§ãããã¨ãæå®ãããªãã·ã§ã³ã
ã¡ããã¨ãã³ã¼ãããã¾ãããï¼ (確èª)
ãã³ã¼ãããã¾ãããï¼ (å¨å§)
ããã次è¡ãã¾ãã(横æ´) *2
æ¿å ¥å¯¾è±¡ã® HTML ãä½æ
ã¨ããããã以ä¸ã®è¦ç´ ã ãå ¥ã£ã HTML ãä½ããã
- ãã¹ã¯ã¼ãå ¥åããã¯ã¹
- å ¥å確å®ç¨ã®ãã¿ã³
- å ¥åå¾ã«ä¸èº«ãæ¸ãæããäºå®ã® div ã¿ã°
ããã§ã¯ããã index.html ã¨å¼ã¼ãã
ãµã³ãã«ã¯ä»¥ä¸ã®éãã
<!DOCTYPE html> <html> <head> <title>æå·åã»å¾©å·ãµã³ãã«</title> </head> <body> <input type="text" id="pass_input" placeholder="ãã¹ã¯ã¼ããå ¥å" value="password"> <button onclick="decrypt()" id="pass_button">復å·å</button> <div id="output">-</div> <!-- å¾ã§ ãã®è¾ºã« script ã追å ã --> </body> </html>
ããã§ã以ä¸ã®ãããªãã¼ã¸ã表示ãããã¯ãã ã
button ã«ã¯ onclick=decrypt()
ã§ãå¾ã§ script å
ã§å®ç¾©ããé¢æ°ãå¼ã¹ãããã«ãã¦ããã
ä»ã¯ä½ãèµ·ããªãã
input ã«ã¯ããã©ã«ã㧠"password" ã¨ãããã¹ã¯ã¼ããå ¥ãããã«ãªã£ã¦ããã æ¬çªã§ã¯æ¶ãã¹ãã
input ã«å
¥ã£ã¦ãããã¹ã¯ã¼ããæ£ãããã°ã
<div id="output">-</div>
ã¨ãªã£ã¦ããã¨ããã«
input.html ã®ä¸èº«ãå
¥ãã
ã¨ãããããããªãããã«ãããã
Javascript ãä½æ
CryptoJS ãç¨ãã¦å¾©å·
ä¸è¿°ã®ããã®è¾ºã« script ã追å ãã¨ãããéãªã³ã¡ã³ããå ¥ããã¨ããã« script ã¿ã°ãã¶ã¡è¾¼ãã§ããã
å ·ä½çã«ã¯ä»¥ä¸ã®ãããªã³ã¼ããæ¸ãã
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script> <script> function decrypt() { const ciphertext = "U2FsdGVkX18Fj3ws/[..]YGi5kqUV5499MizKUEk/LuA=="; const key = document.getElementById('pass_input').value; const originalText = CryptoJS.AES.decrypt(ciphertext, key).toString(CryptoJS.enc.Utf8); document.getElementById('output').innerHTML = originalText; } </script>
ciphertext ã¯ãçç¥ãã¦ãããã cipher.txt ã®æååãã³ããããã ã¨ãã§ããªãé·ãã¨æããæ°ã«ããã³ããããã æ¹è¡ãå ¥ããã«ã³ããããã
CryptoJS ã使ã£ã¦ ciphertext ããã³ã¼ãããã
input.html ã®ä¸èº«ã復å
ãã㦠originalText ã«å
¥ãã
ããã <div id="output">-</div>
ã«æ¿å
¥ãããã¨ããå½¢ã ã
復å·æã® HTML ã¸ã®æ¿å ¥
å®éã«ãã£ã¦ã¿ããã
index.html ã«ä¸è¿°ã® script ãå ¥ãã¦ã input ã« "password" ã¨å ¥åãã ãã¿ã³ãæ¼ãããã input.html ãæ¿å ¥ãããã
以ä¸ã¯ãã®ãã¢ã§ããã
æçµç㪠index.html
ããä¸åº¦ãå ¨ä½ããããããã¦ããã
<!DOCTYPE html> <html> <head> <title>æå·åã»å¾©å·ãµã³ãã«</title> </head> <body> <input type="text" id="pass_input" placeholder="ãã¹ã¯ã¼ããå ¥å"> <button onclick="decrypt()" id="pass_button">復å·å</button> <div id="output">-</div> <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script> <script> function decrypt() { const ciphertext = "U2FsdGVkX18Fj3ws/[..]YGi5kqUV5499MizKUEk/LuA=="; const key = document.getElementById('pass_input').value; const originalText = CryptoJS.AES.decrypt(ciphertext, key).toString(CryptoJS.enc.Utf8); document.getElementById('output').innerHTML = originalText; } </script> </body> </html>
ããã§ã HTML ã½ã¼ã¹ä¸ã«ã¯å ¨ãæ¬æã®æåãå ¥ããªãããã«ãã¤ã¤ã ãã¹ã¯ã¼ããç¥ã£ã¦ã人ã ããä¸èº«ã表示ã§ããä»çµã¿ãã§ãããã£ãã
ãã ãããã ã¨ãå¹³æã«å¯¾ãã¦å¸¸ã«åãæå·æãçæãããã å¤åãåãã人ã«ã¯ããã¯ã©ãã¯ããã¦ãã¾ãã¨æãã®ã§è¦æ³¨æã ããã¾ã§ãéã³ç¨ã
ãã¾ã
ä»ã®ã¾ã¾ã ã¨ä½åãã¹ã¯ã¼ããå ¥åãã¦ãããããã«ãªã£ã¦ããã
æè§ãªã®ã§ããã¿ã³ãæ¼ãããå ¥åãã©ã¼ã ããã¿ã³ãæ¶ããããã«ãã¦ã ä¸åããå ¥åã§ããªãããã«ãã¦ãããã *3
å°ããã¹ã¯ã¼ããééããå ´åã®è¦æ ã¯ä¸ååãä»ãã¦ããã¾ããã
*1:ã§ãã¾ããã¯ã¦ãªããã°ã 㨠HTML ããå¼ããªãã®ã§â¦â¦ã
*2:ãããããã§ãã³ã¼ãã§ãã¦ãªãã¨ãè¨ãããã¨ãã¦ãã ãã¡ã¤ã«åééãã¦ãããããªããã¨ããããããè¨ããªãã®ã§â¦â¦ã
*3:æ´æ°ãããã³ã«æ»ããã