Inscribing SNES ROMs
How to Encrypt ROM Files with a Password and Inscribe Them on Bitcoin
Encrypting ROM Files with a Password
const crypto = require('crypto');
const fs = require("fs");
function encrypt(key, plaintext) {
const nonce = getRandomIV();
const cipher = crypto.createCipheriv('aes-256-gcm', key, nonce);
const nonceCiphertextTag = Buffer.concat([
nonce,
cipher.update(plaintext),
cipher.final(),
cipher.getAuthTag()
]);
return nonceCiphertextTag;
}
function getRandomIV() { return crypto.randomBytes(12); }
function encryptRom(name, password) {
fs.readFile(name, function (err, data) {
if (err) throw err;
const hex = crypto.createHash('sha256').update(password).digest('hex').slice(0, 32);
const key = Buffer.from(hex);
const cipher = encrypt(key, data);
try {
fs.writeFileSync(`./encrypted-${name}`, cipher);
} catch (err) {
console.error(err);
}
});
}
encryptRom('ROM.sfc', 'mypassword');Inscribing Your ROM
Last updated