Hide sensitive string in unity

I made an app on the WebGL platform integrating ChatGPT to interact with the user. The problem I have now is I’m hardcoding my API token on the file, something like this:

public string secretkey = "p2lbgWkFrykA4Q......zmc5BNzIABq";

I know it’s bad practice and people can easily see this but is there a way to hide or encrypt it so it’s not easily visible? I’m not saying to make it secure because, obviously, if the token is in the file, it can be grabbed, but just to make it a little bit harder for people to see the token.

Lookup securestring, but, in essence at some point that string is going to be used, and likely in a raw form…

yep, the string is visible once it is in use. even if I have it in a data file, this will be shown once it is read. any suggestions …

if you can make request through your server (like calling php script or websocket…,
so the server has the api key then, not in the webgl build itself)

1 Like

I tried that, too once the web socket is called, the value needs to be stored locally for the GPT to work, and that variable exposes this key. is this what u are saying, or is something different?

Did you check the terms of service? Very likely to be against the TOS to provide other users access to ChatGPT via your own API key. Typically, if you act as a “reseller” of sorts it’s either outright forbidden, or you have to pay premium.

i mean that server would do all the API requests and just pass the answers/questions as a “middleman”. (then webgl doesnt need to know anything, it just uses your server to send questions & receive replies)