use*_*741 2 java security applet
我编写了一个Java Applet并从我的网站上运行它.
从长远来看,我计划每次使用此applet收取费用.
问题是,是否有可能阻止用户下载我的代码(即我的jar文件)然后从家里运行它而不付费?
(在这里我不是指反编译 - 我使用混淆器.我的意思是有人可以轻松使用它,甚至不用反编译或理解它的代码......)
我想过使用服务器使用HTML发送到applet的更改密码,但我想 - 也许有人知道实现我的目标的标准方法,而不是重新发明轮子?
谢谢..
有几种方法可以做到这一点.
您可以在applet init方法的开头放置这样的代码,假设它创建了一些组件:
if (!getDocumentBase().getHost().equals("yourhost.com")) {
JOptionPane.showMessageDialog(this, "You can't download it");
return;
}
Run Code Online (Sandbox Code Playgroud)
当然,您必须更改yourhost.com为您的实际网站.
您可以将所有代码放在服务器上.为此,我将假设您的applet计算整数的立方体.
然后代码对于您的applet看起来像这样:
public class CubingApplet extends JApplet {
private JTextField intField = new JTextField(3);
private JLabel output = new JLabel();
public void init() {
setLayout(new GridLayout(2, 2));
add(new JLabel("Enter an integer: "));
add(intField);
add(new JLabel("The cube of that is: ");
add(output);
intField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
output.setText("" + getCube());
}
};
}
private int getCube() {
try {
int n = Integer.parseInt(intField.getText());
InputStream response = new URL("http://www.yourhost.com/dosomething.php?n=" + n).openStream();
String sResponse = new BufferedReader(new InputStreamReader(response)).readLine();
return Integer.parseInt(sResponse);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我现在必须停止写这个,但我会尽早添加服务器端代码.
顺便说一下,即使你混淆了,也无法反编译,也可以识别出这些保护方案的样子,然后将它们删除.因此,您设计的任何保护方案都可能被短路,因为没有混淆是防弹的.
| 归档时间: |
|
| 查看次数: |
1409 次 |
| 最近记录: |