Hide strings easily with that lib (and script)! It uses AES/ECB/PKCS5Padding transformation to convert strings with your app's SHA1 fingerprint.
Put AndroidStringObfuscator.jar in the root of the project.
repositories {
jcenter()
}
dependencies {
compile 'efraespada:androidstringobfuscator:0.4.1'
}
android.applicationVariants.all{ variant ->
variant.mergeResources.doLast{
println ":" + project.name + ":initStringObfuscator"
javaexec {
main = "-jar";
args = [
"../AndroidStringObfuscator.jar",
project.name,
variant.dirName
]
}
}
}Initialize the library:
AndroidStringObfuscator.init(this);The script 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 = AndroidStringObfuscator.encryptString(some_string_var);From resources:
String decrypted = AndroidStringObfuscator.getString(R.string.hello);Or from encrypted variables:
String decrypted = AndroidStringObfuscator.decryptString(encrypted_var);AndroidStringObfuscator.init(this);
// getting encrypted string resources
int stringId = R.string.hello;
String message = getString(stringId);
message += " is ";
message += AndroidStringObfuscator.getString(stringId);
// and secret
String mySecret = "lalilulelo";
message += "\n\nFor Metal Gear lovers:\n\n\"Snake, the password is " +
AndroidStringObfuscator.encryptString(mySecret) +
"\n\n.. or " +
AndroidStringObfuscator.decryptString(AndroidStringObfuscator.encryptString(mySecret)) +
"\"";
((TextView) findViewById(R.id.example)).setText(message);...
:sample:mergeDebugResources
:sample:initStringObfuscator
:sample:obfuscator-script - -----------------------------------------------------------------------------
:sample:obfuscator-script - debug variant
:sample:obfuscator-script - SHA1 fingerprint: E1:28:0C:3E:65:91:2E:21:E9:98:2B:58:80:9A:25:3A:F6:88:7D:FF
:sample:obfuscator-script - [hello world!] - [D1862D9B434D08E..]
:sample:obfuscator-script - -----------------------------------------------------------------------------
:sample:obfuscator-script - v 0.6
:sample:processDebugManifest UP-TO-DATE
...
If you haven't installed Gradle before you compile:
...
:sample:obfuscator-script - Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip
:sample:obfuscator-script - Unzipping /Users/efraespada/.gradle/wrapper/dists/gradle-2.14.1-all/8bnwg5hd3w55iofp58khbp6yv/gradle-2.14.1-all.zip to /Users/efraespada/.gradle/wrapper/dists/gradle-2.14.1-all/8bnwg5hd3w55iofp58khbp6yv
:sample:obfuscator-script - Set executable permissions for: /Users/efraespada/.gradle/wrapper/dists/gradle-2.14.1-all/8bnwg5hd3w55iofp58khbp6yv/gradle-2.14.1/bin/gradle
...
If ~/.android/debug.keystore is missing, run your app to generate that file. For non default keystore file, check your project configuration.
...
:sample:obfuscator-script - debug variant
:sample:obfuscator-script - Missing keystore
:sample:obfuscator-script - SHA1 fingerprint not detected; try params [module] [variant] [optional:sha1]
...
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.
