From 258edb87c985e5d0013abec173da9ea7938fae53 Mon Sep 17 00:00:00 2001 From: johan12345 Date: Sun, 18 Apr 2021 13:51:23 +0200 Subject: [PATCH] add ability to pass Chargeprice API key in encrypted form to Gradle build (needed for F-Droid) --- app/build.gradle | 15 +++++++++++++++ gradle.properties | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 59dc70b6..fe1dab94 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,6 +86,9 @@ android { variant.resValue "string", "mapbox_key", mapboxKey } def chargepriceKey = env.CHARGEPRICE_API_KEY ?: project.findProperty("CHARGEPRICE_API_KEY") + if (chargepriceKey == null && project.hasProperty("CHARGEPRICE_API_KEY_ENCRYPTED")) { + chargepriceKey = decode(project.findProperty("CHARGEPRICE_API_KEY_ENCRYPTED"), "FmK.d,-f*p+rD+WK!eds") + } if (chargepriceKey != null) { variant.resValue "string", "chargeprice_key", chargepriceKey } @@ -188,3 +191,15 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1' } + +private static String decode(String s, String key) { + return new String(xorWithKey(s.decodeBase64(), key.getBytes()), "UTF-8"); +} + +private static byte[] xorWithKey(byte[] a, byte[] key) { + byte[] out = new byte[a.length]; + for (int i = 0; i < a.length; i++) { + out[i] = (byte) (a[i] ^ key[i%key.length]); + } + return out; +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 23339e0d..376270d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,4 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": -kotlin.code.style=official +kotlin.code.style=official \ No newline at end of file