Skip to content

Commit

Permalink
Merge pull request #43 from orhanobut/oo/key-generation
Browse files Browse the repository at this point in the history
v1.13 - more improvement
  • Loading branch information
orhanobut committed May 30, 2015
2 parents 6d1c8aa + 09fdc1f commit 1e83b65
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hawk/src/androidTest/java/com/orhanobut/hawk/HawkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void testNullValuePut() {
}

public void testCount() {
Hawk.clear();
String value = "test";
Hawk.put("tag", value);
Hawk.put("tag1", value);
Expand All @@ -349,6 +350,7 @@ public void testClear() {
}

public void testRemove() {
Hawk.clear();
String value = "test";
Hawk.put("tag", value);
Hawk.put("tag1", value);
Expand All @@ -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);
Expand Down
16 changes: 6 additions & 10 deletions hawk/src/main/java/com/orhanobut/hawk/AesEncryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand Down

0 comments on commit 1e83b65

Please sign in to comment.