# Static ciphertext length for any plaintext length less or equal than x?

I am encrypting buffers using AES-256-CTR encryption. My encryption is working but I have a requirement that I want to make sure I implement correctly. The requirement is as follows:

Given any plaintext of length less that x, the ciphertext should always be of length x.

In my example

• x is 1 KB but can be anything while consistent.
• The plaintext could range between 1 byte to 1 KB, never larger.
• The length of the plaintext is not know by decryptor.
• This is tricky (possibly impossible) to implement if an exactly 1kB message must encrypt to an exactly 1kB output. What behavior is expected for blocks that are close to the limit, and what should happen for blocks larger than the limit? (Should a 1.5kB block be 2kB or ~1.5kB?) I'm assuming that the decryptor will not have access to the actual length by any other means than reading the ciphertext. – Rob Napier May 12 '18 at 17:23
• @RobNapier The x does not need to be limited by exactly 1KB and can be any size while its consistent. Blocks larger than x will not be candidates, for shorter plaintext is the question. Decryptor will not have access to the actual length than the ciphertext. Thank you for the questions, I will update the question. – Thor May 12 '18 at 17:56
• @MaartenBodewes, I might have misunderstood your point earlier and you are probably right, I am looking for the approach, not a block of code to copy-paste. Would you mind posting your approach with nodejs implementation in mind? No need to be runnable code – Thor May 12 '18 at 18:40
• @MaartenBodewes, thank you for the link, I would not identify it as a duplicate since I would never have been able to find this answer the way I was looking for it. I will use the message length in the beginning of the buffer approach. – Thor May 12 '18 at 22:49
• Ok removed some more outdated comments. I'm fine with the question and answer here mods... – Maarten Bodewes May 12 '18 at 22:53