我正在嘗試加密和解密 react-native 上的數(shù)據(jù)。所以我決定通過 browserify 在我的 react native 項目中使用加密節(jié)點(diǎn)模塊。下面是我用于加密的代碼片段,但它拋出錯誤TypeError: The first argument must be one type string, Buffer, ArrayBuffer, Array, or Array-like Object. 在 cryptoJS 中接收到類型對象。另外,當(dāng)我在 nodeJS 中使用代碼時,它可以正常工作,但是在本機(jī)反應(yīng)中會引發(fā)該錯誤。我在這里做錯了什么?我認(rèn)為錯誤是從 BUffer.from 語句引發(fā)的,該語句認(rèn)為變量 k 不是數(shù)組或更類似于對象。但這是我的想法,我不知道真正的原因是什么。這是代碼片段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);
TypeError:第一個參數(shù)必須是 string、Buffer、ArrayBuffer、Array
Smart貓小萌
2022-11-11 16:39:48