14 lines
470 B
JavaScript
14 lines
470 B
JavaScript
// server/keygen.js
|
|
const crypto = require('crypto');
|
|
const { encrypt } = require('./utils/crypto');
|
|
|
|
const generateLicenseKey = (userId) => {
|
|
const rawKey = crypto.randomBytes(32).toString('hex');
|
|
const payload = { userId, rawKey, issued: Date.now() };
|
|
const encryptedKey = encrypt(payload);
|
|
return encryptedKey;
|
|
};
|
|
|
|
const hashLicenseKey = (key) => crypto.createHash('sha256').update(key).digest('hex');
|
|
|
|
module.exports = { generateLicenseKey, hashLicenseKey }; |