0

Is there any possibility to secure data only using JavaScript?

User has a token sent between browser and API. This is ok, but I send also additional data without token (I don't want to generate token each time). This happens automatically using JavaScript. Unfortunately the user can get token and change data from outside the token (I send token + data that is different for each request, so the user can change the different data) and next send request by for example PostMan.

If it was on the server side, I could generate a hash with this data and salt, but if I do it in JavaScript itself, everyone can see how hash is generated and what is the salt.

wiwec
  • 1

1 Answers1

0

check this out

Ref1: [https://stackoverflow.com/a/7616484/3217659][1]

Ref2: [https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/][2]

    String.prototype.hashCode = function() {
      var hash = 0, i, chr;
      if (this.length === 0) return hash;
      for (i = 0; i < this.length; i++) {
        chr   = this.charCodeAt(i);
        hash  = ((hash << 5) - hash) + chr;
        hash |= 0; // Convert to 32bit integer
      }
      return hash;
    };


  [1]: https://stackoverflow.com/a/7616484/3217659
  [2]: https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
Fadi
  • 267
  • 2
  • 6