import crypto from "node:crypto";
import { Aes } from "https://deno.land/x/crypto/aes.ts";
import { Ctr } from "https://deno.land/x/crypto/block-modes.ts";
// ...
class Builder {
// ...
protected EncodeFile(
FileSource: string,
FileTarget: string,
UsedKey?: Uint8Array,
UsedIVKey?: Uint8Array,
): { Key: string; Iv: string } {
const Key = UsedKey ?? new Uint8Array(16),
IVKey = UsedIVKey ?? new Uint8Array(16);
const Encoder = new TextEncoder();
const FileContent = Encoder.encode(fs.readFileSync(FileSource, "utf-8"));
// Create an AES-128-CTR cipher
const Cipher = new Ctr(Aes, Key, IVKey);
// Encrypt the data
const EncryptedData = Cipher.encrypt(FileContent);
WriteFile(FileTarget, EncryptedData, "utf-8");
return { Key: this.UInt8ArrayToHex(Key), Iv: this.UInt8ArrayToHex(IVKey) };
}
}
import crypto from "node:crypto";
import { Aes } from "https://deno.land/x/crypto/aes.ts";
import { Ctr } from "https://deno.land/x/crypto/block-modes.ts";
// ...
class Builder {
// ...
protected EncodeFile(
FileSource: string,
FileTarget: string,
UsedKey?: Uint8Array,
UsedIVKey?: Uint8Array,
): { Key: string; Iv: string } {
const Key = UsedKey ?? new Uint8Array(16),
IVKey = UsedIVKey ?? new Uint8Array(16);
const Encoder = new TextEncoder();
const FileContent = Encoder.encode(fs.readFileSync(FileSource, "utf-8"));
// Create an AES-128-CTR cipher
const Cipher = new Ctr(Aes, Key, IVKey);
// Encrypt the data
const EncryptedData = Cipher.encrypt(FileContent);
WriteFile(FileTarget, EncryptedData, "utf-8");
return { Key: this.UInt8ArrayToHex(Key), Iv: this.UInt8ArrayToHex(IVKey) };
}
}