How to encrypt/decrypt URL parameters in javascript?

后端 未结 2 1301
广开言路
广开言路 2020-12-29 08:51

Before anyone jumps in and says, \"Oh!! that\'s a bad idea\", I know it is.

I want to keep both the key and value in the query string to be not easily visible to the

相关标签:
2条回答
  • 2020-12-29 09:19

    If you don't looking for serious strong crypto, you can use ROT13:

    http://en.wikipedia.org/wiki/ROT13

    This is enough for slightly obfuscate keys/values in the your URLs.

    0 讨论(0)
  • 2020-12-29 09:37

    You can use base64. Javascript has native functions to do that :

    alert(btoa("category=textile&user=user1")); // ==> Y2F0ZWdvcnk9dGV4dGlsZSZ1c2VyPXVzZXIx
    

    and to reverse it :

    alert(atob("Y2F0ZWdvcnk9dGV4dGlsZSZ1c2VyPXVzZXIx")); // ==> category=textile&user=user1
    

    Be careful to read the doc if you have unicode strings, it's a little different : https://developer.mozilla.org/en-US/docs/Web/API/Window.btoa

    0 讨论(0)
提交回复
热议问题