javascript - setState 在远程调试器打开时完美运行,但在它关闭时无法正常工作
问题描述
我需要使用私钥解密 json 数据,当远程调试器打开时,该功能可以正常工作,但是当我停止它时,它永远不会得到解决。
我试过用 async/await 来做,但没有任何改变
decryptWithPrivateKey = (privateKey, encrypted) => {
const buf = new Buffer(encrypted, "hex");
encrypted = {
iv: buf.toString("hex", 0, 16),
ephemPublicKey: buf.toString("hex", 16, 49),
mac: buf.toString("hex", 49, 81),
ciphertext: buf.toString("hex", 81, buf.length)
};
// decompress publicKey
encrypted.ephemPublicKey = publicKeyConvert(
new Buffer(encrypted.ephemPublicKey, "hex"),
false
).toString("hex");
const twoStripped = privateKey.substring(2);
const encryptedBuffer = {
iv: new Buffer(encrypted.iv, "hex"),
ephemPublicKey: new Buffer(encrypted.ephemPublicKey, "hex"),
ciphertext: new Buffer(encrypted.ciphertext, "hex"),
mac: new Buffer(encrypted.mac, "hex")
};
return decrypt(new Buffer(twoStripped, "hex"),
encryptedBuffer).then(
decryptedBuffer => decryptedBuffer.toString()
);
};
像这样称呼它:
<TouchableOpacity
onPress={() => {
this.decryptWithPrivateKey(
this.state.privateKey,
this.state.ciphered
).then(result => {
this.setState({ deciphered: result }, () => {
console.log(this.state.deciphered);
alert(this.state.deciphered);
});
});
}}
>
<Text>decrypt</Text>
</TouchableOpacity>
当按下按钮并且远程调试器打开时,它工作得很好。一旦调试器关闭,它既不会设置状态也不会发出警报。
解决方案
推荐阅读
- python - 如何编写 mysql db 数据的 if 条件(条件:qty == 0)然后电子邮件应该发送给管理员
- r - 为什么不同组之间的 p 值总是相同的,有人知道我在做什么错吗?
- excel - 将图像从 Excel 粘贴到 Word 中的特定占位符
- python-3.x - 当用硒和美丽的汤刮页面时,我会得到一些结果的重复
- amazon-sqs - Masstransit amazon-sqs 健康检查问题
- c++ - 为什么所有指针都没有被释放?
- javascript - 如何恢复来自 GetStream.io 提要的反应
- python - 使用 PyQt5 更新接口
- swift - 使用 PythonKit 加载 python 文件时遇到问题
- karate - 由于扩展协商错误,空手道 WebSocket 连接失败