-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.ts
More file actions
26 lines (19 loc) · 757 Bytes
/
encrypt.ts
File metadata and controls
26 lines (19 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { armor, Encrypter } from "age-encryption";
const passphrase =
prompt("Enter passphrase for encryption:") || Bun.env.PASSPHRASE;
const outputFile = Bun.env.OUTPUT_FILE || "public/data/data.age";
if (!passphrase) {
throw new Error("Passphrase is required for encryption.");
}
const plaintext = await Bun.file("data.json")
.json()
// Minify JSON by removing whitespace
.then((data) => JSON.stringify(data));
const encrypter = new Encrypter();
encrypter.setPassphrase(passphrase);
const ciphertext = await encrypter.encrypt(plaintext);
const armored = armor.encode(ciphertext);
console.log("Encrypted text:");
console.log(armored);
await Bun.write(outputFile, armored);
console.log(`Encrypted data written to ${outputFile}`);