2

I am encrypting a user id using crypto-js to send it via url like the following for the user to validate it on click:

http://localhost:3000/api/customer/activate/U2FsdGVkX1DXzzLuf9TgBf31Mc2V/QBVAN05PovlNM

This is the encrypted user id:

U2FsdGVkX1DXzzLuf9TgBf31Mc2V/QBVAN05PovlNM

Using crypto-js encrypt:

crypto.AES.encrypt(term.toString(), config.CRYPTO_PASSPHRASE_RES).toString(crypto.enc.Utf8)

When I run the API, it return route not found, and when I remove / from the encrypted user id, it worked.

How can I prevent crypto-js from adding / into encrypted IDs?

alim1990
  • 4,656
  • 12
  • 67
  • 130
  • Does this answer your question? [Passing base64 encoded strings in URL](https://stackoverflow.com/questions/1374753/passing-base64-encoded-strings-in-url) – Topaco Jul 18 '20 at 12:01
  • You could also replace special characters: https://stackoverflow.com/questions/43399093/encrypt-cryptojs-without-special-characters – tpschmidt Jul 18 '20 at 12:07
  • better pass that id as a query string – Nithin K Joy Jul 18 '20 at 15:02

1 Answers1

6

The solution was to use encodeURIComponent() and then decodeURIComponent() like the following:

encodeURIComponent(crypto.AES.encrypt(term.toString(), config.CRYPTO_PASSPHRASE_RES).toString());

It will replace / into something else.

alim1990
  • 4,656
  • 12
  • 67
  • 130