Download Java Class File & Run? -


okay, pretty i'm trying add security java class file. don't want decompiled. i've done created login system java app checks through web request. if login information correct run script. however, want further improve security , have class file hosted online.

how can make download & run online hosted file?

also, when app/script stops running or it's closed .class file deleted.

i'd prefer did not have download file, online server , compile/run.

create new urlclassloader (the "default" java classloader) , point @ wherever saved file:

// directory you're saving .class file file tmpdir = new file("/tmp/yadda/blah/"); classloader cl = new urlclassloader(new url[] { tmpdir.touri().tourl() }, thread.currentthread().getcontextclassloader()); class<?> cls = cl.loadclass("supersecretclass"); // use reflection instantiate cls, call methods, etc. 

(passing in parent class loader might not necessary in non-webapp, i'm lazy test detail. using thread's classloader explicitly work 1 way or other.

this assumes secret class not in package, if you'll have create appropriate directory structure inside temporary directory , point classloader @ root of package tree, usual.

also: sort of security-by-obscurity sounds bad idea. you're still downloading file, if it's on unsecured connection determined attacker can sniff it, , there's still period of time during it's on disk. could create custom classloader directly reads stream, class file recovered little more effort. (like pointing debugger @ main app , intercepting stream reads.) javadoc classloader provides example of how this.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -