How to secure webservice URL?

前端 未结 4 2022
借酒劲吻你
借酒劲吻你 2021-01-07 14:41

I have an android app with web service urls. If anyone decrypts my apk file, the webservice url will become visible.I am using HTTP POST for calling web service.

An

4条回答
  •  走了就别回头了
    2021-01-07 15:05

    I use it this in all android application I developed

    gradle.properties

    API = http://ec2xxxxx.compute.amazonaws.com
    API_KEY = $2c11SoL/NjJ28
    

    create utils.gradle

    utils.gradle

            class Utils {
            static def r = new Random(System.currentTimeMillis())
        }
    
        def String toJavaCodeString(String string) {
            byte[] b = string.getBytes();
            int c = b.length;
            StringBuilder sb = new StringBuilder();
    
            sb.append("(new Object() {");
            sb.append("int t;");
            sb.append("public String toString() {");
            sb.append("byte[] buf = new byte[");
            sb.append(c);
            sb.append("];");
    
            for (int i = 0; i < c; ++i) {
                int t = Utils.r.nextInt();
                int f = Utils.r.nextInt(24) + 1;
    
                t = (t & ~(0xff << f)) | (b[i] << f);
    
                sb.append("t = ");
                sb.append(t);
                sb.append(";");
                sb.append("buf[");
                sb.append(i);
                sb.append("] = (byte) (t >>> ");
                sb.append(f);
                sb.append(");");
            }
    
            sb.append("return new String(buf);");
            sb.append("}}.toString())");
    
            return sb.toString();} 
    ext.toJavaCodeString = this.&toJavaCodeString
    

    build.gradle

    apply from: "utils.gradle"
       android {
        defaultConfig {
            buildConfigField 'String', 'API', toJavaCodeString(API)
            buildConfigField 'String', 'API_KEY', toJavaCodeString(API_KEY)
        }}
    

    and access your private url;

        public static final String API = BuildConfig.API;
    

提交回复
热议问题