问题描述
我正在建立基于非对称加密的POC,其中将下载KMS的公共密钥并在客户端使用它来加密敏感数据,一旦在服务器端接收到该数据,就需要使用KMS解密功能对其进行解密。 使用KMS进行加密和解密工作正常,但是当我使用下载的公共密钥加密然后使用KMS解密时,我得到 invalidCiphertextException:null
CMK密码配置为 https://i.stack.imgur.com/0muAb.png
我用于加密的代码是
var encrypt_with_public_key = function (data) {
let fs = require('fs'),path = require('path'),absolutePath = path.join(__dirname,'Publickey.pem');
let publicKey = fs.readFileSync(absolutePath,"utf8");
let encrypted = crypto.publicEncrypt({
key: Buffer.from(publicKey),oaepHash: "sha256",},Buffer.from(data)).toString("base64");
return encrypted;
}
用于解密的代码为
var decrypt_data = function (data) {
try {
let params = {
KeyId: kmsConfig["KeyId"],EncryptionAlgorithm: kmsConfig["EncryptionAlgorithm"] /* RSAES_OAEP_SHA_256*/
}
params.CiphertextBlob = Buffer.from(data)
return kms.decrypt(params).promise().then(data => data.Plaintext);
}
catch (ex) {
throw ex
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)