Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const fs = require('fs');
- const crypto = require('crypto');
- const licensePath = path.resolve('z32_k2.lic');
- const SYM_KEY_PREFIX = Buffer.from('SYMKEY').toString('base64');
- try {
- const licenseFileInput = fs.readFileSync(licensePath, 'utf-8');
- const publicKey = readPublicKey(licenseFileInput);
- console.log(publicKey);
- const licenseData = readLicenseData(licenseFileInput, publicKey);
- console.log(licenseData);
- } catch(err) {
- console.log(err);
- }
- function readPublicKey(licenseFileInput) {
- const lines = licenseFileInput.split('\n');
- const indexKeyEnd = lines.indexOf('-----END PUBLIC KEY-----');
- var key = '';
- for (var i = 0; i <= indexKeyEnd; i++) {
- key += lines[i];
- key += i < indexKeyEnd ? '\n' : '';
- }
- return key;
- }
- function readLicenseData(licenseFileInput, publicKey) {
- const lines = licenseFileInput.split('\n');
- for (var i = 0; i < lines.length; i++) {
- if (lines[i].startsWith(SYM_KEY_PREFIX)) {
- const b64SymKey = lines[i];
- const b64LicenseData = lines[i + 1];
- const encSymKey = Buffer.from(b64SymKey.substring(SYM_KEY_PREFIX.length), 'base64');
- const symKey = Buffer.from(crypto.publicDecrypt(publicKey, encSymKey), 'base64');
- console.log(symKey);
- const encLicenseData = Buffer.from(b64LicenseData, 'base64');
- const decipher = crypto.createDecipher('aes-256-cbc', symKey);
- var licenseData = Buffer.concat([decipher.update(encLicenseData), decipher.final()]);
- licenseData = Buffer.from(licenseData, 'base64').toString('utf-8');
- console.log(licenseData);
- return;
- }
- else if (i + 1 === lines.length) {
- var b64LicenseData = lines[i];
- var encLicenseData = Buffer.from(b64LicenseData, 'base64');
- var licenseData = crypto.publicDecrypt(publicKey, encLicenseData);
- return Buffer.from(licenseData, 'base64').toString('utf-8');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement