Skip to content

Commit

Permalink
Merge pull request #30 from StringCare/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
efraespada authored Feb 3, 2018
2 parents a393553 + 344a936 commit 2c2fff2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 17 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gradle implementation
buildscript {

ext {
stringcare_version = '0.6'
stringcare_version = '0.7'
}

repositories {
Expand Down Expand Up @@ -57,8 +57,9 @@ The plugin will encrypt all string tags with `hidden="true"` as attribute.

```xml
<resources>
<string name="hello" hidden="true">hello world!</string>
<string name="app_name">StringObfuscator</string>
<string name="app_name">StringObfuscator</string>
<string name="hello" hidden="true">hello world!</string>
<string name="test_a" hidden="true">%1$s (%2$d)</string>
</resources>
```

Expand All @@ -72,6 +73,7 @@ String encrypted = SC.encryptString(string_var);
From resources:
```java
String decrypted = SC.getString(R.string.hello);
String decrypted = SC.getString(R.string.test_a, "hi", 3); // hi (3)
```
Or from encrypted variables:
```java
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
buildscript {

ext {
stringcare_version = '0.6'
stringcare_version = '0.7'
}

repositories {
Expand All @@ -16,7 +16,7 @@ buildscript {

dependencies {
classpath "com.stringcare:plugin:$stringcare_version"
// classpath files('../AndroidPlugin/build/libs/plugin-0.4.jar')
// classpath files('../AndroidPlugin/build/libs/plugin-0.7.jar')
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "0.6"
version = "0.7"

android {
compileSdkVersion 25
Expand All @@ -11,7 +11,7 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionCode 2
versionName version

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
17 changes: 16 additions & 1 deletion library/src/main/java/com/stringcare/library/SC.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.res.Resources;
import android.os.Build;
import android.support.annotation.StringRes;
import android.util.Log;

import java.io.ByteArrayInputStream;
Expand All @@ -16,6 +19,7 @@
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Locale;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
Expand Down Expand Up @@ -148,7 +152,7 @@ private static String byteArrayToHexString(byte[] bytes) {
* @param id
* @return String
*/
public static String getString(int id) {
public static String getString(@StringRes int id) {
if (context == null) {
Log.e(TAG, "Library not initialized: SC.init(Context)");
return null;
Expand All @@ -163,6 +167,17 @@ public static String getString(int id) {
return context.getString(id); // returns original value, maybe not encrypted
}

public static String getString(@StringRes int id, Object... formatArgs) {
String value = getString(id);
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = Resources.getSystem().getConfiguration().getLocales().get(0);
} else {
locale = Resources.getSystem().getConfiguration().locale;
}
return String.format(locale, value, formatArgs);
}

/**
* encrypts the given value
* @param value
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">AndroidStringObfuscator</string>
<string name="app_name">StringCareLibrary</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ protected void onCreate(Bundle savedInstanceState) {
message += " is ";
message += SC.getString(stringId);

// secret
// secret var
String mySecret = "lalilulelo";

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

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

String numbers = getString(R.string.test_a, "hi", 3) + " is " + SC.getString(R.string.test_a, "hi", 3);
((TextView) findViewById(R.id.example_b)).setText(numbers);

}
}
30 changes: 24 additions & 6 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,31 @@
android:background="@android:color/background_light"
tools:context="com.efraespada.stringobfuscator.MainActivity">

<TextView
android:id="@+id/example"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@android:color/black"
android:text="" />
android:orientation="vertical"
android:layout_centerInParent="true">

<TextView
android:padding="10dp"
android:id="@+id/example_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@android:color/black"
android:text="" />

<TextView
android:padding="10dp"
android:id="@+id/example_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@android:color/black"
android:text="" />

</LinearLayout>


</RelativeLayout>
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="hello" hidden="true">hello world!</string>
<string name="app_name">String Obfuscator Sample</string>
<string name="test_a" hidden="true">%1$s (%2$d)</string>
</resources>

0 comments on commit 2c2fff2

Please sign in to comment.