easy-cipher-mate
Version:
A CLI and programmatic tool for encryption/decryption supporting AES-GCM and ChaCha20-Poly1305 algorithms, with text encoding options and line-by-line text file processing.
27 lines (26 loc) • 978 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deriveStringToBuffer = deriveStringToBuffer;
exports.deriveStringToUint8Array = deriveStringToUint8Array;
const crypto_1 = require("crypto");
function deriveStringToBuffer(ss, targetLength) {
if (!ss) {
return Buffer.alloc(targetLength);
}
let base64Buffer = null;
try {
base64Buffer = Buffer.from(ss, 'base64');
}
catch { }
if ((base64Buffer === null || base64Buffer === void 0 ? void 0 : base64Buffer.length) === targetLength) {
return base64Buffer;
}
const inputBuffer = Buffer.from(ss, 'utf8');
const hash = (0, crypto_1.createHash)('sha256').update(inputBuffer).digest();
const outputBuffer = Buffer.alloc(targetLength);
hash.copy(outputBuffer, 0, 0, targetLength);
return outputBuffer;
}
function deriveStringToUint8Array(ss, targetLength) {
return new Uint8Array(deriveStringToBuffer(ss, targetLength));
}