1

I'm working on .NET app with C# and Visual Studio, I'm embedding two .txt files to import data and that works. I noted although that if I open the .exe with Notepad I can freely read the content of the .txt files inside the whole text. Do you know a way to prevent this? I know if you're enough informed you can just open the code of the program, but I just want this to not be readable this easy and still have it as embedded resource.

2 Answers2

2

I would suggest you encoding them with base64 which will make it less visible, if that works for you. As you already mentioned though, you can not totally prevent it - only make it harder.

likle
  • 1,717
  • 8
  • 10
  • Do I have to put all the content of the file into a string in the code then? Or can I just still use it as an embedded file to make it encoded? – grimoiredark Dec 31 '20 at 12:12
  • @grimoiredark You could already embed the text file encoded and then decode it when you read it – likle Dec 31 '20 at 12:14
  • Ok, the fact is it's a 3-4 MBs txt file with a dictionary-structured content, so i don't know if that is possible, since it's full of " "...I can try. – grimoiredark Dec 31 '20 at 12:17
  • @grimoiredark That should work with all kinds of strings, the size might be a little bigger though if you encode it – likle Dec 31 '20 at 12:19
  • Ok, it seems to work for me and I really thank you for that. Now i only have one question: it sometimes happened to me that opening/saving some text via MS Word (or other editors) with special fonts or symbols turned them in other fonts, example, the "é" became "?" or "À" or something like that...so, is this method safe for that matter? If it is, it's definitely the solution I was looking for. – grimoiredark Dec 31 '20 at 13:13
  • @grimoiredark That's probably because of a mismatch of the text encoding (e.g. UTF-8) before encoding and after decoding. Did you use the functions [here](https://stackoverflow.com/questions/11743160/how-do-i-encode-and-decode-a-base64-string) for both, the encoding and the decoding of the file? – likle Dec 31 '20 at 13:20
  • Actually I'm asking just to be sure that can't happen, what I'm referring to is a simple case of opening/saving files, nothing to do with encoding :) the code i used for this now is just `Convert.ToBase64String(Encoding.UTF8.GetBytes()` for saving a text file and `Encoding.UTF8.GetString(Convert.FromBase64String()` to open that text file. – grimoiredark Dec 31 '20 at 13:27
  • @grimoiredark base64 won't break your symbols, it really just translates the bytes into other bytes and back. So this method will not introduce new problems here. Just to be clear: even without base64/obfuscation, you will have to make sure that you are consistent with the encoding you select when you save the file in your editor and when you read the file. – likle Dec 31 '20 at 13:34
2

You can't hide data that your application must process. It'll be readable from memory using a debugger, or viewable using a resource viewer or decompiler on the executable.

If all you're looking for is to make viewing that data less trivial for the average user, you could consider obfuscation. You could use ROT13 or Base64 to hide the original text.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272