0
console.log("user id to encrypt: "+user.id) //user id to encrypt: 0
    crypted_uId = CryptoJS.AES.encrypt(user.id.toString(), 'pass123');
    console.log("encrypted uid on login: "+crypted_uId); //U2FsdGVkX1+senN8M0jydYxQKZVsu/+m3Qs/wvesnoM=
    decrypted_uId = CryptoJS.AES.decrypt(crypted_uId, 'pass123');
    console.log("decrypted uid on login: "+decrypted_uId); //30

Whats wrong? Why is it returning an unproper decryption?

mouchin777
  • 1,428
  • 1
  • 31
  • 59
  • 1
    by the way, 30 is hex representation of "0" symbol. try to encrypt 12345 and see whether you will get 3132333435 back. – Maxim Sagaydachny Jan 14 '20 at 09:52
  • @MaximSagaydachny you are right , this seems to be my issue, I should recode it from hex to whatever i need to use – mouchin777 Jan 14 '20 at 10:02
  • @MaximSagaydachny I dont actually know how to reconvert it back to a normal number. Do you know how to do it in thiscase? – mouchin777 Jan 14 '20 at 10:07
  • https://stackoverflow.com/questions/3745666/how-to-convert-from-hex-to-ascii-in-javascript Found the answer – mouchin777 Jan 14 '20 at 10:45

0 Answers0