/AndroidLibrary

Android library to obfuscate strings at runtime

Primary LanguageJavaApache License 2.0Apache-2.0

String Care Android Library

Hide strings easily with that lib and plugin! It uses AES/ECB/PKCS5Padding transformation to convert strings with your app's SHA1 fingerprint.

Gradle implementation

// root_project/build.gradle
  
buildscript { 
 
    ext {
        stringcare_version = '0.5'
    }
    
    repositories {
        jcenter()
    }
    
    dependencies {
        classpath "com.stringcare:plugin:$stringcare_version"
    }
     
}
 
apply plugin: StringCare
// root_project/your_module/build.gradle

repositories {
    jcenter()
} 
 
dependencies {
    implementation "com.stringcare:library:$stringcare_version"
}

Setup

Initialize the library:

SC.init(getApplicationContext());

Encrypt

The plugin will encrypt all string tags with hidden="true" as attribute.

<resources>
	<string name="hello" hidden="true">hello world!</string>
	<string name="app_name">StringObfuscator</string>
</resources>

Or encrypt strings programmatically by doing:

String encrypted = SC.encryptString(string_var);

Decrypt

From resources:

String decrypted = SC.getString(R.string.hello);

Or from encrypted variables:

String decrypted = SC.decryptString(encrypted_var);

Sample

SC.init(getApplicationContext());

// getting encrypted string resources
int stringId = R.string.hello;

String message = getString(stringId);
message += " is ";
message += SC.getString(stringId);

// and secret
String mySecret = "lalilulelo";

message += "\n\nFor Metal Gear lovers:\n\n\"Snake, the password is " +
    SC.encryptString(mySecret) +
    "\n\n.. or " +
    SC.decryptString(SC.encryptString(mySecret)) +
    "\"";

((TextView) findViewById(R.id.example)).setText(message);

Configuration

By default the plugin will encrypt every strings.xml file inside src/mainfolder but you can choose a different configuration.

// root_folder/build.gradle
 
apply plugin: StringCare
 
stringcare {
 
    debug true  // prints details
 
    modules {
     
        sample {
            stringFiles = ['strings.xml',"other_file.xml"]
            srcFolders = ['src/main', "other_folder"]
        }
        
        // root_folder/sample/src/main/res/.../strings.xml
        // root_folder/sample/src/main/res/.../other_file.xml
        // root_folder/sample/other_folder/res/.../strings.xml
        // root_folder/sample/other_folder/res/.../other_file.xml
        
        other_module {
            srcFolders = ['src/moduleB']
        }
        
        // root_folder/other_module/src/moduleB/res/.../strings.xml
        
        other_module_ {} // 
        
        // root_folder/other_module_/src/main/res/.../strings.xml
        
    }
     
}

Gradle Console Output Example

...
:sample:generateDebugResValues UP-TO-DATE
:sample:generateDebugResources UP-TO-DATE
:sample:mergeDebugResources
:sample:debug:B8:DC:47:58:9B:5F:2C:21:45:C4:04:37:0E:56:53:DC:24:6B:2C:66
:sample:backupStringResources
	- values/strings.xml
:sample:encryptStringResources
	- values/strings.xml
		[hello world!] - [A8590C43DA85D67..]
:sample:mergeDebugResources UP-TO-DATE
:sample:restoreStringResources
	- values/strings.xml
:sample:createDebugCompatibleScreenManifests UP-TO-DATE
...

Plugin won't work if there is no config defined for the selected variant:

...
:sample:mergeReleaseResources
    🤯 no config defined for variant release
:sample:createReleaseCompatibleScreenManifests
...

License

Copyright 2017 Efraín Espada

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.