Java to JS and JS to Java encryption using cryptojs

前端 未结 1 2081
逝去的感伤
逝去的感伤 2020-12-31 23:55

I got on this post a couple of weeks ago and worked perfectly: Compatible AES algorithm for Java and Javascript

Now, I need to do the reverse operation, but once in

1条回答
  •  爱一瞬间的悲伤
    2021-01-01 00:23

    Change

    return CryptoJS.enc.Base64.parse(encrypted.toString()).toString();
    

    to

    return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
    

    The encrypted object usually stringifies into an OpenSSL format which might also contain the salt. If you're only interested in the actual ciphertext, then you need to stringify the ciphertext property.

    Note that toString() takes an optional encoding function. Use the one that you need.

    0 讨论(0)
提交回复
热议问题