我正在研究一个本机反应项目,并尝试通过加密并使用aes-256-gcm算法对照片进行加密和解密。此代码在android和ios模拟器上均能很好地运行,在调试时在设备上也没有问题,但是一旦我在android设备上停止远程JS调试,就会出现此错误:不支持的状态或无法进行身份验证数据。
我完全感到困惑,我不知道如何解决此问题。
我应该提到的是,此代码仅适用于小数据和字符串,只有大文件存在问题。
这是我的代码:
key = crypto.randomBytes(32);
static encryptFile = inData => {
let iv = Buffer.from(crypto.randomBytes(16));
let cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(inData, "binary", "hex");
encrypted += cipher.final("hex");
let cipherTag = cipher.getAuthTag();
encrypted += "," + iv.toString("hex") + "," + cipherTag.toString("hex");
return encrypted;
};
static decryptFile = inEncData => {