0

I need to AES encrypt fileupload images with javascript before storing to the server but I'm running into LONGTEXT limitations when trying to store as custom field in MySQL. That method involved converting image to base64 and then encrypting.

I'm looking for a method to achieve the smallest string possible from that image upload before encrypting. Or at the very least how to reduce the image under a specified byte maximum.

<input id="foo" type="file" />

Encrypt with CryptoJS

$(document).on("change", "#foo", function() {
    var chatImg = $(this).val();

    // COMPRESS IMAGE

    var keyAES = "123456789";
    var eImg = CryptoJS.AES.encrypt(chatImg, keyAES).toString();
    console.log(eImg);
});

Note: I've searched far and wide for a solution but the only ones I found involved set image widths/heights

user300979
  • 389
  • 1
  • 4
  • 18
  • If you can't compromise on width/height, you'll need to compromise on encoding quality. – samgak Mar 26 '19 at 07:29
  • I'm open to resizing the image under a byte maximum before encryption although I have no idea how. What do you mean exactly by encoding quality? – user300979 Mar 26 '19 at 07:49
  • JPEG is a lossy image format. How lossy depends on the encoding parameters. When you encode an image you can specify a value that determines how aggressively to compress the data. See here: https://stackoverflow.com/questions/14383557/setting-canvas-todataurl-jpg-quality – samgak Mar 26 '19 at 07:53

0 Answers0