Dim
Dim

Reputation: 4807

Hiding class in open source application

I am creating open source application, and one of the classes I have needs to be hidden in open source. I need that when people will see my code the could not see this class. How can I do this? Maybe I can make jar file of this class?

Upvotes: 0

Views: 89

Answers (3)

user3053446
user3053446

Reputation: 124

Well, it's not really open source if you are hiding anything, but:

I would suggest using an asynch task and send a HTTP request to a PHP file and then send a JSON response back. You can interpret it with something like:

package jsonparse.pkg;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    public JSONObject getJSONFromUrl(String url) {

        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}

This way they can not see the php file.

You can do the same thing with an encrypted JS file maybe, I wouldn't know how to go about doing that.

Upvotes: 0

Greg Ennis
Greg Ennis

Reputation: 15379

The only reason I can see for doing this is not publishing an encryption key used to sign the official app that is published on the store. In this situation I simply do not commit the file into the repository, and I store it somewhere else.

Upvotes: 0

Nathan Walters
Nathan Walters

Reputation: 4136

If you are hiding a class, it is not truly open source. If obfuscating code from the end user is necessary, you should perhaps reconsider how you are publishing this.

Upvotes: 4

Related Questions