// // The key length is dependent on the algorithm.
// // In this case for aes256, it is 32 bytes.
const textToEncrypt = '1008';
const iv = randomBytes(16);
const password = 'Password used to generate key';
// The key length is dependent on the algorithm.
// In this case for aes256, it is 32 bytes.
const key = (await promisify(scrypt)(password, 'salt', 32)) as Buffer;
const cipher = createCipheriv('aes-256-ctr', key, iv);
const encryptedText = Buffer.concat([
cipher.update(textToEncrypt),
cipher.final(),
]);
console.log(encryptedText);
const finalEncryptedText = encryptedText.toString('hex');
// return finalEncryptedText;
const encryptedText2 = Buffer.from(finalEncryptedText, 'hex');
const decipher = createDecipheriv('aes-256-ctr', key, iv);
const decryptedText = Buffer.concat([
decipher.update(encryptedText2),
decipher.final(),
]);
return decryptedText.toString();