0

enter image description here

Hello, In terms of this picture, you can see my js code is easy to read for any user, and my important key and logic are naked.

1.Is it possible to hide or encrypt my code to prevent someone from reading my code maliciously? 2.What's the right way to store a public key or symmetric-key in the front-end? Is it correct to write it like this picture?

By the way, this testing project is written by Blazor WebAssembly.

BlueCake
  • 47
  • 4

1 Answers1

3

What you're looking for is code mangling/minification with a library such as uglify-js https://www.npmjs.com/package/uglify-js. This is not a replacement for security though, your JS should not contain sensitive data, that should be handled by a backend.

The short answer to your question is there is no way to obfuscate a key this way. If your frontend can decrypt that key to use it then a user can too.

Alex
  • 848
  • 6
  • 7