Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

545
Views
how to encrypt and decrypt string in vue 3

My id is stored in sessionStorage and I want to encrypt my id. how can I encrypt in Vue 3 and best way to secure my id?

sessionStorage.setItem('id', error.response.data.user.id)

this is my id and I want this to store in sessionStorage in encryption and then get decrypted id.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use cryptoJS to achieve the encryption and decryption.

Demo :

var id = document.getElementById("userId"),
    save = document.getElementById("save"),
    read = document.getElementById("read");
 
// Manage Save event
save.addEventListener("click", function(e){
    window.sessionStorage["userId"] = CryptoJS.AES.encrypt(id.value, 'secret key');
}, true);

// Manage Read Event
read.addEventListener("click", function(e) {
        let decryptedId = CryptoJS.AES.decrypt(window.sessionStorage["userId"].toString(), 'secret key');
    document.getElementById('showId').innerHTML = decryptedId.toString(CryptoJS.enc.Utf8);
}, true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>

<input type="text" id="userId" />
<input type="button" value="Save" id="save" />
<input type="button" value="Read" id="read" />

<p id="showId"></p>

Due to code snippet limitations its not able to accessing window object but you can take the reference.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!