Hello,
I have an application where I generate a URL with token in C# and encode it using H t t pUtility .UrlEncode(token); Now I would like to include email id as well in the URL.
I wish to encrypt email id and send it as part of URL. Then when my react app reads the URL param (useParams();) I would like to decrypt it so that react will have the actual email id.
Any suggestions on how I can do the same?
Thanks.
Tahir AnsariPosted Jul 30, 2023, 6:49 AM
Hi Dave bell Please try the below sample
Encrypting Data in C#
Decrypting Data in React:
npm install crypto-js
Below is a React js code
According to your need adjust the code
Cr BhargaviPosted Jul 29, 2023, 5:00 PM
you can use a symmetric encryption algorithm. Symmetric encryption uses a single secret key to both encrypt and decrypt data. This way, you can encrypt the email ID in C# before generating the URL and then decrypt it in your React app after reading the URL parameter.A gist of the process on how you can implement in C# and React In C#, Use a symmetric encryption algorithm, such as AES (Advanced Encryption Standard), to encrypt the email ID along with the token. and then generate the URL with the encrypted email ID and the token. Use
HttpUtility.UrlEncodeto encode the complete URL (including the encrypted data) before sending it to the React app.In the React App:
useParams()or any URL parsing library to retrieve the URL parameter containing the encrypted data.decodeURIComponent()to get the encrypted data.Hope this solves your question.