diff --git a/README.adoc b/README.adoc
new file mode 100644
index 0000000..e064b61
--- /dev/null
+++ b/README.adoc
@@ -0,0 +1,25 @@
+== Dew Common(Dew公共模块)
+
+=== 功能
+
+. Json与Java对象转换(JsonHelper)
+. Java Bean操作(BeanHelper)
+. Java Class扫描操作(ClassScanHelper)
+. Shell脚本操作(ShellHelper)
+. 加解密(EncryptHelper)
+. 响应处理模型(Resp)
+. 定时器(TimerHelper)
+. 常用时间处理(TimeHelper)
+. 主流文件MIME整理(MimeHelper)
+. 通用拦截器栈(DewInterceptorProcessor)
+
+=== 使用
+
+[source,xml]
+----
+
+ com.ecfront.dew
+ common
+ 1.0.0
+
+----
\ No newline at end of file
diff --git a/README.md b/README.md
deleted file mode 100644
index 85a3b8b..0000000
--- a/README.md
+++ /dev/null
@@ -1,24 +0,0 @@
-Dew Common
---
-Dew公共模块
-
-### 功能
-
-1. Json与Java对象转换(JsonHelper)
-1. Java Bean操作(BeanHelper)
-1. Java Class扫描操作(ClassScanHelper)
-1. Shell脚本操作(ShellHelper)
-1. 加解密(EncryptHelper)
-1. 响应处理模型(Resp)
-1. 定时器(TimerHelper)
-1. 常用时间处理(TimeHelper)
-1. 主流文件MIME整理(MimeHelper)
-1. 通用拦截器栈(DewInterceptorProcessor)
-
-### 使用
-
-
- com.ecfront.dew
- common
- 1.0.0-SNAPSHOT
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3daf3d3..183e100 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
common
Dew Common
jar
- 1.0.0-SNAPSHOT
+ 1.0.0
1.8
@@ -18,13 +18,12 @@
${java.version}
${java.version}
${java.version}
- 2.8.7
+ 2.8.8.1
1.9.3
- 0.3m
- 1.7.22
- 1.1.7
- 1.7.21
- 1.3
+ 0.4
+ 1.7.25
+ 1.2.3
+ 2.8.2
4.12
@@ -49,11 +48,6 @@
slf4j-api
${slf4j.version}
-
- pl.touk
- throwing-function
- ${throwing.version}
-
junit
junit
diff --git a/src/main/java/com/ecfront/dew/common/BeanHelper.java b/src/main/java/com/ecfront/dew/common/BeanHelper.java
index 47180d8..6ea0089 100644
--- a/src/main/java/com/ecfront/dew/common/BeanHelper.java
+++ b/src/main/java/com/ecfront/dew/common/BeanHelper.java
@@ -1,5 +1,7 @@
package com.ecfront.dew.common;
+import org.apache.commons.beanutils.BeanUtilsBean;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -228,4 +230,93 @@ private static String packageMethodNameByField(Field field, boolean isSet) {
}
}
+ public static class NullAwareBeanUtilsBean extends BeanUtilsBean {
+ @Override
+ public void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException {
+ if (null != value) {
+ super.copyProperty(bean, name, value);
+ }
+ }
+ }
+
+ public static class FieldInfo {
+
+ private String name;
+ private Class> type;
+ private Set annotations;
+ private Field field;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Class> getType() {
+ return type;
+ }
+
+ public void setType(Class> type) {
+ this.type = type;
+ }
+
+ public Set getAnnotations() {
+ return annotations;
+ }
+
+ public void setAnnotations(Set annotations) {
+ this.annotations = annotations;
+ }
+
+ public Field getField() {
+ return field;
+ }
+
+ public void setField(Field field) {
+ this.field = field;
+ }
+ }
+
+ public static class MethodInfo {
+
+ private String name;
+ private Class> returnType;
+ private Set annotations;
+ private Method method;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Class> getReturnType() {
+ return returnType;
+ }
+
+ public void setReturnType(Class> returnType) {
+ this.returnType = returnType;
+ }
+
+ public Set getAnnotations() {
+ return annotations;
+ }
+
+ public void setAnnotations(Set annotations) {
+ this.annotations = annotations;
+ }
+
+ public Method getMethod() {
+ return method;
+ }
+
+ public void setMethod(Method method) {
+ this.method = method;
+ }
+ }
+
}
diff --git a/src/main/java/com/ecfront/dew/common/ClassScanHelper.java b/src/main/java/com/ecfront/dew/common/ClassScanHelper.java
index 8b6da4f..2497ea5 100644
--- a/src/main/java/com/ecfront/dew/common/ClassScanHelper.java
+++ b/src/main/java/com/ecfront/dew/common/ClassScanHelper.java
@@ -7,7 +7,9 @@
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLDecoder;
-import java.util.*;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
diff --git a/src/main/java/com/ecfront/dew/common/EncryptHelper.java b/src/main/java/com/ecfront/dew/common/EncryptHelper.java
index 1fbd6d8..be58e57 100644
--- a/src/main/java/com/ecfront/dew/common/EncryptHelper.java
+++ b/src/main/java/com/ecfront/dew/common/EncryptHelper.java
@@ -6,6 +6,8 @@
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
@@ -153,13 +155,14 @@ public static PublicKey getPublicKey(String key, String algorithm) throws NoSuch
*
* @param data 要加密的数据
* @param key 公钥或私钥文件
+ * @param keyLength 密钥长度
* @param algorithm 非对称算法,如 RSA
* @return 加密后的数据
*/
- public static byte[] encrypt(byte[] data, Key key, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+ public static byte[] encrypt(byte[] data, Key key, int keyLength, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, key);
- return cipher.doFinal(data);
+ return packageCipher(data, cipher, keyLength / 8 - 11, data.length);
}
/**
@@ -167,13 +170,34 @@ public static byte[] encrypt(byte[] data, Key key, String algorithm) throws NoSu
*
* @param data 要解密的数据
* @param key 公钥或私钥文件
+ * @param keyLength 密钥长度
* @param algorithm 非对称算法,如 RSA
* @return 解密后的数据
*/
- public static byte[] decrypt(byte[] data, Key key, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+ public static byte[] decrypt(byte[] data, Key key, int keyLength, String algorithm) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException {
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, key);
- return cipher.doFinal(data);
+ return packageCipher(data, cipher, keyLength / 8, data.length);
+ }
+
+ private static byte[] packageCipher(byte[] data, Cipher cipher, int maxLength, int inputLength) throws IllegalBlockSizeException, BadPaddingException, IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ int offSet = 0;
+ byte[] cache;
+ int i = 0;
+ while (inputLength - offSet > 0) {
+ if (inputLength - offSet > maxLength) {
+ cache = cipher.doFinal(data, offSet, maxLength);
+ } else {
+ cache = cipher.doFinal(data, offSet, inputLength - offSet);
+ }
+ out.write(cache, 0, cache.length);
+ i++;
+ offSet = i * maxLength;
+ }
+ byte[] decryptedData = out.toByteArray();
+ out.close();
+ return decryptedData;
}
/**
diff --git a/src/main/java/com/ecfront/dew/common/FieldInfo.java b/src/main/java/com/ecfront/dew/common/FieldInfo.java
deleted file mode 100644
index c2e6371..0000000
--- a/src/main/java/com/ecfront/dew/common/FieldInfo.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.ecfront.dew.common;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.util.Set;
-
-public class FieldInfo {
-
- private String name;
- private Class> type;
- private Set annotations;
- private Field field;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Class> getType() {
- return type;
- }
-
- public void setType(Class> type) {
- this.type = type;
- }
-
- public Set getAnnotations() {
- return annotations;
- }
-
- public void setAnnotations(Set annotations) {
- this.annotations = annotations;
- }
-
- public Field getField() {
- return field;
- }
-
- public void setField(Field field) {
- this.field = field;
- }
-}
diff --git a/src/main/java/com/ecfront/dew/common/MethodInfo.java b/src/main/java/com/ecfront/dew/common/MethodInfo.java
deleted file mode 100644
index 9967281..0000000
--- a/src/main/java/com/ecfront/dew/common/MethodInfo.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.ecfront.dew.common;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.Set;
-
-public class MethodInfo {
-
- private String name;
- private Class> returnType;
- private Set annotations;
- private Method method;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Class> getReturnType() {
- return returnType;
- }
-
- public void setReturnType(Class> returnType) {
- this.returnType = returnType;
- }
-
- public Set getAnnotations() {
- return annotations;
- }
-
- public void setAnnotations(Set annotations) {
- this.annotations = annotations;
- }
-
- public Method getMethod() {
- return method;
- }
-
- public void setMethod(Method method) {
- this.method = method;
- }
-}
diff --git a/src/main/java/com/ecfront/dew/common/Mime.java b/src/main/java/com/ecfront/dew/common/Mime.java
deleted file mode 100644
index 8942615..0000000
--- a/src/main/java/com/ecfront/dew/common/Mime.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.ecfront.dew.common;
-
-public enum Mime {
- HTML1("text/html"),
- HTML2("application/html"),
- XML1("text/xml"),
- XML2("application/xml"),
- TXT("text/plain"),
- JS1("application/javascript"),
- JS2("application/x-javascript"),
- CSS("text/css"),
-
- DOC("application/msword"),
- DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
- XLS1("application/x-xls"),
- XLS2("application/vnd.ms-excel"),
- XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
- PPT1("application/x-ppt"),
- PPT2("application/vnd.ms-powerpoint"),
- PPTX("application/vnd.openxmlformats-officedocument.presentationml.presentation"),
- PDF("application/pdf"),
-
- ZIP1("application/zip"),
- ZIP2("application/x-zip-compressed"),
- ZIP3("application/x-compressed-zip"),
- GZIP("application/gzip"),
- SEVENZ1("application/x-7z-compressed"),
- SEVENZ2("application/octet-stream"),
- RAR1("application/rar"),
- RAR2("application/x-rar-compressed"),
-
- GIF("image/gif"),
- JPG1("image/jpeg"),
- JPG2("image/pjpeg"),
- PNG("image/png"),
- BMP1("application/x-bmp"),
- BMP2("image/bmp"),
-
- MP3("audio/mp3"),
- WAV1("audio/wav"),
- WAV2("audio/x-wav"),
- WMA("audio/x-ms-wma"),
-
- MP4("video/mpeg4"),
- MOV("video/quicktime"),
- AVI1("video/avi"),
- AVI2("video/x-msvideo"),
- AVI3("video/msvideo"),
- MOVIE("video/x-sgi-movie"),
- WEBM("audio/webm"),
- RM("audio/x-pn-realaudio"),
- RMVB("application/vnd.rn-realmedia-vbr");
-
- private String flag;
- Mime(String flag){
- this.flag=flag;
- }
-
- @Override
- public String toString() {
- return this.flag;
- }
-}
diff --git a/src/main/java/com/ecfront/dew/common/MimeHelper.java b/src/main/java/com/ecfront/dew/common/MimeHelper.java
index 4f124a1..c6c7842 100644
--- a/src/main/java/com/ecfront/dew/common/MimeHelper.java
+++ b/src/main/java/com/ecfront/dew/common/MimeHelper.java
@@ -67,4 +67,66 @@ public class MimeHelper {
public static final List TYPE_AUDIO = types.get("audio");
public static final List TYPE_VIDEO = types.get("video");
+ public enum Mime {
+ HTML1("text/html"),
+ HTML2("application/html"),
+ XML1("text/xml"),
+ XML2("application/xml"),
+ TXT("text/plain"),
+ JS1("application/javascript"),
+ JS2("application/x-javascript"),
+ CSS("text/css"),
+
+ DOC("application/msword"),
+ DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
+ XLS1("application/x-xls"),
+ XLS2("application/vnd.ms-excel"),
+ XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
+ PPT1("application/x-ppt"),
+ PPT2("application/vnd.ms-powerpoint"),
+ PPTX("application/vnd.openxmlformats-officedocument.presentationml.presentation"),
+ PDF("application/pdf"),
+
+ ZIP1("application/zip"),
+ ZIP2("application/x-zip-compressed"),
+ ZIP3("application/x-compressed-zip"),
+ GZIP("application/gzip"),
+ SEVENZ1("application/x-7z-compressed"),
+ SEVENZ2("application/octet-stream"),
+ RAR1("application/rar"),
+ RAR2("application/x-rar-compressed"),
+
+ GIF("image/gif"),
+ JPG1("image/jpeg"),
+ JPG2("image/pjpeg"),
+ PNG("image/png"),
+ BMP1("application/x-bmp"),
+ BMP2("image/bmp"),
+
+ MP3("audio/mp3"),
+ WAV1("audio/wav"),
+ WAV2("audio/x-wav"),
+ WMA("audio/x-ms-wma"),
+
+ MP4("video/mpeg4"),
+ MOV("video/quicktime"),
+ AVI1("video/avi"),
+ AVI2("video/x-msvideo"),
+ AVI3("video/msvideo"),
+ MOVIE("video/x-sgi-movie"),
+ WEBM("audio/webm"),
+ RM("audio/x-pn-realaudio"),
+ RMVB("application/vnd.rn-realmedia-vbr");
+
+ private String flag;
+ Mime(String flag){
+ this.flag=flag;
+ }
+
+ @Override
+ public String toString() {
+ return this.flag;
+ }
+ }
+
}
diff --git a/src/main/java/com/ecfront/dew/common/NullAwareBeanUtilsBean.java b/src/main/java/com/ecfront/dew/common/NullAwareBeanUtilsBean.java
deleted file mode 100644
index a01342a..0000000
--- a/src/main/java/com/ecfront/dew/common/NullAwareBeanUtilsBean.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.ecfront.dew.common;
-
-import org.apache.commons.beanutils.BeanUtilsBean;
-
-import java.lang.reflect.InvocationTargetException;
-
-public class NullAwareBeanUtilsBean extends BeanUtilsBean {
- @Override
- public void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException {
- if (null != value) {
- super.copyProperty(bean, name, value);
- }
- }
-}
diff --git a/src/main/java/com/ecfront/dew/common/Resp.java b/src/main/java/com/ecfront/dew/common/Resp.java
index 0c2f4b3..ad2e737 100644
--- a/src/main/java/com/ecfront/dew/common/Resp.java
+++ b/src/main/java/com/ecfront/dew/common/Resp.java
@@ -104,4 +104,8 @@ public static Resp customFail(String code, String message) {
return new Resp<>(code, message, null);
}
+ public static Resp customFail(Resp resp) {
+ return new Resp<>(resp.getCode(), resp.getMessage(), null);
+ }
+
}
diff --git a/src/main/java/com/ecfront/dew/common/ShellHelper.java b/src/main/java/com/ecfront/dew/common/ShellHelper.java
index f6e8193..e6da09b 100644
--- a/src/main/java/com/ecfront/dew/common/ShellHelper.java
+++ b/src/main/java/com/ecfront/dew/common/ShellHelper.java
@@ -16,6 +16,8 @@
*/
public class ShellHelper {
+ private static final Logger logger = LoggerFactory.getLogger(ShellHelper.class);
+
private volatile String taskId;
private volatile String successFlag;
private volatile String progressFlag;
@@ -53,21 +55,21 @@ public void execute(String shellPath, String taskId, String successFlag, String
//删除最后一行(\r\n)
reportHandler.complete(taskId, result.length() > 0 ? result.substring(0, result.length() - 2) : result.toString());
}
- LOGGER.debug("Execute Success: " + shellPath);
+ logger.debug("Execute Success: " + shellPath);
} else {
- LOGGER.warn("Execute fail: Not Find successFlag [" + successFlag + "], shellPath:" + shellPath);
+ logger.warn("Execute fail: Not Find successFlag [" + successFlag + "], shellPath:" + shellPath);
reportHandler.fail(taskId, "Not Find successFlag [" + successFlag + "], shellPath:" + shellPath);
}
} else {
- LOGGER.warn("Execute fail: Abnormal termination , shellPath:" + shellPath);
+ logger.warn("Execute fail: Abnormal termination , shellPath:" + shellPath);
reportHandler.fail(taskId, "Abnormal termination , shellPath:" + shellPath);
}
} else {
- LOGGER.warn("Execute fail: PID NOT exist , shellPath:" + shellPath);
+ logger.warn("Execute fail: PID NOT exist , shellPath:" + shellPath);
reportHandler.fail(taskId, "PID NOT exist , shellPath:" + shellPath);
}
} catch (Exception e) {
- LOGGER.error("Execute fail: ", e);
+ logger.error("Execute fail: ", e);
reportHandler.fail(taskId, e.getMessage() + " , shellPath:" + shellPath);
}
}
@@ -91,7 +93,7 @@ public Boolean call() {
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
- LOGGER.trace("Shell content:" + line);
+ logger.trace("Shell content:" + line);
if (returnResult) {
result.append(line).append("\r\n");
}
@@ -104,27 +106,27 @@ public Boolean call() {
}
}
} catch (IOException e) {
- LOGGER.warn("Execute fail: ", e);
+ logger.warn("Execute fail: ", e);
} finally {
if (br != null) {
try {
br.close();
} catch (Exception e) {
- LOGGER.warn("Execute warn: ", e);
+ logger.warn("Execute warn: ", e);
}
}
if (isr != null) {
try {
isr.close();
} catch (Exception e) {
- LOGGER.warn("Execute warn: ", e);
+ logger.warn("Execute warn: ", e);
}
}
if (is != null) {
try {
is.close();
} catch (Exception e) {
- LOGGER.warn("Execute warn: ", e);
+ logger.warn("Execute warn: ", e);
}
}
}
@@ -132,6 +134,4 @@ public Boolean call() {
}
}
- private static final Logger LOGGER = LoggerFactory.getLogger(ShellHelper.class);
-
}
diff --git a/src/test/java/com/ecfront/dew/common/BeanHelperTest.java b/src/test/java/com/ecfront/dew/common/BeanHelperTest.java
index 115ccbe..428276b 100644
--- a/src/test/java/com/ecfront/dew/common/BeanHelperTest.java
+++ b/src/test/java/com/ecfront/dew/common/BeanHelperTest.java
@@ -35,7 +35,7 @@ public void findClassAnnotation() throws Exception {
@Test
public void findFieldInfo() throws Exception {
- Map fieldsInfo= BeanHelper.findFieldsInfo(IdxController.class,null,null,null,null);
+ Map fieldsInfo= BeanHelper.findFieldsInfo(IdxController.class,null,null,null,null);
Assert.assertEquals(fieldsInfo.size(),2);
fieldsInfo=BeanHelper.findFieldsInfo(IdxController.class,null,new HashSet>(){{add(Deprecated.class);}},null,null);
Assert.assertEquals(fieldsInfo.size(),1);
@@ -49,7 +49,7 @@ public void findFieldInfo() throws Exception {
@Test
public void findMethodInfo() throws Exception {
- Set methodsInfo= BeanHelper.findMethodsInfo(IdxController.class,null,null,null,null);
+ Set methodsInfo= BeanHelper.findMethodsInfo(IdxController.class,null,null,null,null);
Assert.assertEquals(methodsInfo.size(),7);
methodsInfo=BeanHelper.findMethodsInfo(IdxController.class,null,new HashSet>(){{add(TestAnnotation.GET.class);}},null,null);
Assert.assertEquals(methodsInfo.size(),6);
diff --git a/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java b/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java
index a0fff96..bc51c6b 100644
--- a/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java
+++ b/src/test/java/com/ecfront/dew/common/EncryptHelperTest.java
@@ -22,18 +22,22 @@ public void asymmetric() throws Exception {
String privateStr = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALjt0CEssHfGENZxyASF6pNtGKYCGW43+LE3JhT8y8TE39vDK22GJZWJFXYfWwasavknIfepBIVrnuMidtcPqUY3bhrDZN+J6MtYaSPSEwRcS2PgF/065CEdSbLy6cvKA64GUiG188un1xIsGBVUdu3fdu41OQvt+90TZT0HclXJAgMBAAECgYEAjXFndVhHCPU3P637PGppBqW06pREeybYUkNKH1dTS4cBaYcXmke2S290OMq2xp3tm++wbUqbKKkt97AOkWNrJfq8Ecpdw9s3c7yQGWaPuwiX38Cgtq6r0utjT20YgR6etGpqafoBt93RZpEm0eEzFPUnS7qYc86HprL0RJ0/i7kCQQDaOmvO82cYIK1ESkA0GdDVQoz2A1V8HvEWOsccRGqlWuasLUccyBnx1G/LDZUxcPOraDyxI8sdl7VbweLR0H9LAkEA2O/rWXwnSYKqdpt+OhpUBHNnMs3IMvRzefJ1zObnIMyYR3KXtpQ/fL4gEquNwJgFIaPJVg5/3zHISEw3e8XOuwJAIDrGl07tZ+vTiyVoLAmwBP8KMH83jdhIBN9zbqJQGdG+Bam+Oer3ofac+CEuapni8uq3I/ZEVj+EomOVKyWe1wJAATztROd2ee7q9h5RDBfWXughsKKH//JxLkL59R9kNkW0oMPApeQWsKmNGU4tUuoLLXP31CvlAusPz4nPzz8DvQJBAJXpICPNJw84fONzS0raRqlFoZMMI0cqeGtPIiCHKaRHyzQv/FFu2KxUcCrod8PngaBFRselzrwZILmXHqrHc1M=";
String publicStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC47dAhLLB3xhDWccgEheqTbRimAhluN/ixNyYU/MvExN/bwytthiWViRV2H1sGrGr5JyH3qQSFa57jInbXD6lGN24aw2TfiejLWGkj0hMEXEtj4Bf9OuQhHUmy8unLygOuBlIhtfPLp9cSLBgVVHbt33buNTkL7fvdE2U9B3JVyQIDAQAB";
+ String d="Scala是一门多范式的编程语言,一种类似java的编程语言[1] ,设计初衷是实现可伸缩的语言[2] 、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1] ,设计初衷是实现可伸缩的语言[2] 、并集成面向对象编程和函数式编程的各种特性。Scala是一门多范式的编程语言,一种类似java的编程语言[1] ,设计初衷是实现可伸缩的语言[2] 、并集成面向对象编程和函数式编程的各种特性。";
+ // 生成公钥密钥
Map keys = EncryptHelper.Asymmetric.generateKeys("RSA", 1024, "UTF-8");
PublicKey publicKey = EncryptHelper.Asymmetric.getPublicKey(publicStr, "RSA");
PrivateKey privateKey = EncryptHelper.Asymmetric.getPrivateKey(privateStr, "RSA");
- byte[] encryptByPub = EncryptHelper.Asymmetric.encrypt("好的了".getBytes("UTF-8"), publicKey, "RSA");
- String result = new String(EncryptHelper.Asymmetric.decrypt(encryptByPub, privateKey, "RSA"), "UTF-8");
- Assert.assertTrue(Objects.equals(result, "好的了"));
+ // 公钥加密/私钥解密
+ byte[] encryptByPub = EncryptHelper.Asymmetric.encrypt(d.getBytes("UTF-8"), publicKey, 1024,"RSA");
+ String result = new String(EncryptHelper.Asymmetric.decrypt(encryptByPub, privateKey,1024, "RSA"), "UTF-8");
+ Assert.assertTrue(Objects.equals(result, d));
- byte[] encryptByPriv = EncryptHelper.Asymmetric.encrypt("好的了".getBytes("UTF-8"), privateKey, "RSA");
- byte[] decryptByPub = EncryptHelper.Asymmetric.decrypt(encryptByPriv, publicKey, "RSA");
- Assert.assertTrue(Objects.equals(new String(decryptByPub, "UTF-8"), "好的了"));
- Assert.assertTrue(EncryptHelper.Asymmetric.verify(publicKey, decryptByPub, EncryptHelper.Asymmetric.sign(privateKey, "好的了".getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA"));
+ // 私钥加密/公钥解密
+ byte[] encryptByPriv = EncryptHelper.Asymmetric.encrypt(d.getBytes("UTF-8"), privateKey,1024, "RSA");
+ byte[] decryptByPub = EncryptHelper.Asymmetric.decrypt(encryptByPriv, publicKey,1024, "RSA");
+ Assert.assertTrue(Objects.equals(new String(decryptByPub, "UTF-8"), d));
+ Assert.assertTrue(EncryptHelper.Asymmetric.verify(publicKey, decryptByPub, EncryptHelper.Asymmetric.sign(privateKey, d.getBytes("UTF-8"), "SHA1withRSA"), "SHA1withRSA"));
}
}
\ No newline at end of file
diff --git a/src/test/java/com/ecfront/dew/common/JsonHelperTest.java b/src/test/java/com/ecfront/dew/common/JsonHelperTest.java
index 1999064..6d8ad25 100644
--- a/src/test/java/com/ecfront/dew/common/JsonHelperTest.java
+++ b/src/test/java/com/ecfront/dew/common/JsonHelperTest.java
@@ -28,7 +28,7 @@ public void toList() throws Exception {
Assert.assertEquals(model.getName(), "sunisle");
Assert.assertEquals(model.getCid(), "1");
Assert.assertEquals(model.getCreateTime(), "123456789");
- Assert.assertEquals(df.format(model.getDate()),"2016-07-12 12:00:00");
+ Assert.assertEquals(df.format(model.getDate()), "2016-07-12 12:00:00");
}
@Test
@@ -37,7 +37,7 @@ public void toObject() throws Exception {
Assert.assertEquals(model.getName(), "sunisle");
Assert.assertEquals(model.getCid(), "1");
Assert.assertEquals(model.getCreateTime(), "123456789");
- Assert.assertEquals(df.format(model.getDate()),"2016-07-12 12:00:00");
+ Assert.assertEquals(df.format(model.getDate()), "2016-07-12 12:00:00");
}
}
\ No newline at end of file