Announcement

Collapse
No announcement yet.

AES encryption issues

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AES encryption issues

    Encrypt Key: A4 49 43 0E 74 61 6F 95 13 6A DF 60 73 D6 EE 28

    Decrypt Key: FF 09 04 46 F6 EA EB C5 D5 28 B2 60 40 67 0C A1

    I entered the keys above with spaces into the lantronix web config.

    What I would like to achieve is, to send encrypted text to a nodejs TCP server and decrypt the encrypted text on the nodejs TCP server side. However I am having issues with the length of the encrypted text. The length of the incoming encrypted json string is never consistent. Therefor causing the nodejs error explained below.

    Nodejs outputs this error:
    TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
    at Decipher.Cipher.final (crypto.js:292:27)
    My tcp server nodejs code is:
    socket.on('data', function (data) {
    // AES Key storage
    var key = new Buffer('A449430E74616F95136ADF6073D6EE28', 'hex');

    var t = data.toString();
    var e = encrypt(key, data);
    var d = decrypt(key, t);

    console.log("Text: "+t+"\n");
    console.log("Encrypted Length: "+e.length+"\n");


    //broadcast(socket.name + "> " + decrypted, socket);
    });

    To debug this issue I send the incoming encrypted string to the nodejs console which, for example, is: ?_?c???8?~??Hf-?uO?l?? \P=?▲%^?x?B▼?k?M???/c???;??
    The encrypted string stated above doesn't "look" correct.

    To troubleshoot this issue further I decided to shut off the xPico Wi-Fi encryption feature and encrypt/decrypt the sting at the nodejs tcp server side.

    For an example, the plain text string that is sent to the TCP server is:
    <{"resTemp":"87.25","roomTemp":98,"ph":58,"ec":700 }>
    The length of string sent is always 52 characters.

    When I encrypt the incoming unencrypted string inside of the nodejs tcp server I have nodejs output the encrypted string which is, for example: 0023335ffa2a0511ec6c8936c385144a3ae00d0e84dae641be c777f269b071814a193dafb965f1e1c0d7746bb65074bcb607 365702c96abd73413e840c49a37d
    the above encrypted string "looks" correct.
    When encrypting the incoming string Inside nodejs tcp server I always get a character length of 128. I then decrypt the encrypted string inside of the nodejs tcp server with success.

    encrypting/decrypting the string inside nodejs tcp server code successfully tells me that the Encrypted hexadecimal key should be correct. So, I'm not sure why when the wifi module encrypts the data first then sends the encrypted data the tcp server I get strange characters, for example,
    ?_?c???8?~??Hf-?uO?l?? \P=?▲%^?x?B▼?k?M???/c???;??
    Should, for example, 0023335ffa2a0511ec6c8936c385144a3ae00d0e84dae641be c777f269b071814a193dafb965f1e1c0d7746bb65074bcb607 365702c96abd73413e840c49a37d
    be more of a correct encrypted characters?

  • #2
    I'm not very well versed in node.js, but at first glance it looks like the data.toString() is converting the stream coming from the xPico Wi-Fi into the ASCII characters represented, instead of displaying the hex values.

    I ran the same test as you (but sent to a Python server instead of node.js). On the Python side, I get the "strange" characters (because it's making hex-to-ascii conversion in the print statement).

    But if I look in Wireshark, the actual data coming across the "wire" is the hex values like you're expecting.

    Comment

    Working...
    X