如何创建 Java 程序的试用版
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2769384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a trial version of a Java program
提问by Eddinho
I'm coding a software on java and i almost finished, i would like to know how can we create a trial version which work for example for 30 days, because i will to send it to some companies
我正在用 java 编写一个软件,我快完成了,我想知道我们如何创建一个试用版,例如可以使用 30 天,因为我会将它发送给一些公司
so how to make it like shareware or trialware, also can we block access to the .class in the jar file?
那么如何使它像共享软件或试用软件一样,我们是否也可以阻止对 jar 文件中的 .class 的访问?
Thank you
谢谢
采纳答案by Joe
There's a product called Rampart that lets you make a trial version for your Java app. It only takes a couple of minutes and it works pretty well.
有一个名为 Rampart 的产品,它可以让您为 Java 应用程序制作试用版。它只需要几分钟,而且效果很好。
You can find it at http://Rampartlicensing.com
回答by Marcus Adams
Why not just hard code an expiry date into the trial program so that you don't have to continue to support it? You could put this in main().
为什么不将到期日期硬编码到试用程序中,这样您就不必继续支持它了?你可以把它放在 main() 中。
// Die after October 1, 2010
Calendar expireDate = Calendar.getInstance();
// January is 0 (y, m, d)
expireDate.set(2010, 9, 1);
// Get current date and compare
if (Calendar.getInstance().after(expireDate)) {
// Die
System.exit(0);
}
This is how Microsoft distributes their large scale beta software. They just give it an expiry date.
这就是 Microsoft 分发其大规模测试版软件的方式。他们只是给它一个到期日。
If you're talking about preventing reverse engineering or modifying the code, you can't. You could obfuscate the compiled program, but this won't stop the people who would be reverse engineering your code anyway.
如果您正在谈论防止逆向工程或修改代码,则不能。您可以混淆编译后的程序,但这并不能阻止那些对您的代码进行逆向工程的人。
回答by Pyrolistical
I would just do something really simple and just hard enough such that non-programmers wouldn't be able to figure it out.
我只会做一些非常简单且足够困难的事情,以至于非程序员无法弄清楚。
I would something like write to a file the number of milliseconds when the program was first installed in a 64-bit long in binary to a file. And have your main class check and enforce the time limit. Yes people can change their clocks to work around this, but really you don't want to sell to those people anyways. Also ensure the current time is strictly within 30 days of the install. Most users will just set their clocks back one year and it works with most programs because they just did a simple less than the difference check. You should also check that the difference in number of days from current to install is also greater than 0.
我想将程序第一次以 64 位长的二进制文件安装到文件时的毫秒数写入文件。并让您的主班检查并执行时间限制。是的,人们可以改变他们的时钟来解决这个问题,但实际上你无论如何都不想卖给那些人。还要确保当前时间严格在安装后的 30 天内。大多数用户只会将他们的时钟调回一年,并且它适用于大多数程序,因为他们只是做了一个简单的小于差异检查。您还应该检查从当前安装到安装的天数差异是否也大于 0。
If you feel you need more protection than that, then you have a business model problem more than a software one. Its basically impossible to make it unhackable, especially since you can just extract and disassemble the class files.
如果你觉得你需要更多的保护,那么你的商业模式问题就不仅仅是软件问题了。基本上不可能使它无法破解,特别是因为您可以提取和反汇编类文件。
回答by Paul Tomblin
The problem with trying to limit the dates is that the naive solution of just checking the date is easily fooled if the person sets back their system clock. I worked with a guy who kept a VMWare virtual box just for running time limited software. A better approach would be to record the time of the last time it was run, and if the time ever goes before that time, you know the clock was set back and you can abort. The problem is figuring out how to stash that file somewhere where the user can't find it an overwrite it. Again, in the the VMWare or VirtualBox environment, the user could just roll back to an earlier snapshot.
尝试限制日期的问题在于,如果该人调回系统时钟,那么仅检查日期的幼稚解决方案很容易被愚弄。我和一个人一起工作,他保留了一个 VMWare 虚拟机,只是为了运行时间有限的软件。更好的方法是记录上次运行的时间,如果时间早于该时间,则您知道时钟已倒退,您可以中止。问题是弄清楚如何将该文件存储在用户无法找到并覆盖它的地方。同样,在 VMWare 或 VirtualBox 环境中,用户可以回滚到较早的快照。
In other words, you can limit some of the people some of the time, but not all of the people all of the time.
换句话说,您可以在某些时间限制某些人,但不能始终限制所有人。
回答by Eyal Schneider
Regarding the class files, you can't block access to them, but you can make their de-compiled version totally unreadable by obfuscation.
关于类文件,您不能阻止对它们的访问,但是您可以通过obfuscation使它们的反编译版本完全不可读。
回答by SyntaxT3rr0r
I work on a commercial Java software and it is protected.
我在开发一个商业 Java 软件,它受到保护。
Is mandating an Internet connection acceptable in your case? In our case, our software only makes sense if there's an Internet connection and hence we can make reverse engineering impossible by simply following this mantra:
在您的情况下是否可以接受强制 Internet 连接?在我们的例子中,我们的软件只有在有互联网连接的情况下才有意义,因此我们可以通过简单地遵循以下原则来使逆向工程变得不可能:
make sufficient part of the computation happen on the server side
在服务器端进行足够的计算
There's nothingagainst this an attacker can do besides:
有没有针对这个攻击者就可以做之外:
rewrite the part of your software that is happening on the server side
pirating your server
重写在服务器端发生的软件部分
盗版你的服务器
If our potential users are not happy with the fact that our software mandates an always-on Internet connection they can either buy or pirate one of our competitor's inferior product.
如果我们的潜在用户对我们的软件要求始终在线的 Internet 连接这一事实不满意,他们可以购买或盗用我们竞争对手的劣质产品之一。
Think of it this way: nobody ever succeeded in playing on Blizzard's battle.net using fake/generated license keys.
可以这样想:没有人使用伪造/生成的许可证密钥在暴雪的战网上成功玩过游戏。
Sure, a pirate could try to fake the whole battle.net, but then the pirated version wouldn't allow people to play in, say, the real WoW economy nor to compete on the real Starcraft ladder, etc.
当然,盗版者可以尝试伪造整个战网,但盗版版本将不允许人们在真正的魔兽世界经济中玩游戏,也不能在真正的星际争霸阶梯上竞争,等等。
Why did no-one managed to do that: because Blizzard made sufficient part of the computation happen on the server side.
为什么没有人做到这一点:因为暴雪在服务器端做了足够多的计算。
Sufficient part of the computation happening on the server side effectively means: "good games pirates".
发生在服务器端的足够部分计算实际上意味着:“好游戏盗版者”。
The more we move to an always-connected world, the easier it is to protect apps against piracy. Same for content (DRM), for the better or the worse.
我们越是进入一个始终互联的世界,就越容易保护应用程序免遭盗版。内容 (DRM) 相同,无论好坏。
回答by Jon Onstott
Here is an idea:
这是一个想法:
Create a database (such as a SQL Server database) that is publicly available on the web. It will keep a list of "trial version" license keys. You can use the same system for full-version license keys when your product is purchased.
When your Java software is first run, it'll cause a trial license to be created which will be stored in the database
The Java software checks for a valid license each time it is run. The date that the license was created is stored in the database so it doesn't matter what the client clocks are set at.
The software stops functioning when the license is expired
创建在 Web 上公开可用的数据库(例如 SQL Server 数据库)。它将保留“试用版”许可证密钥列表。购买产品时,您可以使用相同的系统获取完整版许可证密钥。
当您的 Java 软件第一次运行时,它会导致创建一个试用许可证,该许可证将存储在数据库中
Java 软件每次运行时都会检查是否有有效的许可证。许可证的创建日期存储在数据库中,因此客户端时钟的设置无关紧要。
许可证过期后软件停止运行
Standard windows software can look up the CPU ID and use that as part of the license, so that each computer can only run the trial software once. Does anyone know if there is a "JVM ID" of some kind that can be used for this purpose?
标准的 windows 软件可以查找 CPU ID 并将其用作许可证的一部分,这样每台计算机只能运行一次试用版软件。 有谁知道是否有某种“JVM ID”可用于此目的?
Maybe there is free or open-source license-related code out there already?
也许已经有免费或开源许可证相关的代码了?
回答by Cogsy
I've had success using True Licensein the past. It has a support for a trial period. Use it in combination with an obfuscation tool like ProGuardand it certainly makes it non-trivial to crack.
我过去曾成功使用True License。它支持试用期。将它与混淆工具(如ProGuard)结合使用,它肯定会让破解变得非常重要。
回答by Cogsy
I recommend functional limitions. I have little post it note program. The program works fully, but you can create only 10 notes in unregistered mode. So i try to be nice to user. No date limitions, nag screens or someting else evil. Only small status line that has limition text and and register button.
我推荐功能限制。我有很少的便笺程序。该程序完全运行,但您只能在未注册模式下创建 10 个笔记。所以我尽量对用户友好。没有日期限制、唠叨屏幕或其他邪恶的东西。只有带有限制文本和注册按钮的小状态行。
回答by Caesar
I check date from what an atomic time server will send me at the beginning at the code. Then, I will compare that date with a specific date. If the atomic time is less, then System.exit(0).
我从原子时间服务器将在代码开头发送给我的内容中检查日期。然后,我会将该日期与特定日期进行比较。如果原子时间更短,则 System.exit(0)。
public static GregorianCalendar getAtomicTime() throws IOException {
BufferedReader in = null;
try {
URLConnection conn = new URL("http://64.90.182.55:13").openConnection();
GregorianCalendar calendar = new GregorianCalendar();
conn.setConnectTimeout(1000);
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String atomicTime;
while (true) {
if ((atomicTime = in.readLine()).indexOf("*") > -1) {
break;
}
}
//System.out.println("DEBUG : " + atomicTime);
String[] fields = atomicTime.split(" ");
String[] date = fields[1].split("-");
calendar.set(Calendar.YEAR, 2000 + Integer.parseInt(date[0]));
calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1);
calendar.set(Calendar.DATE, Integer.parseInt(date[2]));
// deals with the timezone and the daylight-saving-time
TimeZone tz = TimeZone.getDefault();
int gmt = (tz.getRawOffset() + tz.getDSTSavings()) / 3600000;
//System.out.println("DEBUG : " + gmt);
String[] time = fields[2].split(":");
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0]) + gmt);
calendar.set(Calendar.MINUTE, Integer.parseInt(time[1]));
calendar.set(Calendar.SECOND, Integer.parseInt(time[2]));
return calendar;
} catch (IOException e) {
throw e;
} finally {
if (in != null) {
in.close();
}
}
}