web前端,RSA加密,提示“Message too long for RSA”

931 阅读1分钟

项目中需要加密一个很长的字符串,因为太长的缘故所以加密失败,加密结果返回false,并抛出如下错误:

Message too long for RSA

解决方法: 最终找到另一个npm依赖包----------> encryptlong <------------(使劲戳它,进入官网查看具体使用方法,这里不多做介绍),完美解决这个问题了。

修改后的代码:

const {JSEncrypt} = require('encryptlong')

let encryptedData = (data, key=PUBLIC_KEY) => {

let encryptor = new JSEncrypt()

encryptor.setPublicKey(key)

let cptData = encryptor.encryptLong(data)

return cptData

}

转载自:blog.csdn.net/qq_35164962…