From 09fdc1f7ec8334579ecf05d70ff7b69709654a55 Mon Sep 17 00:00:00 2001 From: orhanobut Date: Sat, 30 May 2015 12:43:02 +0200 Subject: [PATCH] v1.13 - more improvement --- README.md | 6 +++--- gradle.properties | 4 ++-- .../java/com/orhanobut/hawk/HawkTest.java | 3 +++ .../java/com/orhanobut/hawk/AesEncryption.java | 16 ++++++---------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3bcac79..1e477b1 100644 --- a/README.md +++ b/README.md @@ -17,17 +17,17 @@ Hawk provides: ###Add dependency ```groovy -compile 'com.orhanobut:hawk:1.12' +compile 'com.orhanobut:hawk:1.13' ``` #### Initialize the hawk ```java -Hawk.init(context, PASSWORD); +Hawk.init(context, PASSWORD); // might take 200ms ``` if you don't put any password, it will use another approach, it is faster but less secure. ```java -Hawk.init(context); +Hawk.init(context); // very fast ``` init takes 200-400ms depends on the device. You may want to use async solution in order to avoid this. Add a callback to init and it will work asynchronous. diff --git a/gradle.properties b/gradle.properties index 3dcf163..7479056 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,8 +19,8 @@ # VERSION_NAME=1.10-SNAPSHOT # VERSION_CODE=11 -VERSION_NAME=1.12 -VERSION_CODE=13 +VERSION_NAME=1.13 +VERSION_CODE=14 GROUP=com.orhanobut POM_DESCRIPTION=Secure, Advanced Storage for android diff --git a/hawk/src/androidTest/java/com/orhanobut/hawk/HawkTest.java b/hawk/src/androidTest/java/com/orhanobut/hawk/HawkTest.java index f5c21f5..2afb5f8 100644 --- a/hawk/src/androidTest/java/com/orhanobut/hawk/HawkTest.java +++ b/hawk/src/androidTest/java/com/orhanobut/hawk/HawkTest.java @@ -325,6 +325,7 @@ public void testNullValuePut() { } public void testCount() { + Hawk.clear(); String value = "test"; Hawk.put("tag", value); Hawk.put("tag1", value); @@ -349,6 +350,7 @@ public void testClear() { } public void testRemove() { + Hawk.clear(); String value = "test"; Hawk.put("tag", value); Hawk.put("tag1", value); @@ -363,6 +365,7 @@ public void testRemove() { } public void testBulkRemoval() { + Hawk.clear(); Hawk.put("tag", "test"); Hawk.put("tag1", 1); Hawk.put("tag2", Boolean.FALSE); diff --git a/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java b/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java index 770d43f..e380d8d 100644 --- a/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java +++ b/hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java @@ -31,13 +31,8 @@ final class AesEncryption implements Encryption { public boolean init() { this.saltKey = storage.get(KEY_STORAGE_SALT); - try { - generateSecretKey(password); - return true; - } catch (GeneralSecurityException e) { - Logger.w("Encryption is not supported in this device"); - return false; - } + key = generateSecretKey(password); + return key != null; } @Override @@ -90,10 +85,10 @@ private AesCbcWithIntegrity.CipherTextIvMac getCipherTextIvMac(String cipherText * Some phones especially Samsung(I hate Samsung) do not support every algorithm. If it is not * supported, it will fall generate the key without password and store it. */ - private void generateSecretKey(String password) throws GeneralSecurityException { + private AesCbcWithIntegrity.SecretKeys generateSecretKey(String password) { + AesCbcWithIntegrity.SecretKeys key; if (password == null || storage.contains(KEY_GENERATED_SECRET_KEYS)) { - key = getSecretKeysWithoutPassword(); - return; + return getSecretKeysWithoutPassword(); } key = generateSecretKeyFromPassword(password); @@ -102,6 +97,7 @@ private void generateSecretKey(String password) throws GeneralSecurityException } else { Logger.w("key is generated from password"); } + return key; } private AesCbcWithIntegrity.SecretKeys getSecretKeysWithoutPassword() {