<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Encrypt on Micha Kops&#39; Tech Notes</title>
    <link>https://www.hascode.com/tags/encrypt/</link>
    <description>Recent content in Encrypt on Micha Kops&#39; Tech Notes</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>Copyright © 2010 - 2025 Micha Kops. #e9d956c0c0154a221ad83c925346a8fa0e72f866</copyright>
    <lastBuildDate>Sun, 02 Feb 2020 00:00:00 +0100</lastBuildDate>
    <atom:link href="https://www.hascode.com/tags/encrypt/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Encrypt/Decrypt Text Content</title>
      <link>https://www.hascode.com/tools/encrypt/</link>
      <pubDate>Sun, 02 Feb 2020 00:00:00 +0100</pubDate>
      <guid>https://www.hascode.com/tools/encrypt/</guid>
      <description>&lt;!DOCTYPE html&gt;
&lt;html lang=&#34;en&#34;&gt;
&lt;head&gt;
    &lt;meta charset=&#34;UTF-8&#34;&gt;
    &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1.0&#34;&gt;
    &lt;title&gt;AES Encryption Tool&lt;/title&gt;
    &lt;script src=&#34;https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js&#34;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;div class=&#34;custom-tools&#34;&gt;
    &lt;h2&gt;AES Encryption Tool&lt;/h2&gt;

    &lt;label for=&#34;inputText&#34;&gt;Text to Encrypt:&lt;/label&gt;
    &lt;textarea id=&#34;inputText&#34; rows=&#34;5&#34; cols=&#34;50&#34;&gt;&lt;/textarea&gt;
    &lt;div class=&#34;button-group&#34;&gt;
      &lt;button onclick=&#34;copyToClipboard(&#39;inputText&#39;)&#34;&gt;Copy&lt;/button&gt;
      &lt;button onclick=&#34;pasteFromClipboard(&#39;inputText&#39;)&#34;&gt;Paste&lt;/button&gt;
    &lt;/div&gt;

    &lt;label for=&#34;password&#34;&gt;Password:&lt;/label&gt;
    &lt;input type=&#34;password&#34; id=&#34;password&#34;&gt;

    &lt;label for=&#34;salt&#34;&gt;Salt:&lt;/label&gt;
    &lt;input type=&#34;password&#34; id=&#34;salt&#34;&gt;

    &lt;label for=&#34;iv&#34;&gt;IV:&lt;/label&gt;
    &lt;input type=&#34;password&#34; id=&#34;iv&#34;&gt;
    &lt;div class=&#34;button-group&#34;&gt;
      &lt;button onclick=&#34;generateRandomIV()&#34;&gt;Generate IV&lt;/button&gt;
      &lt;button onclick=&#34;useFixedIV()&#34;&gt;Use Fixed IV&lt;/button&gt;
    &lt;/div&gt;

    &lt;div class=&#34;button-group&#34;&gt;
      &lt;button onclick=&#34;encryptText()&#34;&gt;Encrypt&lt;/button&gt;
      &lt;button onclick=&#34;decryptText()&#34;&gt;Decrypt&lt;/button&gt;
      &lt;button onclick=&#34;resetAll()&#34;&gt;Reset All&lt;/button&gt;
    &lt;/div&gt;

    &lt;label for=&#34;outputText&#34;&gt;Decrypted Text:&lt;/label&gt;
    &lt;textarea id=&#34;outputText&#34; rows=&#34;5&#34; cols=&#34;50&#34;&gt;&lt;/textarea&gt;
    &lt;div class=&#34;button-group&#34;&gt;
      &lt;button onclick=&#34;copyToClipboard(&#39;outputText&#39;)&#34;&gt;Copy&lt;/button&gt;
      &lt;button onclick=&#34;pasteFromClipboard(&#39;outputText&#39;)&#34;&gt;Paste&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;

    &lt;script&gt;
        function encryptText() {
            let text = document.getElementById(&#39;inputText&#39;).value;
            let password = document.getElementById(&#39;password&#39;).value;
            let salt = document.getElementById(&#39;salt&#39;).value;
            let iv = document.getElementById(&#39;iv&#39;).value;
            if (!text || !password || !salt || !iv) {
                alert(&#39;All fields are required!&#39;);
                return;
            }
            let key = CryptoJS.PBKDF2(password, CryptoJS.enc.Utf8.parse(salt), { keySize: 256 / 32, iterations: 65536 });
            let encrypted = CryptoJS.AES.encrypt(text, key, { iv: CryptoJS.enc.Utf8.parse(iv), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
            document.getElementById(&#39;outputText&#39;).value = encrypted.toString();
        }
        
        function decryptText() {
            let encryptedText = document.getElementById(&#39;outputText&#39;).value;
            let password = document.getElementById(&#39;password&#39;).value;
            let salt = document.getElementById(&#39;salt&#39;).value;
            let iv = document.getElementById(&#39;iv&#39;).value;
            if (!encryptedText || !password || !salt || !iv) {
                alert(&#39;All fields are required!&#39;);
                return;
            }
            let key = CryptoJS.PBKDF2(password, CryptoJS.enc.Utf8.parse(salt), { keySize: 256 / 32, iterations: 65536 });
            let decrypted = CryptoJS.AES.decrypt(encryptedText, key, { iv: CryptoJS.enc.Utf8.parse(iv), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
            document.getElementById(&#39;inputText&#39;).value = decrypted.toString(CryptoJS.enc.Utf8);
        }
        
        function generateRandomIV() {
            let randomIV = CryptoJS.lib.WordArray.random(16).toString(CryptoJS.enc.Hex);
            document.getElementById(&#39;iv&#39;).value = randomIV;
        }
        
        function useFixedIV() {
            document.getElementById(&#39;iv&#39;).value = &#34;AAAAAAAAAAAAAAAAAAAAAA==&#34;; // Fixed 16-byte IV in hex
        }
        
        function copyToClipboard(elementId) {
            let text = document.getElementById(elementId);
            text.select();
            document.execCommand(&#39;copy&#39;);
        }
        
        function pasteFromClipboard(elementId) {
            navigator.clipboard.readText().then(text =&gt; {
                document.getElementById(elementId).value = text;
            }).catch(err =&gt; {
                alert(&#39;Failed to read clipboard: &#39; + err);
            });
        }
        
        function resetAll() {
            document.getElementById(&#39;inputText&#39;).value = &#39;&#39;;
            document.getElementById(&#39;outputText&#39;).value = &#39;&#39;;
            document.getElementById(&#39;password&#39;).value = &#39;&#39;;
            document.getElementById(&#39;salt&#39;).value = &#39;&#39;;
            document.getElementById(&#39;iv&#39;).value = &#39;&#39;;
        }
    &lt;/script&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</description>
    </item>
  </channel>
</rss>
