我有一个http请求,我想传递一些敏感数据,所以我试图加密这些数据。在我的React Native应用程序中,我使用react-native-rsa-native生成了一对密钥,并通过RSA.encrypt函数(我的字符串,我的公钥)使用公钥加密我的字符串。
在此之后,我在我的http请求中发送生成的加密数据,并尝试在我的node.js环境中解密它(Google Cloud Functions)。为此我使用Crypto模块。
我导入它:
const crypto = require('crypto');
我尝试使用在react-native模块中生成的RSA私钥来解密我的数据:
crypto.privateDecrypt(rsaPrivateKey, myCryptedString)
但是我得到了错误:
TypeError:数据必须是位于CloudFunction的exports.createPaymentMethod.functions.https.onRequest(/user_code/index.js:928:10)的Object.privateDecrypt(crypto.js:375:12)的TypeError(本机)缓冲区( /user_code/node_modules/firebase-functions/lib/providers/https.js:37:41)/var/tmp/worker/worker.js:783:7 at /var/tmp/worker/worker.js:766: 11在_combinedTickCallback(internal / process / next_tick.js:73:7)at process._tickDomainCallback(internal / process / next_tick.js:128:9)
有人能解决我的问题吗?
根据documentation,密文应该是Buffer
而不是String
的实例,因此您可以尝试将密文包装到缓冲区中:
crypto.privateDecrypt(rsaPrivateKey, Buffer.from(myCryptedString))