I know this topic have a couple answer, but I have problem about details key length.
I would like to encryption data in AES algorithm with CTR. The encryption will have length of 256 bits.
If I do encryption data by key length 256 and IV length 16, I get a error Invalid key length. I thought IV must be the same key length. I change length of IV to 256, but I get an error Invalid iv length. I found out IV must be 16 bits long.
My code works only if my key is 16 bits and my IV is 16 bits long. So my code didn't encrypt with length of 256 bits.
My code
const crypto = require('crypto');
let key = crypto.randomBytes(16).toString('hex'); // Key is static
let iv = crypto.randomBytes(16);
let cipher = crypto.createCipheriv('aes-256-ctr', process.env.KEY, iv);
let encrypte = cipher.update("Example_data", 'utf-8', 'hex');
encrypte += cipher.final('hex');
What should I do to encrypt data with a key length of 256 bits?