英文:
How to prevent a user from opening/changing/editing a file inside a jar
问题
说我有一个文件 test.txt
,它被捆绑在我的 jar 文件中。这个文本文件可能最开始是空的,但随着程序运行,它将有数据被写入。我想阻止用户展开我的 jar
文件并以任何方式编辑这个文本文件。
这种可能吗?
为此我感到抱歉,因为这个问题比较简短/看起来有点懒,但目前我没有任何尝试可以展示出来。
英文:
Say I have a file test.txt
which is bundled inside my jar file. This text file might initially be empty but it will have data written to it as the program runs. I want to prevent the user from expanding my jar
file and editing this text file in anyway.
Is this possible?
Apologies for the short/seemingly lazy question but I do not have any attempt to show at the moment.
答案1
得分: 2
这根本是不可能的,jar文件是一个标准的zip文件,可以轻松解压。
如果您有敏感信息不希望用户篡改,您需要将其写回到您在其他地方控制的服务器。客户机上的任何内容都应该被视为已被泄漏和公开。
同样地,您可以在jar文件中加密文件,但在没有单独的服务器的情况下,jar文件必须携带解密密钥,因此这将带来轻微的不便,但仍然容易被解开。
英文:
It is simply not possible, the jar file is a standard zip file and trivially unpacked.
If you have sensitive information you don't want the user to tamper with you need to be writing it back to a server you control elsewhere. Anything on the client's machine should be assumed compromised and public.
By the same token you could encrypt the file inside the jar, but in the absence of a separate server the jar would necessarily have to carry the decryption keys with it as well so it becomes a minor inconvenience, but still easily unpicked.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论