当前位置:   article > 正文

crypto-js解密报错malformed utf-8 data_malformed utf-8 data at object.stringify

malformed utf-8 data at object.stringify

在使用crypto-js进行解密的时候,有可能会报错:

Malformed UTF-8 data
Error: Malformed UTF-8 data
    at Object.stringify (d:\StudeyCode\myStudy\encryptDemo\routes\encrypt\crypto-js.js:478:27)
    at WordArray.init.toString (d:\StudeyCode\myStudy\encryptDemo\routes\encrypt\crypto-js.js:215:41)
    at decryptByDESModeCBC (d:\StudeyCode\myStudy\encryptDemo\routes\encrypt\crypto.js:90:22)
    at testSign (d:\StudeyCode\myStudy\encryptDemo\routes\test.js:34:18)
    at Layer.handle [as handle_request] (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\layer.js:95:5)
    at next (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\layer.js:95:5)
    at d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\index.js:335:12)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

报错的原因是: des解密时,如果加密数据不是8的整数倍就会报上述错误,
解决办法:将数据加密后,再进行base64进行加密,解密时首先通过base64进行解密,然后再进行des解密。即可解决上述问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/576016
推荐阅读
相关标签
  

闽ICP备14008679号