我正在嘗試加密和解密 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);
TypeError:第一個參數必須是 string、Buffer、ArrayBuffer、Array
Smart貓小萌
2022-11-11 16:39:48
