Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users

    Crypto for secured requests

    Developers
    3
    5
    294
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • beachb_sl
      beachb_sl last edited by

      Hi, I'm trying to automate some smart devices I own (through the Tuya Cloud interface) but I need to encrypt the POST request before I can get a token to work with the API.

      Anyone knows if it's even possible to use crypt properly?
      Ideally, this should be based on TypeScript which I dont think the hub supports (?)
      For vanilla Javascript I need to create an SHA256 based string and it breaks on the following -
      crypto.subtle.digest('SHA-256', msgBuffer);

      msgBuffer is just an encoded string which seems to be working -
      var msgBuffer = new TextEncoder().encode(message);

      I think crypto is not supported as it's a heavy operation?

      Emil 1 Reply Last reply Reply Quote 0
      • beachb_sl
        beachb_sl @oskar last edited by

        @oskar That's great thank you! I just managed to separate the logic to different files so it's shaping up well. Thanks for the help

        1 Reply Last reply Reply Quote 0
        • oskar
          oskar FlicTeam @beachb_sl last edited by

          @beachb_sl

          Hi! You can find an implementation of SHA-256 here:

          https://geraintluff.github.io/sha256/

          beachb_sl 1 Reply Last reply Reply Quote 0
          • beachb_sl
            beachb_sl @Emil last edited by

            @Emil Thanks for the reply, the code lines I added in my post are what I found for vanilla implementation of cryptography, but it fails

            oskar 1 Reply Last reply Reply Quote 0
            • Emil
              Emil FlicTeam @beachb_sl last edited by

              @beachb_sl Cryptographic functions are not part of the javascript language itself, but typically included in browser APIs or e.g. Node.js environments.

              To use SHA-256 encryption with the Hub SDK, use a pure javascript implementation. You should be able to find that with a simple online search.

              If you want to run TypeScript, my suggestion is to transpile it to javascript first.

              beachb_sl 1 Reply Last reply Reply Quote 0
              • First post
                Last post