PDFVault Pro – Secure PDF Encryption
/* — CSS SEPARATION START — */
@import url(‘https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap’);:root {
–primary: #10B981; /* Emerald-500 */
–bg-dark: #022C22;
}body {
font-family: ‘Inter’, sans-serif;
transition: background-color 0.3s, color 0.3s;
}/* Lock Animation */
.lock-shackle {
transform-origin: 70% 30%;
transition: transform 0.3s ease;
}
.locked .lock-shackle {
transform: translateY(4px);
}/* Loading Spinner */
.loader {
border: 3px solid #f3f3f3;
border-radius: 50%;
border-top: 3px solid #10B981;
width: 20px;
height: 20px;
animation: spin 1s linear infinite;
}@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}/* Dropzone Active */
.dropzone-active {
border-color: #10B981 !important;
background-color: rgba(16, 185, 129, 0.05) !important;
transform: scale(1.01);
}/* Dark Mode */
.dark body {
background-color: var(–bg-dark);
color: #F9FAFB;
}
.dark .card {
background-color: #064E3B;
border-color: #065F46;
}
.dark input {
background-color: #065F46;
color: white;
border-color: #047857;
}
/* — CSS SEPARATION END — */
tailwind.config = {
darkMode: ‘class’,
theme: {
extend: {
colors: {
primary: ‘#10B981’,
}
}
}
}
Secure your PDF documents with 128-bit AES encryption. Add passwords directly in your browser without uploading files.
Drop PDF to Protect Encrypt your document instantly
Select File
document.pdf Set a password to encrypt this file
Advanced Options (Permissions)
Owner Password (Optional)
Allow Printing
Allow Copying Text
Allow Modifying
Encrypt PDF
Password cannot be empty
Cancel
File Secured! Your PDF is now password protected.
// — JAVASCRIPT SEPARATION START —// DOM Elements
const dropzone = document.getElementById(‘upload-stage’);
const fileInput = document.getElementById(‘fileInput’);
const passwordStage = document.getElementById(‘password-stage’);
const successStage = document.getElementById(‘success-stage’);
const filenameDisplay = document.getElementById(‘filename-display’);
const userPassInput = document.getElementById(‘user-password’);
const ownerPassInput = document.getElementById(‘owner-password’);
const btnLock = document.getElementById(‘btn-lock’);
const btnText = document.getElementById(‘btn-text’);
const btnLoader = document.getElementById(‘btn-loader’);
const errorMsg = document.getElementById(‘error-msg’);
const downloadBtn = document.getElementById(‘download-btn’);
const advancedOptions = document.getElementById(‘advanced-options’);let currentFile = null;
let isDarkMode = false;// — Event Listeners —
dropzone.addEventListener(‘click’, () => fileInput.click());
dropzone.addEventListener(‘dragover’, (e) => {
e.preventDefault();
dropzone.classList.add(‘dropzone-active’);
});
dropzone.addEventListener(‘dragleave’, () => {
dropzone.classList.remove(‘dropzone-active’);
});
dropzone.addEventListener(‘drop’, (e) => {
e.preventDefault();
dropzone.classList.remove(‘dropzone-active’);
if (e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
});fileInput.addEventListener(‘change’, (e) => {
if (e.target.files.length) handleFile(e.target.files[0]);
});userPassInput.addEventListener(‘keypress’, (e) => {
if (e.key === ‘Enter’) lockPDF();
});// — Functions —function handleFile(file) {
if (file.type !== ‘application/pdf’) {
alert(‘Please upload a valid PDF file.’);
return;
}currentFile = file;
filenameDisplay.innerText = file.name;
dropzone.classList.add(‘hidden’);
passwordStage.classList.remove(‘hidden’);
userPassInput.focus();
}async function lockPDF() {
const userPass = userPassInput.value;
const ownerPass = ownerPassInput.value || userPass; // Default owner pass to user pass if empty
if (!userPass) {
errorMsg.classList.remove(‘hidden’);
return;
}btnLock.disabled = true;
btnText.innerText = ‘Encrypting…’;
btnLoader.classList.remove(‘hidden’);
errorMsg.classList.add(‘hidden’);try {
const arrayBuffer = await currentFile.arrayBuffer();
// Load PDF
const pdfDoc = await PDFLib.PDFDocument.load(arrayBuffer);
// Encrypt
// Note: Standard encryption uses 128-bit AES or RC4 depending on library version
// pdf-lib supports standard encryption via encrypt()
const permissions = {
printing: document.getElementById(‘perm-print’).checked ? ‘highResolution’ : undefined,
modifying: document.getElementById(‘perm-mod’).checked,
copying: document.getElementById(‘perm-copy’).checked,
annotating: document.getElementById(‘perm-mod’).checked,
fillingForms: document.getElementById(‘perm-mod’).checked,
contentAccessibility: true,
documentAssembly: document.getElementById(‘perm-mod’).checked,
};pdfDoc.encrypt({
userPassword: userPass,
ownerPassword: ownerPass,
permissions: permissions,
});
// Save
const pdfBytes = await pdfDoc.save();
prepareDownload(pdfBytes, currentFile.name);
// Show Success
passwordStage.classList.add(‘hidden’);
successStage.classList.remove(‘hidden’);} catch (error) {
console.error(error);
alert(‘Error encrypting PDF. File may be corrupted or already encrypted.’);
// Reset button
btnLock.disabled = false;
btnText.innerText = ‘Encrypt PDF’;
btnLoader.classList.add(‘hidden’);
}
}function prepareDownload(bytes, originalName) {
const blob = new Blob([bytes], { type: ‘application/pdf’ });
const url = URL.createObjectURL(blob);
downloadBtn.href = url;
downloadBtn.download = ‘protected_’ + originalName;
}function togglePassword(id) {
const input = document.getElementById(id);
const btn = input.nextElementSibling.querySelector(‘i’);
if (input.type === “password”) {
input.type = “text”;
btn.classList.remove(“fa-eye”);
btn.classList.add(“fa-eye-slash”);
} else {
input.type = “password”;
btn.classList.remove(“fa-eye-slash”);
btn.classList.add(“fa-eye”);
}
}function toggleAdvanced() {
advancedOptions.classList.toggle(‘hidden’);
}function resetApp() {
currentFile = null;
fileInput.value = ”;
userPassInput.value = ”;
ownerPassInput.value = ”;
dropzone.classList.remove(‘hidden’);
passwordStage.classList.add(‘hidden’);
successStage.classList.add(‘hidden’);
btnLock.disabled = false;
btnText.innerText = ‘Encrypt PDF’;
btnLoader.classList.add(‘hidden’);
errorMsg.classList.add(‘hidden’);
advancedOptions.classList.add(‘hidden’);
}function toggleDarkMode() {
isDarkMode = !isDarkMode;
document.documentElement.classList.toggle(‘dark’);
const icon = document.getElementById(‘theme-icon’);
if(isDarkMode) {
icon.classList.remove(‘fa-moon’);
icon.classList.add(‘fa-sun’);
} else {
icon.classList.remove(‘fa-sun’);
icon.classList.add(‘fa-moon’);
}
}// — JAVASCRIPT SEPARATION END —
Using Lock PDF The Lock PDF utility is designed for PDF document tasks. Check the on-page controls for available formats, limits and options. Always review the output for accuracy before sharing or publishing it.
Practical tips Keep your original files or source information as a backup. Choose suitable options using the controls provided by this tool. Check the generated result and retry with different settings if needed. Explore related tools Related PDF tools: Unlock PDF and Merge PDF . Review your output before sharing.