Skip to content

Commit e8987ff

Browse files
committed
fix constant
1 parent 95e7f9d commit e8987ff

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

library/src/main/java/com/zeroone/conceal/CipherUtils.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import javax.crypto.spec.IvParameterSpec;
1010
import javax.crypto.spec.SecretKeySpec;
1111

12+
import static com.zeroone.conceal.model.Constant.UTF8;
13+
1214
/**
1315
* @author : hafiq on 29/03/2017.
1416
*/
@@ -33,7 +35,7 @@ static byte[] deObscureSixFour(byte[] cipher){
3335

3436
static String encode64WithIteration(String plaintext,int iteration){
3537
try {
36-
byte[] dataDec = plaintext.getBytes("UTF-8");
38+
byte[] dataDec = plaintext.getBytes(UTF8);
3739
for (int x=0;x<iteration;x++){
3840
dataDec = obscureEncodeSixFourBytes(dataDec);
3941
}
@@ -48,7 +50,7 @@ static String encode64WithIteration(String plaintext,int iteration){
4850

4951
static String decode64WithIteration(String plaintext,int iteration){
5052
try {
51-
byte[] dataDec = plaintext.getBytes("UTF-8");
53+
byte[] dataDec = plaintext.getBytes(UTF8);
5254
for (int x=0;x<iteration;x++){
5355
dataDec = deObscureSixFour(dataDec);
5456
}
@@ -90,18 +92,18 @@ static String AesCrypt(String key, String iv, String data) {
9092
}
9193

9294

93-
IvParameterSpec initVector = new IvParameterSpec(iv.getBytes("UTF-8"));
94-
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
95+
IvParameterSpec initVector = new IvParameterSpec(iv.getBytes(UTF8));
96+
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(UTF8), "AES");
9597

9698
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
9799
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, initVector);
98100

99101
byte[] encryptedData = cipher.doFinal((data.getBytes()));
100102

101103
String base64_EncryptedData = Base64.encodeToString(encryptedData, Base64.DEFAULT);
102-
String base64_IV = Base64.encodeToString(iv.getBytes("UTF-8"), Base64.DEFAULT);
104+
String base64_IV = Base64.encodeToString(iv.getBytes(UTF8), Base64.DEFAULT);
103105

104-
return Base64.encodeToString((base64_EncryptedData + ":" + base64_IV).getBytes("UTF-8"), Base64.DEFAULT);
106+
return Base64.encodeToString((base64_EncryptedData + ":" + base64_IV).getBytes(UTF8), Base64.DEFAULT);
105107

106108
} catch (Exception ex) {
107109
ex.printStackTrace();
@@ -130,7 +132,7 @@ static String AesDecrypt(String key, String data) {
130132
String[] parts = new String(Base64.decode(data, Base64.DEFAULT)).split(":");
131133

132134
IvParameterSpec iv = new IvParameterSpec(Base64.decode(parts[1], Base64.DEFAULT));
133-
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
135+
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(UTF8), "AES");
134136

135137
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
136138
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);

library/src/main/java/com/zeroone/conceal/ConcealPrefRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ public void commit() {
727727

728728
public static class UserPref<T>{
729729

730-
731730
private String PREFIX = "conceal";
732731
private String DEFAULT_VALUE = null;
733732
private String SEPARATOR = "_";

library/src/main/java/com/zeroone/conceal/ConverterListUtils.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import java.util.List;
99
import java.util.Map;
1010

11+
import static com.zeroone.conceal.model.Constant.UTF8;
12+
1113
/**
1214
* @author : hafiq on 23/03/2017.
1315
*/
1416

1517
class ConverterListUtils {
1618

1719
static List<Integer> toIntArray(String string) {
18-
String[] strings = string.replace("[", "").replace("]", "").split(", ");
20+
String[] strings = getArray(string);
1921
Integer result[] = new Integer[strings.length];
2022
try {
2123
for (int i = 0; i < result.length; i++) {
@@ -29,7 +31,7 @@ static List<Integer> toIntArray(String string) {
2931
}
3032

3133
static List<Boolean> toBooleanArray(String string) {
32-
String[] strings = string.replace("[", "").replace("]", "").split(", ");
34+
String[] strings = getArray(string);
3335
Boolean result[] = new Boolean[strings.length];
3436
try {
3537
for (int i = 0; i < result.length; i++) {
@@ -43,7 +45,7 @@ static List<Boolean> toBooleanArray(String string) {
4345
}
4446

4547
static List<Long> toLongArray(String string) {
46-
String[] strings = string.replace("[", "").replace("]", "").split(", ");
48+
String[] strings = getArray(string);
4749
Long result[] = new Long[strings.length];
4850
try {
4951
for (int i = 0; i < result.length; i++) {
@@ -58,7 +60,7 @@ static List<Long> toLongArray(String string) {
5860
}
5961

6062
static List<Double> toDoubleArray(String string) {
61-
String[] strings = string.replace("[", "").replace("]", "").split(", ");
63+
String[] strings = getArray(string);
6264
Double result[] = new Double[strings.length];
6365
try {
6466
for (int i = 0; i < result.length; i++) {
@@ -73,7 +75,7 @@ static List<Double> toDoubleArray(String string) {
7375
}
7476

7577
static List<Float> toFloatArray(String string) {
76-
String[] strings = string.replace("[", "").replace("]", "").split(", ");
78+
String[] strings = getArray(string);
7779
Float result[] = new Float[strings.length];
7880
try {
7981
for (int i = 0; i < result.length; i++) {
@@ -87,7 +89,11 @@ static List<Float> toFloatArray(String string) {
8789
}
8890

8991
static List<String> toStringArray(String string) {
90-
return Arrays.asList(string.replace("[", "").replace("]", "").split(", "));
92+
return Arrays.asList(getArray(string));
93+
}
94+
95+
static String[] getArray(String string) {
96+
return string.replace("[", "").replace("]", "").split(", ");
9197
}
9298

9399

@@ -100,9 +106,9 @@ static String convertMapToString(Map<String,String> maps){
100106
}
101107
String value = maps.get(key);
102108
try {
103-
stringBuilder.append((key != null ? URLEncoder.encode(key, "UTF-8") : ""));
109+
stringBuilder.append((key != null ? URLEncoder.encode(key, UTF8) : ""));
104110
stringBuilder.append("=");
105-
stringBuilder.append(value != null ? URLEncoder.encode(value, "UTF-8") : "");
111+
stringBuilder.append(value != null ? URLEncoder.encode(value, UTF8) : "");
106112
} catch (UnsupportedEncodingException e) {
107113
throw new RuntimeException("This method requires UTF-8 encoding support", e);
108114
}
@@ -118,7 +124,7 @@ static LinkedHashMap<String,String> convertStringToMap(String input){
118124
for (String nameValuePair : nameValuePairs) {
119125
String[] nameValue = nameValuePair.split("=");
120126
try {
121-
map.put(URLDecoder.decode(nameValue[0], "UTF-8"), nameValue.length > 1 ? URLDecoder.decode(nameValue[1], "UTF-8") : "");
127+
map.put(URLDecoder.decode(nameValue[0], UTF8), nameValue.length > 1 ? URLDecoder.decode(nameValue[1], UTF8) : "");
122128
} catch (UnsupportedEncodingException e) {
123129
throw new RuntimeException("This method requires UTF-8 encoding support", e);
124130
}

library/src/main/java/com/zeroone/conceal/FileUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static File moveFile(File file, File dir){
5757
static boolean saveBitmap(File imageFile, Bitmap bitmap) {
5858

5959
boolean fileCreated = false;
60-
boolean bitmapCompressed = false;
60+
boolean bitmapCompressed;
6161
boolean streamClosed = false;
6262

6363
if (imageFile.exists())

library/src/main/java/com/zeroone/conceal/model/Constant.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
public class Constant {
1010

11+
12+
public static final String UTF8 = "UTF-8";
13+
14+
1115
public static final String DEFAULT_DIRECTORY = Environment.getExternalStorageDirectory()+"/.";
1216
public static final String DEFAULT_FILES_FOLDER = "files";
1317
public static final String DEFAULT_IMAGE_FOLDER = "images";

0 commit comments

Comments
 (0)