stencyption
Version:
Military-grade JavaScript encryption with AES-256-GCM, polymorphic obfuscation, and anti-debugging protection. Each file gets unique encryption keys embedded in heavily obfuscated code.
92 lines (76 loc) • 3.84 kB
JavaScript
const fs = require('fs');
const path = require('path');
const { Encryptor } = require('./src/encryptor.js');
const { Decryptor } = require('./src/decryptor.js');
console.log('\n╔═══════════════════════════════════════════════════════════╗');
console.log('║ STENCYPTION v2.0.0 - Demo & Test Suite ║');
console.log('╚═══════════════════════════════════════════════════════════╝\n');
const testCode = `
// Sample JavaScript code for testing
const greeting = "Hello, Stencyption!";
const numbers = [1, 2, 3, 4, 5];
function calculateSum(arr) {
return arr.reduce((sum, num) => sum + num, 0);
}
console.log(greeting);
console.log("Sum of numbers:", calculateSum(numbers));
module.exports = { greeting, calculateSum };
`;
const testDir = path.join(__dirname, 'test-files');
if (!fs.existsSync(testDir)) {
fs.mkdirSync(testDir);
}
console.log('📝 Step 1: Creating test file...');
const testFile = path.join(testDir, 'sample.js');
fs.writeFileSync(testFile, testCode, 'utf8');
console.log(' ✅ Created: test-files/sample.js\n');
console.log('🔒 Step 2: Testing encryption...');
const encrypted = Encryptor.encrypt(testCode);
const encryptedFile = path.join(testDir, 'sample.encrypted.js');
fs.writeFileSync(encryptedFile, encrypted, 'utf8');
console.log(' ✅ Encrypted: test-files/sample.encrypted.js');
console.log(` 📊 Original: ${testCode.length} bytes`);
console.log(` 📊 Encrypted: ${encrypted.length} bytes\n`);
console.log('🔓 Step 3: Testing decryption with correct admin key...');
try {
const decrypted = Decryptor.decrypt(encrypted, 'tormairechudi');
const decryptedFile = path.join(testDir, 'sample.decrypted.js');
fs.writeFileSync(decryptedFile, decrypted, 'utf8');
console.log(' ✅ Decrypted: test-files/sample.decrypted.js');
console.log(` 📊 Decrypted: ${decrypted.length} bytes`);
console.log(' ✅ Decryption successful!\n');
} catch (error) {
console.log(' ❌ Decryption failed:', error.message, '\n');
}
console.log('🔐 Step 4: Testing decryption with wrong admin key...');
try {
const decrypted = Decryptor.decrypt(encrypted, 'wrongkey');
console.log(' ❌ Security breach! Wrong key should not work.\n');
} catch (error) {
console.log(' ✅ Access denied (as expected)');
console.log(' 🛡️ Security working correctly!\n');
}
console.log('▶️ Step 5: Testing encrypted file execution...');
try {
// Load stencyption runtime to enable encrypted file execution
require('./src/index.js');
delete require.cache[path.resolve(encryptedFile)];
const result = require(encryptedFile);
console.log(' ✅ Encrypted file executed successfully!');
if (result && typeof result === 'object') {
console.log(' 📊 Exported:', Object.keys(result).join(', '));
}
console.log('\n');
} catch (error) {
console.log(' ⚠️ Execution error:', error.message, '\n');
}
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
console.log('✅ All Tests Completed!\n');
console.log('📂 Test files created in: test-files/');
console.log(' - sample.js (original)');
console.log(' - sample.encrypted.js (encrypted)');
console.log(' - sample.decrypted.js (decrypted)\n');
console.log('🚀 Try the CLI commands:');
console.log(' Encrypt: stencyption encrypt test-files/sample.js');
console.log(' Decrypt: stencyption decrypt test-files/sample.encrypted.js --key tormairechudi\n');
console.log('📖 For more info: See HOW_TO_USE.md\n');