[英]TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object
[英]TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type object in cryptoJS
我正在嘗試加密和解密 react-native 上的數據。 所以我決定通過 browserify 在我的 react native 項目中使用加密節點模塊。 下面是我用於加密的代碼片段,但它會拋出錯誤TypeError:第一個參數必須是類型字符串、緩沖區、數組緩沖區、數組或類似數組的 Object 之一。 在 cryptoJS 中接收到類型 object 。 另外,當我在 nodeJS 中使用代碼時,它可以正常工作,但是在本機反應中會引發該錯誤。 我在這里做錯了什么? 我認為錯誤是由 BUffer.from 語句引發的,該語句認為變量 k 不是數組或更類似於 object。 但這是我的想法,我不知道真正的原因是什么。 這是代碼片段
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);
問題已解決,只需在createCipheriv 中將 null替換為 ' ',感謝@Topaco
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.