I am trying to pass encrypted data via a browser/client session variable - not to be confused with server-side session variable:
encrypt:
var encrypted_user_id = CryptoJS.AES.encrypt(user_id, cipher_pass);
var encrypted_user_password = CryptoJS.AES.encrypt(password, cipher_pass);
sessionStorage.setItem('user_id', encrypted_user_id);
sessionStorage.setItem('user_password', encrypted_user_password);
decrypt:
var encrypted_user_id = sessionStorage.getItem('user_id');
var encrypted_user_password = sessionStorage.getItem('user_password');
var plaintext_user_id = CryptoJS.AES.decrypt(encrypted_user_id, cipher_pass).toString(CryptoJS.enc.Utf8);
var plaintext_user_password = CryptoJS.AES.decrypt(encrypted_user_password, cipher_pass).toString(CryptoJS.enc.Utf8);
There is no error, but the plaintext is empty string.
If I perform the exact same encryption/decryption using variables
instead of sessionStorage
it works fine.
What am I not understanding? Is there something about session variables that is different than a local variable?