Encrypt string in java, decrypt in node.js, error: bad decrypt

后端 未结 2 1473
春和景丽
春和景丽 2021-02-09 07:26

I\'m trying to encrypt a string in java, send it to my node.js server, and decrypt it. However, when I try to do this I get keep getting errors when trying to decrypt.

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 07:47

    Java crypto's default mode for DES is ECB, which you need to specify in nodejs:

    var decipher = crypto.createDecipheriv('des-ecb', key, new Buffer(0))
    var txt = decipher.update(encrypt_text, 'hex', 'utf8');
    txt += decipher.final('utf8')
    return txt
    

提交回复
热议问题