This project showcases a JavaScript-based encryption and decryption application utilizing AES (Advanced Encryption Standard) encryption via the CryptoJS library. With an intuitive UI, users can easily encrypt text using a secret key and decrypt it when needed. It serves as an excellent learning resource for frontend enthusiasts interested in implementing secure data handling.
The project includes the following key components:
The HTML file defines the layout, including a form for input, output sections, and buttons for user interaction.
<div class="textBox">
<input type="password" id="secretKey" placeholder="Enter secret key" autocomplete="off">
<span id="toggleSecretKey">🙈</span>
</div>
The JavaScript (script.js
) file implements the core encryption and decryption logic using the CryptoJS library.
function encryptText() {
const plainText = document.getElementById('plainText').value;
const secretKey = document.getElementById('secretKey').value;
if (!plainText || !secretKey) {
alert('Please provide both plain text and secret key.');
return;
}
const encrypted = CryptoJS.AES.encrypt(plainText, secretKey).toString();
document.getElementById('encryptedText').value = encrypted;
}
function decryptText() {
const encryptedText = document.getElementById('encryptedTextInput').value;
const secretKey = document.getElementById('secretKey').value;
if (!encryptedText || !secretKey) {
alert('Please provide both encrypted text and secret key.');
return;
}
try {
const decrypted = CryptoJS.AES.decrypt(encryptedText, secretKey).toString(CryptoJS.enc.Utf8);
if (!decrypted) throw new Error();
document.getElementById('decryptedText').value = decrypted;
} catch {
alert('Decryption failed. Please check the secret key and encrypted text.');
}
}
navigator.clipboard
API.The styles.css
file ensures a clean, responsive design for optimal user experience. It includes styles for:
By working through this project, you will:
This project highlights the practical use of AES encryption in securing data, coupled with an interactive and user-friendly interface. Whether you’re a beginner or an experienced developer, building this project is a great way to delve into secure JavaScript programming.
✅ Note: This project includes valid, well-documented comments within the code for better understanding.
🔗 Repository Link: GitHub Repository
Project link: https://vijaywhat.github.io/encrypt/