Skip to content

Commit 877bbc4

Browse files
committed
see 12/28 log
1 parent c8274ae commit 877bbc4

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

utilcode/lib/src/main/java/com/blankj/utilcode/util/EncryptUtils.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import javax.crypto.IllegalBlockSizeException;
2222
import javax.crypto.Mac;
2323
import javax.crypto.NoSuchPaddingException;
24+
import javax.crypto.SecretKey;
25+
import javax.crypto.SecretKeyFactory;
26+
import javax.crypto.spec.DESKeySpec;
2427
import javax.crypto.spec.IvParameterSpec;
2528
import javax.crypto.spec.SecretKeySpec;
2629

@@ -942,13 +945,20 @@ private static byte[] symmetricTemplate(final byte[] data,
942945
final boolean isEncrypt) {
943946
if (data == null || data.length == 0 || key == null || key.length == 0) return null;
944947
try {
945-
SecretKeySpec keySpec = new SecretKeySpec(key, algorithm);
948+
SecretKey secretKey;
949+
if ("DES".equals(algorithm)) {
950+
DESKeySpec desKey = new DESKeySpec(key);
951+
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
952+
secretKey = keyFactory.generateSecret(desKey);
953+
} else {
954+
secretKey = new SecretKeySpec(key, algorithm);
955+
}
946956
Cipher cipher = Cipher.getInstance(transformation);
947957
if (iv == null || iv.length == 0) {
948-
cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, keySpec);
958+
cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, secretKey);
949959
} else {
950960
AlgorithmParameterSpec params = new IvParameterSpec(iv);
951-
cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, keySpec, params);
961+
cipher.init(isEncrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, secretKey, params);
952962
}
953963
return cipher.doFinal(data);
954964
} catch (Throwable e) {

utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ private static String formatObject(Object object) {
348348
}
349349
}
350350
if (object.getClass().isArray()) return LogFormatter.array2String(object);
351+
if (object instanceof Map) return LogFormatter.map2String((Map) object);
352+
if (object instanceof Collection) return LogFormatter.collection2String((Collection) object);
351353
if (object instanceof Throwable) return LogFormatter.throwable2String((Throwable) object);
352354
if (object instanceof Bundle) return LogFormatter.bundle2String((Bundle) object);
353355
if (object instanceof Intent) return LogFormatter.intent2String((Intent) object);
354-
if (object instanceof Map) return LogFormatter.map2String((Map) object);
355-
if (object instanceof Collection) return LogFormatter.collection2String((Collection) object);
356356
return LogFormatter.object2String(object);
357357
}
358358

