我正在尝试加密和解密 react-native 上的数据。所以我决定通过 browserify 在我的 react native 项目中使用加密节点模块。下面是我用于加密的代码片段,但它抛出错误TypeError: The first argument must be one type string, Buffer, ArrayBuffer, Array, or Array-like Object. 在 cryptoJS 中接收到类型对象。另外,当我在 nodeJS 中使用代码时,它可以正常工作,但是在本机反应中会引发该错误。我在这里做错了什么?我认为错误是从 BUffer.from 语句引发的,该语句认为变量 k 不是数组或更类似于对象。但这是我的想法,我不知道真正的原因是什么。这是代码片段
const algorithm = 'des-ede';
const key = [
43,
57,
97,
-68,
-63,
-61,
-40,
9,
50,
87,
-104,
101,
63,
34,
-78,
60,
];
var CryptoJS = require('../crypto/crypto');
var k = new Buffer.from(key);
let cipher = CryptoJS.createCipheriv(algorithm, k, null);
cipher.setAutoPadding(true); //default true
var ciph = cipher.update("Hello World!'", 'utf8', 'base64');
ciph += cipher.final('base64');
console.log(ciph);
白衣非少年
相关分类