-2

I want to develop code for which business logic should not open and I tried encapsulation and RMI to keep code at the secure end but anybody can get that using Reflection. Is there any possibilities?

  • 3
    No, it's not possible. – Kayaman Dec 12 '19 at 08:51
  • You can try obfuscator, check https://sourceforge.net/projects/proguard/ – Karthikeyan Vaithilingam Dec 12 '19 at 08:54
  • 2
    There are no possibilities that will defend you against someone with moderate "hacking" skills and sufficient time and motivation. – Stephen C Dec 12 '19 at 09:39
  • The only way you can keep your code private is to keep it only on your own machines (i.e. not distribute the software, but provide it "as a service"). – Thilo Dec 12 '19 at 10:26
  • @Thilo but we have to provide solutions to client for offline also as nowadays no one wants to share data on the cloud with others they want their own environment they demand to give all permission of server else we will secure by permission. So that's why I am looking for it. – Vishal Patel Dec 13 '19 at 05:27
  • @KarthikeyanVaithilingam that one which is provided by you is used for clean up code, not for security. – Vishal Patel Dec 13 '19 at 05:30

1 Answers1

0

You may want to try to read an encoded .class file and then load it using a custom class loader

    byte[] bytes = // read from encoded file and decode
    ClassLoader cl = new ClassLoader() {
        @Override
        public Class<?> loadClass(String name) {
            try {
                return super.loadClass(name);
            } catch (ClassNotFoundException e) {
                return defineClass(name, bytes, 0, bytes.length);
            }
        }
    };

    Class clazz = cl.loadClass("my.Decoded");
    Object o = clazz.getConstructor().newInstance();
    Method action = clazz.getMethod("action");
    action.invoke(o);
matepal297
  • 809
  • 1
  • 10
  • 18
  • what content should be there in "defineClass" method? – Vishal Patel Dec 13 '19 at 05:34
  • It is a protected ClassLoader#defineClass method. Youd don't need to write your own. https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#defineClass-java.lang.String-byte:A-int-int- – matepal297 Dec 13 '19 at 08:37