Мне нужно расшифровать данные 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, ни оповещение.