如何防止用户打开/更改/编辑 jar 内的文件

huangapple go评论51阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年9月9日 23:15:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63814647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定