Skip to content

Commit

Permalink
Upgraded dependancy to core crypto library which now allows custom it…
Browse files Browse the repository at this point in the history
…eration counts, meaning you can make quicker but less secure keys. Added example method to sample project
  • Loading branch information
scottyab committed Jul 24, 2015
1 parent 832568a commit 925855b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
}

dependencies {
compile 'com.scottyab:aes-crypto:0.0.2'
compile 'com.scottyab:aes-crypto:0.0.3'
}


Expand Down
22 changes: 19 additions & 3 deletions sample/src/com/securepreferences/sample/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import android.app.Application;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;

import com.securepreferences.SecurePreferences;
import com.securepreferences.sample.utils.TickTock;
import com.tozny.crypto.android.AesCbcWithIntegrity;

import java.security.GeneralSecurityException;

Expand Down Expand Up @@ -36,16 +38,30 @@ public static App get() {
@DebugLog
public SharedPreferences getSharedPreferences() {
if(mSecurePrefs==null){
TickTock tickTock = new TickTock();
tickTock.tic();
mSecurePrefs = new SecurePreferences(this, "", "my_prefs.xml");
SecurePreferences.setLoggingEnabled(true);
Log.d(TAG, "SecurePreferences init time: " + TickTock.formatDuration(tickTock.toc()));
}
return mSecurePrefs;
}


/**
* This is just an example of how you might want to create your own key with less iterations 1,000 rather than default 10,000. This makes it quicker but less secure.
* @return
*/
@DebugLog
public SharedPreferences getSharedPreferences1000() {
try {
AesCbcWithIntegrity.SecretKeys myKey = AesCbcWithIntegrity.generateKeyFromPassword(Build.SERIAL,AesCbcWithIntegrity.generateSalt(),1000);
SharedPreferences securePrefs1000 = new SecurePreferences(this, myKey, "my_prefs_1000.xml");
return securePrefs1000;
} catch (GeneralSecurityException e) {
Log.e(TAG, "Failed to create custom key for SecurePreferences", e);
}
return null;
}


@DebugLog
public SecurePreferences getUserPinBasedSharedPreferences(String password){
if(mUserPrefs==null) {
Expand Down
2 changes: 2 additions & 0 deletions sample/src/com/securepreferences/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {

mSecurePrefs = App.get().getSharedPreferences();

App.get().getSharedPreferences1000();

updateEncValueDisplay();

mSecurePrefs
Expand Down

0 comments on commit 925855b

Please sign in to comment.