You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@guacamole.apache.org by Caleb Coverdale <ca...@me.com.INVALID> on 2022/01/26 21:00:16 UTC

Encrypted JSON with Javascript

Hey there! 

I have been banging my head against the wall trying to get the EncryptedJSON script working in Javascript. 

I was wondering if anyone has been down the rabbit hole and got it working? 


Any help would be appreciated… 


Here’s what I have so far: 



const crypto = require("crypto");
const guacjson = `{"username":"MyUser","connections":{"MyConnection":{"protocol":"rdp","parameters":{"hostname":"10.0.0.41","port":"3389","security":"nla","ignore-cert":"true"}}}}`;
const secretkey = "fe57526d73a1e5116bbbefad1c91b38f";

// sign the contents of guacjson with secret key using HMAC/SHA-256 out in binary
function cryptedmessage() {
  const hmac = crypto.createHmac("sha256", secretkey);
  hmac.update(guacjson);
  // output the hmac in binary followed by guacjson
  signature = hmac.digest("binary") + guacjson;
  return signature;
}

const INITIALIZATION_VECTOR = "0000000000000000";

class Crypt {
  static encrypt128(data, key) {
    const cipher = crypto.createCipheriv(
      "aes-128-cbc",
      Buffer.from(key, "hex"),
      Buffer.from(INITIALIZATION_VECTOR)
    );
    // return cipher encoded as bas64
    console.log(data);
    const encrypted =
      cipher.update(data, "utf8", "base64") + cipher.final("base64");
    return encrypted;
  }
}

const key = "fe57526d73a1e5116bbbefad1c91b38f";

const cipher = Crypt.encrypt128(cryptedmessage(), key);

console.log(cipher);