我需要使用私钥解密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>
按下按钮并打开远程调试器时,它可以正常工作。调试器关闭后,既不会执行setState也不会发出警报。