@@ -992,22 +992,22 @@ static String intent2String(Intent intent) {
992992

993993
static String map2String(Map map) {
994994
JSONObject jsonObject = new JSONObject(map);
995-
return jsonObject.toString();
995+
return LogFormatter.formatJson(jsonObject.toString());
996996
}
997997

998998
static String collection2String(Collection collection) {
999999
JSONObject jsonObject = new JSONObject();
10001000
try {
10011001
jsonObject.put("size", collection.size());
10021002
jsonObject.put("data", collection);
1003-
return jsonObject.toString();
1003+
return LogFormatter.formatJson(jsonObject.toString());
10041004
} catch (JSONException ignore) {
10051005
return collection.toString();
10061006
}
10071007
}
10081008

10091009
static String object2String(Object object) {
1010-
if (object instanceof String || object instanceof JSONObject ||
1010+
if (object instanceof CharSequence || object instanceof JSONObject ||
10111011
object instanceof JSONArray) {
10121012
return object.toString();
10131013
}
@@ -1039,7 +1039,7 @@ static String object2String(Object object) {
10391039
}
10401040
} catch (Exception ignore) {
10411041
}
1042-
return jsonObject.toString();
1042+
return LogFormatter.formatJson(jsonObject.toString());
10431043
}
10441044

10451045
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/log/LogActivity.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import android.widget.TextView;
1212

1313
import com.blankj.lib.base.BaseApplication;
14+
import com.blankj.lib.base.BaseBackActivity;
1415
import com.blankj.utilcode.pkg.Config;
1516
import com.blankj.utilcode.pkg.R;
16-
import com.blankj.lib.base.BaseBackActivity;
1717
import com.blankj.utilcode.util.LogUtils;
1818

1919
import java.util.ArrayList;
20+
import java.util.HashMap;
21+
import java.util.Map;
2022

2123

2224
/**
@@ -41,14 +43,16 @@ public class LogActivity extends BaseBackActivity {
4143
private static final int UPDATE_CONSOLE_FILTER = 0x01 << 8;
4244
private static final int UPDATE_FILE_FILTER = 0x01 << 9;
4345

44-
private static final String JSON = "{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"JSON format\" , \"site\":\"http://tools.w3cschool.cn/code/JSON\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}";
45-
private static final String XML = "<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>";
46-
private static final int[] ONE_D_ARRAY = new int[]{1, 2, 3};
47-
private static final int[][] TWO_D_ARRAY = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
48-
private static final Throwable THROWABLE = new NullPointerException();
49-
private static final Bundle BUNDLE = new Bundle();
50-
private static final Intent INTENT = new Intent();
51-
private static final ArrayList<String> LIST = new ArrayList<>();
46+
private static final String JSON = "{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"JSON format\" , \"site\":\"http://tools.w3cschool.cn/code/JSON\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}";
47+
private static final String XML = "<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>";
48+
private static final int[] ONE_D_ARRAY = new int[]{1, 2, 3};
49+
private static final int[][] TWO_D_ARRAY = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
50+
private static final Throwable THROWABLE = new NullPointerException();
51+
private static final Bundle BUNDLE = new Bundle();
52+
private static final Intent INTENT = new Intent();
53+
private static final ArrayList<String> LIST = new ArrayList<>();
54+
private static final Map<String, String> MAP = new HashMap<>();
55+
private static final Object OBJECT = new Config();
5256

5357
private static final String LONG_STR;
5458

@@ -95,6 +99,9 @@ public class LogActivity extends BaseBackActivity {
9599
LIST.add("hello");
96100
LIST.add("log");
97101
LIST.add("utils");
102+
103+
MAP.put("name", "AndroidUtilCode");
104+
MAP.put("class", "LogUtils");
98105
}
99106

100107
private TextView tvAboutLog;
@@ -169,6 +176,8 @@ public void initView(Bundle savedInstanceState, View contentView) {
169176
findViewById(R.id.btn_log_bundle).setOnClickListener(this);
170177
findViewById(R.id.btn_log_intent).setOnClickListener(this);
171178
findViewById(R.id.btn_log_array_list).setOnClickListener(this);
179+
findViewById(R.id.btn_log_map).setOnClickListener(this);
180+
findViewById(R.id.btn_log_object).setOnClickListener(this);
172181
updateConfig(0);
173182
}
174183

@@ -285,6 +294,12 @@ public void onWidgetClick(View view) {
285294
} else if (i1 == R.id.btn_log_array_list) {
286295
LogUtils.e(LIST);
287296

297+
} else if (i1 == R.id.btn_log_map) {
298+
LogUtils.e(MAP);
299+
300+
} else if (i1 == R.id.btn_log_object) {
301+
LogUtils.e(OBJECT);
302+
288303
}
289304
}
290305

utilcode/pkg/src/main/res/layout/activity_log.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,18 @@
181181
android:layout_height="wrap_content"
182182
android:text="@string/log_array_list" />
183183

184+
<Button
185+
android:id="@+id/btn_log_map"
186+
style="@style/WideBtnStyle"
187+
android:layout_width="match_parent"
188+
android:layout_height="wrap_content"
189+
android:text="@string/log_map" />
190+
191+
<Button
192+
android:id="@+id/btn_log_object"
193+
style="@style/WideBtnStyle"
194+
android:layout_width="match_parent"
195+
android:layout_height="wrap_content"
196+
android:text="@string/log_object" />
197+
184198
</LinearLayout>

utilcode/pkg/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
<string name="log_bundle">Log Bundle</string>
207207
<string name="log_intent">Log Intent</string>
208208
<string name="log_array_list">Log Array List</string>
209+
<string name="log_map">Log Map</string>
210+
<string name="log_object">Log Object</string>
209211

210212
<!--Permission 相关-->
211213
<string name="permission_open_app_settings">Open App Settings</string>

0 commit comments

Comments
 (0)