在使用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)
报错的原因是: des解密时,如果加密数据不是8的整数倍就会报上述错误,
解决办法:将数据加密后,再进行base64进行加密,解密时首先通过base64进行解密,然后再进行des解密。即可解决上述问题。