Skip to content

Commit a2e6a93

Browse files
author
Blankj
committed
see 02/27 log
1 parent 267bd3d commit a2e6a93

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.2.3'
9+
classpath 'com.android.tools.build:gradle:2.3.0-rc1'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
1212
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Mon Feb 27 13:02:08 CST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

utilcode/src/main/java/com/blankj/utilcode/utils/EncryptUtils.java

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
import javax.crypto.Mac;
1414
import javax.crypto.spec.SecretKeySpec;
1515

16-
import static com.blankj.utilcode.utils.ConvertUtils.bytes2HexString;
17-
import static com.blankj.utilcode.utils.ConvertUtils.hexString2Bytes;
18-
1916
/**
2017
* <pre>
2118
* author: Blankj
@@ -816,4 +813,66 @@ public static byte[] desTemplate(byte[] data, byte[] key, String algorithm, Stri
816813
return null;
817814
}
818815
}
816+
817+
private static final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
818+
819+
/**
820+
* byteArr转hexString
821+
* <p>例如:</p>
822+
* bytes2HexString(new byte[] { 0, (byte) 0xa8 }) returns 00A8
823+
*
824+
* @param bytes 字节数组
825+
* @return 16进制大写字符串
826+
*/
827+
private static String bytes2HexString(byte[] bytes) {
828+
if (bytes == null) return null;
829+
int len = bytes.length;
830+
if (len <= 0) return null;
831+
char[] ret = new char[len << 1];
832+
for (int i = 0, j = 0; i < len; i++) {
833+
ret[j++] = hexDigits[bytes[i] >>> 4 & 0x0f];
834+
ret[j++] = hexDigits[bytes[i] & 0x0f];
835+
}
836+
return new String(ret);
837+
}
838+
839+
840+
/**
841+
* hexString转byteArr
842+
* <p>例如:</p>
843+
* hexString2Bytes("00A8") returns { 0, (byte) 0xA8 }
844+
*
845+
* @param hexString 十六进制字符串
846+
* @return 字节数组
847+
*/
848+
private static byte[] hexString2Bytes(String hexString) {
849+
if (StringUtils.isSpace(hexString)) return null;
850+
int len = hexString.length();
851+
if (len % 2 != 0) {
852+
hexString = "0" + hexString;
853+
len = len + 1;
854+
}
855+
char[] hexBytes = hexString.toUpperCase().toCharArray();
856+
byte[] ret = new byte[len >> 1];
857+
for (int i = 0; i < len; i += 2) {
858+
ret[i >> 1] = (byte) (hex2Dec(hexBytes[i]) << 4 | hex2Dec(hexBytes[i + 1]));
859+
}
860+
return ret;
861+
}
862+
863+
/**
864+
* hexChar转int
865+
*
866+
* @param hexChar hex单个字节
867+
* @return 0..15
868+
*/
869+
private static int hex2Dec(char hexChar) {
870+
if (hexChar >= '0' && hexChar <= '9') {
871+
return hexChar - '0';
872+
} else if (hexChar >= 'A' && hexChar <= 'F') {
873+
return hexChar - 'A' + 10;
874+
} else {
875+
throw new IllegalArgumentException();
876+
}
877+
}
819878
}

0 commit comments

Comments
 (0)