Skip to content

Instantly share code, notes, and snippets.

@aogilvie
aogilvie / string_encrypt_decrypt.md
Created August 19, 2013 08:52
Quick and sexy String encrypt / decrypt for Android

#Quick and sexy String encrypt / decrypt for Android

Sometimes you find yourself wanted to use SharedPrefs to hold something precious? Want to prevent those pesky rooted hackz0rs from looking in your SharedPreds? Here is a quick and sexy no-external-libs-required solution.

Notes;

  • I have declared everything static so you can create your own utility class and throw the following straight in.

  • 3rd party imports are not required. Use import android.util.Base64; for Base64, and import javax.crypto.*; for Cipher.

@aogilvie
aogilvie / gist:5625088
Last active December 17, 2015 14:29
HttpUriRequest and HttpPut, sending a payload String with multilingual characters.

A Java String doesn't have an encoding but it can easily be forced into UTF-16 on conversions. ALWAYS specify UTF-8 when creating a new StringEntity from String!

Add payload to HttpPut
HttpPut hp = (HttpPut) this.request;
hp.setEntity(new StringEntity(yourStringPayload, "UTF-8"));
hp.setHeader("Content-Type", "application/json");
// ... then execute