fenhanxue Posted Wednesday at 04:26 AM Posted Wednesday at 04:26 AM This HTML file source code already contains encrypt and decrypt JS code. How can I convert it into Autoit3 code expandcollapse popup<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AES-CBC </title> <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script> </head> <body> <div class="container"> <main> <div class="card"> <div class="input-group"> <textarea id="inputText" placeholder="">Hello</textarea> </div> <div class="btn-group"> <button class="encrypt-btn" id="encryptBtn">encrypt</button> <button class="decrypt-btn" id="decryptBtn">decrypt</button> </div> <div id="encryptResult" class="result-section"> <h3>result:</h3> <div class="result-content" id="encryptedOutput"></div> </div> <div id="decryptResult" class="result-section"> <h3>result:</h3> <div class="result-content" id="decryptedOutput"></div> </div> </div> </div> <script> // encrypt function encrypt(plainText) { const mt = "bW8Jc63Uz7I1N5R9"; const ht = "0000000000000000"; const key = CryptoJS.enc.Utf8.parse(mt); const iv = CryptoJS.enc.Utf8.parse(ht); const encrypted = CryptoJS.AES.encrypt(plainText, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); const hexString = encrypted.ciphertext.toString(); const wordArray = CryptoJS.enc.Hex.parse(hexString); return CryptoJS.enc.Base64.stringify(wordArray); } // decrypt function decrypt(cipherText) { const mt = "bW8Jc63Uz7I1N5R9"; const ht = "0000000000000000"; const key = CryptoJS.enc.Utf8.parse(mt); const iv = CryptoJS.enc.Utf8.parse(ht); const parsedBase64 = CryptoJS.enc.Base64.parse(cipherText); //return parsedBase64; const hexString = CryptoJS.enc.Hex.stringify(parsedBase64); //return hexString; const decrypted = CryptoJS.AES.decrypt( { ciphertext: CryptoJS.enc.Hex.parse(hexString) }, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } ); return decrypted.toString(CryptoJS.enc.Utf8); } // 事件监听 encryptBtn.addEventListener('click', () => { const text = inputText.value.trim(); if (!text) { alert('please insert text first'); return; } try { const encrypted = encrypt(text); encryptedOutput.textContent = encrypted; encryptResult.style.display = 'block'; decryptResult.style.display = 'none'; } catch (e) { alert('error: ' + e.message); } }); decryptBtn.addEventListener('click', () => { const text = inputText.value.trim(); if (!text) { alert('please insert text first'); return; } try { const decrypted = decrypt(text); decryptedOutput.textContent = decrypted; decryptResult.style.display = 'block'; encryptResult.style.display = 'none'; } catch (e) { alert('error: ' + e.message); } }); </script> </body> </html> I have tryed the code below, but it dose not work: expandcollapse popupLocal $crypto_js = BinaryToString(InetRead('https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js')) ;1 encrypt Local $str = 'hello' Local $encrypt_code = 'var ciphertext = "'&$str&'"' & _ 'var mt = "bW8Jc63Uz7I1N5R9";' & _ 'var ht = "0000000000000000";' & _ 'var key = CryptoJS.enc.Utf8.parse(mt);' & _ 'var iv = CryptoJS.enc.Utf8.parse(ht);' & _ 'var encrypted = CryptoJS.AES.encrypt(plainText, key, {' & _ ' iv: iv,' & _ ' mode: CryptoJS.mode.CBC,' & _ ' padding: CryptoJS.pad.Pkcs7' & _ '});' & _ 'var hexString = encrypted.ciphertext.toString();' & _ 'var wordArray = CryptoJS.enc.Hex.parse(hexString);' ;return ; $nJS = ObjCreate("MSScriptControl.ScriptControl") $nJS.language = "JavaScript" $nJS.addcode($crypto_js&$encrypt_code) MsgBox(0,0,$nJS.eval('CryptoJS.enc.Base64.stringify(wordArray)') ) $nJS = Null ;2 decrypt Local $crypt_str = 'hgrGXJU0a5dpU8cXiBwrPw==' Local $decrypt_code ='var ciphertext = "'&$crypt_str&'"' & _ 'var mt = "bW8Jc63Uz7I1N5R9";' & _ 'var ht = "0000000000000000";' & _ 'var key = CryptoJS.enc.Utf8.parse(mt);' & _ 'var iv = CryptoJS.enc.Utf8.parse(ht);' & _ 'var parsedBase64 = CryptoJS.enc.Base64.parse(cipherText);' & _ 'var hexString = CryptoJS.enc.Hex.stringify(parsedBase64);' & _ 'var decrypted = CryptoJS.AES.decrypt(' & _ ' { ciphertext: CryptoJS.enc.Hex.parse(hexString) },' & _ ' key,' & _ ' { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }' & _ ');' $nJS = ObjCreate("MSScriptControl.ScriptControl") $nJS.language = "JavaScript" $nJS.addcode($crypto_js&$decrypt_code) MsgBox(0,0,$nJS.eval('decrypted.toString(CryptoJS.enc.Utf8);') ) $nJS = Null crypto-js.min.js
argumentum Posted Wednesday at 11:43 AM Posted Wednesday at 11:43 AM "Active development of CryptoJS has been discontinued. This library is no longer maintained." 7 hours ago, fenhanxue said: <title>AES-CBC </title> https://www.google.com/search?q=autoit+"AES-CBC" ..not much help but may serve as a starting point. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now