1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| import java.net.MalformedURLException;
import java.net.URL;
public class Main {
public static final String CLASSES_URL = "http://f.slukjanov.name/jc13/03/";
public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, IllegalAccessException,
InstantiationException {
EncryptedClassesClassLoader noEncryptClassLoader = new EncryptedClassesClassLoader(new URL(CLASSES_URL));
Class<?> secretKeyClass = noEncryptClassLoader.loadClass("ru.sgu.itcourses.Key");
Object secretKeyInstance = secretKeyClass.newInstance();
String secretKey = secretKeyInstance.toString();
System.out.println("secretKey=" + secretKey);
EncryptedClassesClassLoader encryptedClassesClassLoader = new EncryptedClassesClassLoader(new URL(CLASSES_URL),
secretKey);
Class<?> secretClass = encryptedClassesClassLoader.loadClass("ru.sgu.itcourses.Secret");
Object secretInstance = secretClass.newInstance();
System.out.println("secretMessage=" + secretInstance.toString());
}
}
|