Frontend Security Implementation Guide: Encryption Algorithms and Anti-Debugging Techniques

Algorithm Comparison

SHA-256 AES
Hash Algorithm Symmetric Encryption
Irreversible Reversible
No Key Storage Required Requires Key Storage

When securing passwords, hash functions are typically preferred over symmetric encryption algorithms. Hash algorithms like SHA-256 are more commonly recommended for password protection due to their one-way nature (irreversible), unlike symmetric encryption which can be reversed.

Security Analysis:

AES Encryption: Security relies primarily on key confidentiality and length. Longer keys provide enhanced security. Currently, AES-256 is considered highly secure.

SHA-256 Hashing: This robust hashing algorithm provides strong collision resistance, making it extremely unlikely for different inputs to produce identical hash values. However, evolvign collision attack methods may impact its security.

MD5: Generates 128-bit (16-byte) hash values, typically represented as 32 hexadecimal characters. While MD5 was once widely used, it's no longer recommended for high-security applications due to collision vulnerabilities and weak resistance.

Frontend Cryptography with crypto-js

The crypto-js library serves as a pure JavaScript cryptographic toolkit, offering various common encryption algorithms including AES, DES, Triple DES, Rabbit, MD5, SHA-1, and SHA-256. It aims to provide secure cryptographic implementations within browsers.

Key Features and Usage:

  1. Multiple Algorithm Support: Supports various symmetric and hash algorithms, creating a comprehensive cryptography toolkit.
  2. User-Friendly API: Provieds straightforward interfaces, making cryptographic operations accessible in JavaScript environments.
  3. Modular Design: Allows selective module imports to minimize library size.
  4. Standard Compatibility: API design aligns with Web Crypto API standards for consistent cross-environment usage.
  5. Easy Integration: Pure JavaScript implementation enables seamless browser embedding and Node.js compatibility.

Here's a basic example demonstrating AES encryption using Crypto-JS:

// Import CryptoJS library
const CryptoJS = require("crypto-js");

// Define key and plaintext
const secretKey = CryptoJS.enc.Utf8.parse("1234567890123456");
const plainText = "Hello, Crypto-JS!";

// Perform AES encryption
const encryptedData = CryptoJS.AES.encrypt(plainText, secretKey, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
});

// Output encrypted result
console.log("Encrypted: " + encryptedData.toString());

Configuring Anti-Crawling in vue.config.js

{
   from: path.resolve(__dirname, './public/robots.txt'),
   to: './'
}

While this prevents crawling, source code remains accessible through debugging. To prevent debugging:

Developer Tool Prevention

Monitor developer tool activation and close the page using window.close() when detected.

  1. Keyboard Shortcut Monitoring: Listen for F12, Ctrl+Shift+I (Windows), right-click context menu, and Ctrl+S to prevent local saves and overrides.
<script>
    document.addEventListener('keydown', function(event) {
        if (event.key === 'F12') {
            window.close();
            window.location = 'about:blank';
        } else if (event.ctrlKey && event.shiftKey && event.key === 'I') {
            window.close();
            window.location = 'about:blank';
        } else if (event.ctrlKey && event.key === 's') {
            event.preventDefault();
            window.close();
            window.location = 'about:blank';
        }
    });

    document.addEventListener('contextmenu', function() {
        window.close();
        window.location = 'about:blank';
    });
</script>
  1. Window Size Change Detection
<script>
    const initialHeight = window.innerHeight;
    const initialWidth = window.innerWidth;
    
    window.addEventListener('resize', function() {
        if (initialHeight !== window.innerHeight || initialWidth !== window.innerWidth) {
            window.close();
            window.location = 'about:blank';
        }
    });
</script>
  1. Console Detection Method
<script>
    function handleConsoleOpen() {
        window.close();
        window.location = 'about:blank';
        return '';
    }

    (function() {
        const testObject = /./;
        console.log(testObject);
        
        testObject.toString = function() {
            handleConsoleOpen();
        };
    })();
</script>

Tags: frontend-security cryptography web-security Encryption anti-debugging

Posted on Tue, 19 May 2026 02:23:31 +0000 by sirstrumalot