gh-legacy
Version:
A powerful GitHub CLI tool for automatic repository ownership transfer to trusted beneficiaries after periods of inactivity
41 lines (34 loc) • 1.16 kB
JavaScript
// encryptToken.js
const fs = require('fs');
const crypto = require('crypto');
const os = require('os');
const path = require('path');
const configDir = path.join(os.homedir(), '.gh-legacy');
const tokenPath = path.join(configDir, '.gh_token');
function encryptToken(token) {
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}
const key = crypto.createHash('sha256').update('gh-legacy-secret-key').digest();
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let encrypted = cipher.update(token, 'utf8', 'hex');
encrypted += cipher.final('hex');
fs.writeFileSync(tokenPath, JSON.stringify({
encrypted,
iv: iv.toString('hex')
}));
console.log(`🔐 GitHub token encrypted and saved to ${tokenPath}`);
}
module.exports = encryptToken;
if (require.main === module) {
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter your GitHub token: ', (token) => {
encryptToken(token);
rl.close();
});
}