MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / encrypt_json

Function encrypt_json

runners/helpers/ValidateRequest.cpp:1509–1527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1507}
1508
1509void encrypt_json(nlohmann::json &v, const td::Bits256 &private_key, const td::Bits256 &public_key,
1510 bool client_to_worker) {
1511 v["is_encrypted"] = "v1";
1512
1513 td::Ed25519::PrivateKey pk(td::SecureString{private_key.as_slice()});
1514 td::Bits256 pub;
1515 pub.as_slice().copy_from(pk.get_public_key().move_as_ok().as_octet_string().as_slice());
1516 v["sender_public_key"] = td::hex_encode(pub.as_slice());
1517 v["receiver_public_key"] = td::hex_encode(public_key.as_slice());
1518
1519 char buf[32];
1520 td::Random::secure_bytes(td::MutableSlice(buf, 32));
1521 auto encryption_nonce = td::base64_encode(td::Slice(buf, 32));
1522 v["encryption_nonce"] = encryption_nonce;
1523
1524 auto shared_secret =
1525 generate_shared_secret(private_key, public_key, pub, encryption_nonce, client_to_worker).move_as_ok();
1526 encrypt_all_strings(v, shared_secret.as_slice());
1527}
1528
1529td::Status decrypt_json(nlohmann::json &v, const td::Bits256 &private_key, td::Bits256 &public_key,
1530 bool check_public_key, bool client_to_worker) {

Callers 2

mainFunction · 0.85
add_next_answer_sliceMethod · 0.85

Calls 3

generate_shared_secretFunction · 0.85
encrypt_all_stringsFunction · 0.85
as_sliceMethod · 0.80

Tested by

no test coverage detected