Skip to content

Commit

Permalink
v1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanobut committed May 30, 2015
1 parent 1e83b65 commit 23b4aab
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Hawk provides:

###Add dependency
```groovy
compile 'com.orhanobut:hawk:1.13'
compile 'com.orhanobut:hawk:1.14'
```

#### Initialize the hawk
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.13
VERSION_CODE=14
VERSION_NAME=1.14
VERSION_CODE=15
GROUP=com.orhanobut

POM_DESCRIPTION=Secure, Advanced Storage for android
Expand Down
20 changes: 20 additions & 0 deletions hawk/src/main/java/com/orhanobut/hawk/DataUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.orhanobut.hawk;

import android.util.Base64;

import java.io.Serializable;

/**
Expand Down Expand Up @@ -75,5 +77,23 @@ static String addTypeAsList(String cipherText, Class clazz) {
return className + TYPE_LIST + FLAG_NON_SERIALIZABLE + DELIMITER + cipherText;
}

static String encodeBase64(byte[] bytes) {
try {
return Base64.encodeToString(bytes, Base64.DEFAULT);
} catch (Exception e) {
Logger.w(e.getMessage());
return null;
}
}

static byte[] decodeBase64(String value) {
try {
return Base64.decode(value, Base64.DEFAULT);
} catch (Exception e) {
Logger.w(e.getMessage());
return null;
}
}


}
9 changes: 7 additions & 2 deletions hawk/src/main/java/com/orhanobut/hawk/Hawk.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private static <T> String encode(List<T> list) {
String cipherText;

if (noEncryption) {
cipherText = Base64.encodeToString(encodedValue, Base64.DEFAULT);
cipherText = DataUtil.encodeBase64(encodedValue);
} else {
cipherText = encryption.encrypt(encodedValue);
}
Expand Down Expand Up @@ -269,10 +269,15 @@ public static <T> T get(String key) {
byte[] bytes;

if (noEncryption) {
bytes = Base64.decode(dataInfo.getCipherText(), Base64.DEFAULT);
bytes = DataUtil.decodeBase64(dataInfo.getCipherText());
} else {
bytes = encryption.decrypt(dataInfo.getCipherText());
}

if (bytes == null) {
return null;
}

try {
return encoder.decode(bytes, dataInfo);
} catch (Exception e) {
Expand Down

0 comments on commit 23b4aab

Please sign in to comment.