Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 用什么方法来保护Java程序的安全
bbrr



发贴: 0
积分: 0
于 2004-06-07 14:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Java编的程序很容易就可以用反编译程序还原成原代码。悲哀。

数字签名可以用来保护JAVA程序的安全吗?假如我编了一个C/S系统,对客户端的程序进行数字签名后再发给用户,那么在服务器端怎么才能保证只接受我自己进行签名的程序连接,而拒绝别人破解过的程序的连接?



作者 Re:用什么方法来保护Java程序的安全 [Re:bbrr]
menzy



版主


发贴: 754
积分: 113
于 2004-06-08 08:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看看实用工具jarsigner


作者 Re:用什么方法来保护Java程序的安全 [Re:bbrr]
sc33



版主


发贴: 128
积分: 30
于 2004-06-09 14:08 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
通过动态加载类的方法和混淆结合可以达到较安全的代码保护!

下面举一个动态加载类的例子,至于混淆,网上的例子很多,搜一下就可以了!我仅在这里抛砖引玉... ...


import java.io.*;
import java.lang.reflect.Method;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.zip.*;
import javax.crypto.*; //javax.crypto是1.4.0以上新增的包,用于加密
import javax.crypto.spec.DESKeySpec;
public class JptStart extends ClassLoader
{

private Hashtable htSizes;
private Hashtable htJarContents;
private String jarFileName;
private SecretKey key;
private Cipher cipher;

public JptStart(SecretKey secretkey, String s)
throws GeneralSecurityException, IOException
{
htSizes = new Hashtable();
htJarContents = new Hashtable();
key = secretkey;
jarFileName = s;
String s1 = "DES";
SecureRandom securerandom = new SecureRandom();
cipher = Cipher.getInstance(s1);//加密算法
cipher.init(2, secretkey, securerandom);
initvalue(s + ".jar");
}

public static void main(String args[])
throws Exception
{
String s = args[1];
String s1 = args[2];
String args1[] = new String[args.length - 3];
System.arraycopy(args, 3, args1, 0, args.length - 3);
byte abyte0[] = Util.readFileMoon;
DESKeySpec deskeyspec = new DESKeySpec(abyte0);
SecretKeyFactory secretkeyfactory = SecretKeyFactory.getInstance("DES");
SecretKey secretkey = secretkeyfactory.generateSecret(deskeyspec);
JptStart jptstart = new JptStart(secretkey, s1);
Class class1 = jptstart.loadClass(s1);
String args2[] = new String[1];
Class aclass[] = {
(new String[1]).getClass()
};
Method method = class1.getMethod("main", aclass);
Object aobj[] = {
args1
};
method.invoke(null, aobj);
}

private void initvalue(String s)
{
try
{
ZipFile zipfile = new ZipFileMoon;
ZipEntry zipentry;
for(Enumeration enumeration = zipfile.entries(); enumeration.hasMoreElements();

htSizes.put(zipentry.getName(), new Integer((int)zipentry.getSize())))
zipentry = (ZipEntry)enumeration.nextElement();

zipfile.close();
FileInputStream fileinputstream = new FileInputStreamMoon;
BufferedInputStream bufferedinputstream = new BufferedInputStream(fileinputstream);
ZipInputStream zipinputstream = new ZipInputStream(bufferedinputstream);
for(ZipEntry zipentry1 = null; (zipentry1 = zipinputstream.getNextEntry()) != nullWink
if(!zipentry1.isDirectory())
{
int i = (int)zipentry1.getSize();
if(i == -1)
i = ((Integer)htSizes.get(zipentry1.getName())).intvalue();
byte abyte0[] = new byte[i];
int j = 0;
boolean flag = false;
int k;
for(; i - j > 0; j += k)
{
k = zipinputstream.read(abyte0, j, i - j);
if(k == -1)
break;
}

htJarContents.put(zipentry1.getName(), abyte0);
}

}
catch(NullPointerException nullpointerexception)
{
nullpointerexception.printStackTrace();
}
catch(FileNotFoundException filenotfoundexception)
{
filenotfoundexception.printStackTrace();
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
}

public byte[] getJarResource(String s)
{
return (byte[])htJarContents.getMoon;
}

public Class loadClass(String s, boolean flag)
throws ClassNotFoundException
{
try
{
Class class1 = null;
class1 = findLoadedClassMoon;
if(class1 != null)
return class1;
byte abyte0[] = getJarResource(s + ".class");
if(abyte0 != null)
{
byte abyte1[] = cipher.doFinal(abyte0);
class1 = defineClass(s, abyte1, 0, abyte1.length);
}
if(class1 == null)
class1 = findSystemClassMoon;
if(flag && class1 != null)
resolveClass(class1);
return class1;
}
catch(GeneralSecurityException generalsecurityexception)
{
throw new ClassNotFoundException(generalsecurityexception.toString());
}
}
}




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923