0

Let's say I have the following where k is any length string

If I do the following

var p = aes256.decrypt(k, 'XXXXXXXXXXXXXXXXXXXXX');

The value of p will always equal nothing. Can this please be explained in really simple terms?

XXXXXXXXXXXXXXXXXXXXX being any 22 character string if I do the following where p is any 5 byte string.

var c = aes256.encrypt(k, p);

Here's some code in Node

var aes256 = require('aes256');
var k = 'THIS IS MY ONE AND ONLY KEY'; // A KEY
var p = 'ABCDE'; // 5 CHARACTER STRING
var e = aes256.encrypt(k, p);
console.log (e);
var decrypted_1 = aes256.decrypt(k, e);
console.log (decrypted_1)
var decrypted_2 = aes256.decrypt(k, 'AAAAAAAAAAAAAAAAAAAAAA');
console.log (decrypted_2)

The value of decrypted_2 is blank - I don't understand why

0

1 Answer 1

1

My guess ist that you are referring to this JS library. While the incomplete documentation suggests that it does AES-256 with the given key and cipher text a look at the code suggests that it does something else: The key is not the AES key but the AES key will be derived from it using SHA256. And the input is not the cipher text but will be treated as Base64. It will also use the first 16 byte of the decoded input as IV and then decrypt the next 16 byte. This means to cover at least 1 byte of plain text your input need to be an 17 byte binary (16 bytes IV + 1 byte data). This 17 bytes binary results in a 23 byte long base64 encoded string and any input shorter than that will just not contain any data to decrypt.

2
  • So if the next 16 bytes are empty, does this mean the result will be blank? This is the bit I am struggling with
    – pee2pee
    Commented Dec 27, 2017 at 10:18
  • 1
    @pee2pee: if the input is too short it will just fail to decrypt the data and return nothing. Commented Dec 27, 2017 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .