My program (written in C++) utilizes a telegram bot for sending me status messages. For being able to do that it needs the bot token (a simple string), something which I prefer to keep private.
This program will not only run on my own computer, but also on other (shared) computers, where I have to compile the program on. Thus I was wondering if it is possible to put the token into the code such that it can not be read out by others, but still can be used by the program?
The source code is residing next to the program, due to the need of recompilation, i.e. if the token is in the source code, everyone can read it.
Is that even possible, or is securing the token impossible on the shared computer?

1 Answer 1


Is it possible to share the token privately

No. If the machine can access the token then the token can be recovered (assuming you can't place it in SGX or a trusted module).

How to workaround

You can set up a server which recieves API calls, and then forwards the body of them to you, the server can hold the token, so your compiled code never needs to handle it. You could host this on a serverless platform if you prefer (AWS Lambda, Google Cloud Functions, Azure Functions etc.).

enter image description here

Possible issues

If anyone can message you, you may receive a lot of spam, depending on how you filter it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.