Skip to content

Instantly share code, notes, and snippets.

@igor-brishkoski
igor-brishkoski / alias_decrypt.sh
Created January 3, 2018 18:42
Decrypt your secrets
# put this in your .bashrc or .zshrc or whatever you're using
# make sure you're in the directory where the file is when running this command
alias decrypt_secrets='openssl enc -d -aes-256-cbc -in secrets.properties.enc -out secrets.properties'
@igor-brishkoski
igor-brishkoski / alias_encrypt.sh
Last active January 3, 2018 18:39
Create alias for encrypting your secrets
# put this in your .bashrc or .zshrc or whatever you're using
# make sure you're in the directory where the file is when running this command
alias encrypt_secrets='openssl enc -aes-256-cbc -salt -in secrets.properties -out secrets.properties.enc'
@igor-brishkoski
igor-brishkoski / use_res_values_in_manifest.xml
Created January 2, 2018 23:08
We can use the resource value from build.gradle in our manifest.
//AndroidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
@igor-brishkoski
igor-brishkoski / use_build_config.java
Last active January 2, 2018 23:08
We can use the config variables from build.gradle in your java code
// java code
...
//init the service
return new ExpensiveServiceThatMyAppUses.Builder()
.initWithKey(BuildConfig.SERVICE_THAT_I_NEED); // use the value here
.someConfig(true)
.build();
...
@igor-brishkoski
igor-brishkoski / decrypt.sh
Created January 2, 2018 22:53
Decrypt the encrypted file
https://superuser.com/questions/370388/simple-built-in-way-to-encrypt-and-decrypt-a-file-on-a-mac-via-command-line
# decrypt binary file.enc
openssl enc -d -aes-256-cbc -in secrets.properties.enc -out secrets.properties
# decrypt base64-encoded version
openssl enc -d -aes-256-cbc -a -in secrets.properties.enc -out secrets.properties
@igor-brishkoski
igor-brishkoski / AndroidManifest.xml
Created January 2, 2018 21:15
AndroidManifest hardcoded value
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
....
//We want to use google maps in our app
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="kx23x234x4x234kjfd9845n" /> // DON'T HARDCODE THE VALUE
....
</manifest>
@igor-brishkoski
igor-brishkoski / extract_keys_from_gradle.groovy
Last active May 4, 2017 00:17
Extract the keys from build.gradle
//build.gradle
android{
...
productFlavors{
staging{
//use in java code
buildConfigField "String", "SERVICE_THAT_I_NEED", getProps("service_secret_key")
buildConfigField "String", "MY_BACKEND_URL", getProps("my_url")
//use in xml, like AndroidManifest.xml
resValue "string", "google_maps_key", getProps("google_maps_key")
@igor-brishkoski
igor-brishkoski / encrypt.sh
Last active January 2, 2018 22:53
Encrypt/Decrypt file
https://superuser.com/questions/370388/simple-built-in-way-to-encrypt-and-decrypt-a-file-on-a-mac-via-command-line
# encrypt file.txt to file.enc using 256-bit AES in CBC mode
openssl enc -aes-256-cbc -salt -in secrets.properties -out secrets.properties.enc
# the same, only the output is base64 encoded for, e.g., e-mail
openssl enc -aes-256-cbc -a -salt -in secrets.properties -out secrets.properties.enc
@igor-brishkoski
igor-brishkoski / store_in_one_place.java
Last active January 2, 2018 23:09
Store them in one place
//build.gradle
android{
...
productFlavors{
staging{
//use in java code
buildConfigField "String", "SERVICE_THAT_I_NEED", "s3cr3t_k3y_f0r_hackz0rz_staging"
buildConfigField "String", "MY_BACKEND_URL", "https://www.staging-example.com/api"
//use in xml, like AndroidManifest.xml
resValue "string", "google_maps_key", "5435651423234"
@igor-brishkoski
igor-brishkoski / hardoced_secrets.java
Last active January 2, 2018 21:17
Hardcoded secrets
...
//Creating an instance of some service that your app relays on,
//Twitter, Facebook, Google, etc
//This service costs money to use
return new ExpensiveServiceThatMyAppUses.Builder()
.initWithKey("s3cr3t_k3y_f0r_hackz0rz"); // DON'T HARDCODE THE VALUE
.someConfig(true)
.build();
...