diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..5039140 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '19 22 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.gitignore b/.gitignore index 26498aa..143ba4a 100644 --- a/.gitignore +++ b/.gitignore @@ -41,5 +41,4 @@ hs_err_pid* .idea/ target/ *.iml -logs/ -.gitignore \ No newline at end of file +logs/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9031f2a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java + +java: + - 1.8 + +sudo: false + +install: + - mvn clean install \ No newline at end of file diff --git a/LICENSE b/LICENSE index 257fa5c..ce3f3d8 100644 --- a/LICENSE +++ b/LICENSE @@ -176,7 +176,7 @@ recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2017 siter + Copyright 2018 SeanDragon Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index b1862f8..b6167b8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,70 @@ -# pro.tools:protools:2.0 +# protools -# future -1 在面向对象思想上思考更多,多线程场景深入思考 \ No newline at end of file +[![Build Status](https://travis-ci.org/SeanDragon/protools.svg?branch=master)](https://travis-ci.org/SeanDragon/protools) +[![License](http://img.shields.io/:license-apache-blue.svg)](https://github.com/SeanDragon/protools/blob/master/LICENSE) +[![JDK 1.8](https://img.shields.io/badge/JDK-1.8-blue.svg)](#protools) + +[![GitHub Forks](https://img.shields.io/github/forks/SeanDragon/protools.svg?style=flat&label=Fork)](https://github.com/SeanDragon/protools/fork) +[![GitHub Watchers](https://img.shields.io/github/watchers/SeanDragon/protools.svg?style=flat&label=Watch)](https://github.com/SeanDragon/protools/watchers) + + + + + + + + + + + + + + + + + +
+ +[![Stargazers Over Time](https://starcharts.herokuapp.com/SeanDragon/protools.svg)](https://starcharts.herokuapp.com/SeanDragon/protools) + +历经开发周期两年,并且应用过千万级别项目的工具箱 + +大家如果想使用可以先执行 `mvn clean install` 即可在本地的其他 `maven` 项目中使用 + +## 开发计划 +- 使用阿里的规范手册整理规范所有代码 +- 将当时临时添加或欠缺考虑的命名或方法进行优化 +- 将maven私人仓库转移到中心仓库 +- 即将进行大升级,`Gradle` + `java module` + +## 目录 + +- [protools](#protools) + - [common](#common) + - [http](#http) + - [mail](#mail) + - [security](#common) + - [all](#all) + +### common +* 数据的处理 +* 文件的处理 +* script 引擎的封装 +* 系统方面查询的封装 +* 日期对象的封装DatePlus +* 数值对象的封装Decimal +### http +* 统一发送对象为HttpSend +* 统一接收对象为HttpReceive +* 三个版本的 http 客户端(Jdk、Netty 和 OkHttp) +### mail +* 封装 JavaMail,并采用了队列等方法提高性能,并简化了发送过程 +### security +* 封装了 jdk 和 bouncycastle 中几十种常见加密方式 +### all +* 如果需要使用上述多个模块,可以导入all模块以使用所有模块 + + +### 感谢 + - 感谢 **JetBrains** 对开源项目的支持
+![输入图片说明](https://images.gitee.com/uploads/images/2020/0714/114152_d335c2f1_416720.png "jetbrains.png") diff --git a/protools/pom.xml b/all/pom.xml similarity index 82% rename from protools/pom.xml rename to all/pom.xml index d0bc3a5..4cf618d 100644 --- a/protools/pom.xml +++ b/all/pom.xml @@ -3,13 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - parent + protools pro.tools - 2.0 + 3.0 4.0.0 - protools + all jar @@ -17,28 +17,32 @@ pro.tools http - 2.0 + ${project.version} pro.tools mail - 2.0 + ${project.version} pro.tools security - 2.0 + ${project.version} + + 1.4 + + org.apache.maven.plugins maven-shade-plugin - 1.4 + ${shade-plugin.version} package diff --git a/common/pom.xml b/common/pom.xml index 6455312..edfde99 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - parent + protools pro.tools - 2.0 + 3.0 4.0.0 @@ -16,55 +16,49 @@ org.slf4j slf4j-api - 1.7.9 + ${slf4j.version} com.google.guava guava - - 23.5-jre + ${guavav.version} - - - - - - org.google.code.gson + com.google.code.gson gson - 2.8.3 + ${gson.version} com.google.zxing javase - 3.3.1 + ${zxing.version} com.belerweb pinyin4j - 2.5.1 + ${pinyin4j.version} uk.com.robust-it cloning - 1.9.6 + ${cloning.version} de.ruedigermoeller fst - 2.56 + ${fst.version} objenesis @@ -77,7 +71,7 @@ com.github.junrar junrar - 0.7 + ${junrar.version} maven-scm-api @@ -95,4 +89,15 @@ + + 7.4.1 + 2.56 + 1.9.6 + 2.5.1 + 3.3.1 + 2.8.9 + 32.0.0-jre + 1.7.9 + + \ No newline at end of file diff --git a/common/src/main/java/pro/tools/constant/RegexConst.java b/common/src/main/java/pro/tools/constant/RegexConst.java index baa7ed3..8f92178 100644 --- a/common/src/main/java/pro/tools/constant/RegexConst.java +++ b/common/src/main/java/pro/tools/constant/RegexConst.java @@ -7,7 +7,8 @@ /** * 正则的常量 * - * @author SeanDragon Create By 2017-04-17 10:13 + * @author SeanDragon + * @date 2017-04-17 10:13 */ public final class RegexConst { @@ -114,7 +115,7 @@ public final class RegexConst { public static final Pattern REGEX_NEGATIVE_FLOAT = compile("^-[1-9]\\d*\\.\\d*|-0\\.\\d*[1-9]\\d*$"); private RegexConst() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } //endregion diff --git a/common/src/main/java/pro/tools/constant/StrConst.java b/common/src/main/java/pro/tools/constant/StrConst.java index af912af..c2570ce 100644 --- a/common/src/main/java/pro/tools/constant/StrConst.java +++ b/common/src/main/java/pro/tools/constant/StrConst.java @@ -12,7 +12,7 @@ public final class StrConst { private StrConst() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** diff --git a/common/src/main/java/pro/tools/constant/UnitConst.java b/common/src/main/java/pro/tools/constant/UnitConst.java index d7c0cbf..1545759 100644 --- a/common/src/main/java/pro/tools/constant/UnitConst.java +++ b/common/src/main/java/pro/tools/constant/UnitConst.java @@ -12,7 +12,7 @@ public final class UnitConst { private UnitConst() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } //region 存储相关常量 @@ -50,9 +50,21 @@ private UnitConst() { //endregion public enum MemoryUnit { + /** + * 字节 + */ BYTE, + /** + * KB + */ KB, + /** + * MB = 1024 * KB + */ MB, + /** + * GB = 1024 * MB + */ GB } diff --git a/common/src/main/java/pro/tools/data/ToolSerialize.java b/common/src/main/java/pro/tools/data/ToolSerialize.java index 7f0d20a..b0d4481 100644 --- a/common/src/main/java/pro/tools/data/ToolSerialize.java +++ b/common/src/main/java/pro/tools/data/ToolSerialize.java @@ -10,7 +10,7 @@ public final class ToolSerialize { private ToolSerialize() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } private static FSTConfiguration CONFIGURATION = FSTConfiguration diff --git a/common/src/main/java/pro/tools/data/decimal/Decimal.java b/common/src/main/java/pro/tools/data/decimal/Decimal.java index 7e5c1ca..0f13c2b 100644 --- a/common/src/main/java/pro/tools/data/decimal/Decimal.java +++ b/common/src/main/java/pro/tools/data/decimal/Decimal.java @@ -12,7 +12,8 @@ /** * 数值类型封装类 * - * @author SeanDragon Create By 2017-04-13 14:22 + * @author SeanDragon + * Create By 2017-04-13 14:22 */ public class Decimal extends Number implements Cloneable { @@ -50,6 +51,7 @@ public static void setDefaultMathContext(MathContext defaultMathContext) { * 便利生成方式,获取实例方法 * * @param initValue + * * @return */ public static Decimal instance(Object initValue) { @@ -111,7 +113,9 @@ public MathContext getMathContext() { /** * 获取该数被除后的整数 * - * @param object 因数 + * @param object + * 因数 + * * @return 结果 */ public Decimal getDivGetInteger(Object object) { @@ -121,7 +125,9 @@ public Decimal getDivGetInteger(Object object) { /** * 求余 * - * @param object 因数 + * @param object + * 因数 + * * @return 结果 */ public Decimal getRemainder(Object object) { @@ -135,6 +141,7 @@ public Decimal getRemainder(Object object) { * 基本数值运算:加法 * * @param object + * * @return */ public Decimal add(Object object) { @@ -146,6 +153,7 @@ public Decimal add(Object object) { * 减法 * * @param object + * * @return */ public Decimal sub(Object object) { @@ -157,6 +165,7 @@ public Decimal sub(Object object) { * 乘法 * * @param object + * * @return */ public Decimal mul(Object object) { @@ -168,6 +177,7 @@ public Decimal mul(Object object) { * 除法 * * @param object + * * @return */ public Decimal div(Object object) { @@ -191,7 +201,9 @@ public Decimal abs() { /** * 幂运算 * - * @param n 幂数 + * @param n + * 幂数 + * * @return 结果 */ public Decimal pow(int n) { @@ -202,7 +214,9 @@ public Decimal pow(int n) { /** * 开平方 * - * @param scale 精度 + * @param scale + * 精度 + * * @return 结果 */ public Decimal sqrt2(int scale) { @@ -221,7 +235,9 @@ public Decimal sqrt2(int scale) { /** * 开N次方 * - * @param n 几次方 + * @param n + * 几次方 + * * @return 结果 */ public Decimal sqrtN(int n) { @@ -229,9 +245,11 @@ public Decimal sqrtN(int n) { this.bigDecimal = new BigDecimal(log, mathContext); return this; } + //endregion //region 数据变现 + @Override public String toString() { return fullStrValue(); @@ -271,13 +289,11 @@ public double moneyValue() { @Override public int intValue() { return (int) doubleValue(); - //return this.bigDecimal.intValueExact(); } @Override public long longValue() { return (long) doubleValue(); - //return this.bigDecimal.longValueExact(); } @Override @@ -293,7 +309,9 @@ public double doubleValue() { /** * 传入进度和舍入原则进行double * - * @param scale 进度 + * @param scale + * 进度 + * * @return 结果 */ public double doubleValue(int scale) { @@ -303,14 +321,18 @@ public double doubleValue(int scale) { /** * 传入进度和舍入原则进行double * - * @param scale 进度 - * @param roundingMode 舍入原则 + * @param scale + * 进度 + * @param roundingMode + * 舍入原则 + * * @return 结果 */ public double doubleValue(int scale, RoundingMode roundingMode) { String strValue = this.fullStrValue(scale, roundingMode); return Double.valueOf(strValue); } + //endregion diff --git a/common/src/main/java/pro/tools/data/decimal/ToolDecimal.java b/common/src/main/java/pro/tools/data/decimal/ToolDecimal.java index 1eba063..79709c4 100644 --- a/common/src/main/java/pro/tools/data/decimal/ToolDecimal.java +++ b/common/src/main/java/pro/tools/data/decimal/ToolDecimal.java @@ -17,7 +17,7 @@ public final class ToolDecimal { private ToolDecimal() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } private final static BigInteger HUNDRED = BigInteger.valueOf(100); @@ -25,9 +25,13 @@ private ToolDecimal() { /** * 自己实现的开平方 * - * @param number 数值 - * @param scale 精度 - * @param roundingMode 舍入方法 + * @param number + * 数值 + * @param scale + * 精度 + * @param roundingMode + * 舍入方法 + * * @return 结果 */ static BigDecimal sqrt(BigDecimal number, int scale, RoundingMode roundingMode) { @@ -98,7 +102,9 @@ static BigDecimal sqrt(BigDecimal number, int scale, RoundingMode roundingMode) *

* 此方法返回零位的最高位(“最左侧”)前在指定的int值的二进制补码表示法,或32个1位的数量,如果该值为零。 * - * @param i 数字 + * @param i + * 数字 + * * @return 结果 */ public static int numberOfLeadingZeros(long i) { @@ -134,7 +140,9 @@ public static int numberOfLeadingZeros(long i) { /** * 设置给DecimalFormat用的精度字符创 * - * @param scale 精度 + * @param scale + * 精度 + * * @return 结果 */ public static String scale2FormatStr(int scale) { @@ -174,6 +182,7 @@ public static DecimalFormat scale2Format(final int scale, final RoundingMode rou /** * @param value * @param scale + * * @return */ public static String number2Str(Double value, int scale) { @@ -183,6 +192,7 @@ public static String number2Str(Double value, int scale) { /** * @param value * @param scale + * * @return */ public static Double number2double(Double value, int scale) { diff --git a/common/src/main/java/pro/tools/data/image/ToolBarCode.java b/common/src/main/java/pro/tools/data/image/ToolBarCode.java index 872f6ba..a77ad3b 100644 --- a/common/src/main/java/pro/tools/data/image/ToolBarCode.java +++ b/common/src/main/java/pro/tools/data/image/ToolBarCode.java @@ -1,19 +1,12 @@ package pro.tools.data.image; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.BinaryBitmap; -import com.google.zxing.EncodeHintType; -import com.google.zxing.LuminanceSource; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.MultiFormatWriter; -import com.google.zxing.NotFoundException; -import com.google.zxing.Result; -import com.google.zxing.WriterException; +import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageConfig; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import pro.tools.constant.StrConst; @@ -22,8 +15,14 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; +import java.nio.file.Paths; import java.util.Hashtable; +import static com.google.zxing.BarcodeFormat.QR_CODE; + /** * 条码处理 * @@ -32,7 +31,7 @@ public final class ToolBarCode { private ToolBarCode() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -45,16 +44,19 @@ private ToolBarCode() { * @param savePath 保存路径 */ @SuppressWarnings({"rawtypes", "unchecked", "deprecation"}) - @Deprecated public static void encode(String content, int width, int height, String fileType, String savePath) throws IOException, WriterException { - content = new String(content.getBytes(StrConst.DEFAULT_CHARSET_NAME), StrConst.DEFAULT_CHARSET_NAME);// 二维码内容 - Hashtable hints = new Hashtable(); - hints.put(EncodeHintType.CHARACTER_SET, StrConst.DEFAULT_CHARSET_NAME); - BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); - File file = new File(savePath); - MatrixToImageWriter.writeToFile(bitMatrix, fileType, file); + Charset charset = Charset.forName("UTF-8"); + CharsetEncoder encoder = charset.newEncoder(); + + byte[] b = encoder.encode(CharBuffer.wrap(content)).array(); + String data = new String(b, "iso8859-1"); + + Writer writer = new QRCodeWriter(); + BitMatrix matrix = writer.encode(data, QR_CODE, width, height); + MatrixToImageWriter.writeToPath(matrix, fileType, Paths.get(savePath)); } + /** * 生成带logo的二维码 * @@ -65,10 +67,22 @@ public static void encode(String content, int width, int height, String fileType * @param fileType 文件类型,如png * @param savePath 保存路径 */ - public static void encodeLogo(String content, int width, int height, String logoPath, String fileType, String savePath) throws IOException { - BitMatrix matrix = MatrixToImageWriterEx.createQRCode(content, width, height); - MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig(Color.BLUE, 4); + public static void encodeLogo(String content, int width, int height, String logoPath, String fileType, String savePath) throws IOException, WriterException { + Charset charset = Charset.forName("UTF-8"); + CharsetEncoder encoder = charset.newEncoder(); + + byte[] b = encoder.encode(CharBuffer.wrap(content)).array(); + String data = new String(b, "iso8859-1"); + + Writer writer = new QRCodeWriter(); + BitMatrix matrix = writer.encode(data, QR_CODE, width, height); + MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig(Color.BLACK, 10); MatrixToImageWriterEx.writeToFile(matrix, fileType, savePath, logoPath, logoConfig); + + +// BitMatrix matrix = MatrixToImageWriterEx.createQRCode(content, width, height); +// MatrixToLogoImageConfig logoConfig = new MatrixToLogoImageConfig(Color.BLUE, 4); +// MatrixToImageWriterEx.writeToFile(matrix, fileType, savePath, logoPath, logoConfig); } /** @@ -79,17 +93,12 @@ public static void encodeLogo(String content, int width, int height, String logo */ @SuppressWarnings({"rawtypes", "unchecked"}) public static String decode(String filePath) throws IOException, NotFoundException { - BufferedImage image; - image = ImageIO.read(new File(filePath)); - if (image == null) { - return "Could not decode image"; - } + BufferedImage image = ImageIO.read(new File(filePath)); LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); - Result result; - Hashtable hints = new Hashtable(); - hints.put(EncodeHintType.CHARACTER_SET, StrConst.DEFAULT_CHARSET_NAME); - result = new MultiFormatReader().decode(bitmap, hints); + Hashtable hints = new Hashtable<>(); + hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); + Result result = new MultiFormatReader().decode(bitmap, hints); return result.getText(); } @@ -167,7 +176,7 @@ public static BitMatrix createQRCode(String content, int width, int height) { hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); BitMatrix matrix = null; try { - matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); + matrix = new MultiFormatWriter().encode(content, QR_CODE, width, height, hints); } catch (WriterException e) { e.printStackTrace(); } @@ -183,10 +192,8 @@ public static BitMatrix createQRCode(String content, int width, int height) { * @param logoPath logo路径 * @throws IOException */ - @SuppressWarnings({"deprecation"}) - @Deprecated public static void writeToFile(BitMatrix matrix, String format, String imagePath, String logoPath) throws IOException { - MatrixToImageWriter.writeToFile(matrix, format, new File(imagePath), new MatrixToImageConfig()); + MatrixToImageWriter.writeToPath(matrix, format, Paths.get(imagePath), new MatrixToImageConfig()); // 添加logo图片, 此处一定需要重新进行读取,而不能直接使用二维码的BufferedImage 对象 BufferedImage img = ImageIO.read(new File(imagePath)); @@ -203,10 +210,8 @@ public static void writeToFile(BitMatrix matrix, String format, String imagePath * @param logoConfig logo配置对象 * @throws IOException */ - @SuppressWarnings({"deprecation"}) - @Deprecated public static void writeToFile(BitMatrix matrix, String format, String imagePath, String logoPath, MatrixToLogoImageConfig logoConfig) throws IOException { - MatrixToImageWriter.writeToFile(matrix, format, new File(imagePath), new MatrixToImageConfig()); + MatrixToImageWriter.writeToPath(matrix, format, Paths.get(imagePath), new MatrixToImageConfig()); // 添加logo图片, 此处一定需要重新进行读取,而不能直接使用二维码的BufferedImage 对象 BufferedImage img = ImageIO.read(new File(imagePath)); diff --git a/common/src/main/java/pro/tools/data/image/ToolImagePressText.java b/common/src/main/java/pro/tools/data/image/ToolImagePressText.java index 9072647..34a290b 100644 --- a/common/src/main/java/pro/tools/data/image/ToolImagePressText.java +++ b/common/src/main/java/pro/tools/data/image/ToolImagePressText.java @@ -15,7 +15,7 @@ public final class ToolImagePressText { private ToolImagePressText() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -44,12 +44,8 @@ public static void pressImage(String pressImg, String targetImg, int x, int y) t int readHeight = read.getHeight(null); g.drawImage(read, width - readWidth - x, height - readHeight - y, readWidth, readHeight, null); g.dispose(); - //try (FileOutputStream out = new FileOutputStream(targetImg)) { - // JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); - // encoder.encode(image); - //} String formatName = targetImg.substring(targetImg.lastIndexOf(".") + 1); - ImageIO.write(image, /*"GIF"*/ formatName /* format desired */, new File(targetImg) /* target */); + ImageIO.write(image, formatName, new File(targetImg)); } /** diff --git a/common/src/main/java/pro/tools/data/image/ToolImageResize.java b/common/src/main/java/pro/tools/data/image/ToolImageResize.java index 76fd572..c295e3a 100644 --- a/common/src/main/java/pro/tools/data/image/ToolImageResize.java +++ b/common/src/main/java/pro/tools/data/image/ToolImageResize.java @@ -28,7 +28,7 @@ public final class ToolImageResize { private ToolImageResize() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } public static final MediaTracker TRACKER = new MediaTracker(new Component() { diff --git a/common/src/main/java/pro/tools/data/image/ToolImageTailor.java b/common/src/main/java/pro/tools/data/image/ToolImageTailor.java index 6b8ebc7..4970ee3 100644 --- a/common/src/main/java/pro/tools/data/image/ToolImageTailor.java +++ b/common/src/main/java/pro/tools/data/image/ToolImageTailor.java @@ -19,18 +19,23 @@ public final class ToolImageTailor { private ToolImageTailor() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 裁剪 * - * @param srcPath 源图片路径名称如:c:/1.jpg - * @param savePath 剪切图片存放路径名称.如:c:/2.jpg - * @param x 剪切点x坐标 + * @param srcPath + * 源图片路径名称如:c:/1.jpg + * @param savePath + * 剪切图片存放路径名称.如:c:/2.jpg + * @param x + * 剪切点x坐标 * @param y - * @param width 剪切点大小 + * @param width + * 剪切点大小 * @param height + * * @throws IOException */ public static void cut(String srcPath, String savePath, int x, int y, int width, int height) throws IOException { @@ -52,26 +57,26 @@ public static void cut(String srcPath, String savePath, int x, int y, int width, ) { /* *

iis:读取源.true:只向前搜索

.将它标记为 ‘只向前搜索’。 此设置意味着包含在输入源中的图像将只按顺序读取,可能允许 reader 避免缓存包含与以前已经读取的图像关联的数据的那些输入部分。 - */ + */ reader.setInput(iis, true); - /* + /* *

描述如何对流进行解码的类

.用于指定如何在输入时从 Java Image I/O 框架的上下文中的流转换一幅图像或一组图像。用于特定图像格式的插件 将从其 ImageReader 实现的 getDefaultReadParam 方法中返回 - * ImageReadParam 的实例。 - */ + * ImageReadParam 的实例。 + */ ImageReadParam param = reader.getDefaultReadParam(); - /* + /* * 图片裁剪区域。Rectangle 指定了坐标空间中的一个区域,通过 Rectangle 对象 的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。 - */ + */ Rectangle rect = new Rectangle(x, y, width, height); // 提供一个 BufferedImage,将其用作解码像素数据的目标。 param.setSourceRegion(rect); - /* + /* * 使用所提供的 ImageReadParam 读取通过索引 imageIndex 指定的对象,并将 它作为一个完整的 BufferedImage 返回。 - */ + */ BufferedImage bi = reader.read(0, param); // 保存新图片 diff --git a/common/src/main/java/pro/tools/data/text/ToolConvert.java b/common/src/main/java/pro/tools/data/text/ToolConvert.java index 6494072..d258f7a 100644 --- a/common/src/main/java/pro/tools/data/text/ToolConvert.java +++ b/common/src/main/java/pro/tools/data/text/ToolConvert.java @@ -21,7 +21,7 @@ public final class ToolConvert { private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; private ToolConvert() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -329,9 +329,11 @@ public static byte[] bits2Bytes(String bits) { int byteLen = bits.length() / 8; // 不是8的倍数前面补0 if (lenMod != 0) { + StringBuilder bitsBuilder = new StringBuilder(bits); for (int i = lenMod; i < 8; i++) { - bits = "0" + bits; + bitsBuilder.insert(0, "0"); } + bits = bitsBuilder.toString(); byteLen++; } byte[] bytes = new byte[byteLen]; diff --git a/common/src/main/java/pro/tools/data/text/ToolJson.java b/common/src/main/java/pro/tools/data/text/ToolJson.java index 9b5f799..c9acdbe 100644 --- a/common/src/main/java/pro/tools/data/text/ToolJson.java +++ b/common/src/main/java/pro/tools/data/text/ToolJson.java @@ -2,20 +2,28 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import org.google.gson.Gson; -import org.google.gson.GsonBuilder; -import org.google.gson.JsonObject; -import org.google.gson.reflect.TypeToken; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; import pro.tools.data.decimal.Decimal; import pro.tools.data.text.json.TypeBuilder; -import pro.tools.data.text.json.typeadapter.*; +import pro.tools.data.text.json.typeadapter.BigDecimalTypeAdapter; +import pro.tools.data.text.json.typeadapter.DatePlusTypeAdapter; +import pro.tools.data.text.json.typeadapter.DecimalTypeAdapter; +import pro.tools.data.text.json.typeadapter.LocalDateTimeTypeAdapter; +import pro.tools.data.text.json.typeadapter.LocalDateTypeAdapter; +import pro.tools.data.text.json.typeadapter.TreeMapTypeAdapter; import pro.tools.time.DatePlus; import java.lang.reflect.Type; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; /** * 辅助类 @@ -75,6 +83,7 @@ public static GsonBuilder buildSimpleGsonBuilder() { * 将Map进行JSON编码 * * @param map + * * @return */ public static String mapToJson(Map map) { @@ -88,6 +97,7 @@ public static String mapToJson(Map map) { * 将Map进行JSON编码 * * @param json + * * @return */ public static Map jsonToMap(String json) { @@ -103,6 +113,7 @@ public static Map jsonToMap(String json) { * 将模型进行JSON编码 * * @param model + * * @return String */ public static String modelToJson(T model) { @@ -117,6 +128,7 @@ public static String modelToJson(T model) { * * @param sJson * @param classOfT + * * @return Object */ public static T jsonToModel(String sJson, Class classOfT) { @@ -128,6 +140,7 @@ public static T jsonToModel(String sJson, Class classOfT) { * * @param sJson * @param type + * * @return Object */ public static T jsonToAny(String sJson, Type type) { @@ -168,6 +181,7 @@ public static S anyToAny(T t, Type type) { * * @param data * @param classOfT + * * @return Object */ public static T mapToModel(Map data, Class classOfT) { @@ -179,6 +193,7 @@ public static T mapToModel(Map data, Class classOfT) { * * @param data * @param classOfT + * * @return Object */ public static List mapToModelList(Map data, Class classOfT) { @@ -189,6 +204,7 @@ public static List mapToModelList(Map data, Class classOfT) { * 将模型进行JSON解码 * * @param data + * * @return Object */ public static Map modelToMap(T data) { @@ -199,6 +215,7 @@ public static Map modelToMap(T data) { * 将模型进行JSON解码 * * @param data + * * @return Object */ public static List modelToMapList(T data) { @@ -210,6 +227,7 @@ public static List modelToMapList(T data) { * 将模型列表进行JSON解码 * * @param sJson + * * @return List */ public static List jsonToModelList(String sJson, Class classOfT) { @@ -231,6 +249,7 @@ public static List jsonToModelList(String sJson, Class classOfT) { * 将模型列表进行JSON解码 * * @param sJson + * * @return List */ public static List jsonToMapList(String sJson) { @@ -251,9 +270,13 @@ public static List jsonToMapList(String sJson) { /** * 把json数组转换成泛型T为类型的ArrayList * - * @param json Json数组 - * @param clazz 泛型类型的class - * @param 泛型类型 + * @param json + * Json数组 + * @param clazz + * 泛型类型的class + * @param + * 泛型类型 + * * @return 返回ArrayList */ public static ArrayList jsonToArrayList(String json, Class clazz) { @@ -271,7 +294,9 @@ public static ArrayList jsonToArrayList(String json, Class clazz) { /** * 把json数组转换成String类型的ArrayList * - * @param json json数组 + * @param json + * json数组 + * * @return 返回ArrayList */ public static ArrayList jsonToArrayList(String json) { @@ -290,6 +315,7 @@ public static ArrayList jsonToArrayList(String json) { * 将json列表转换为字符串列表,每个字符串为一个对象 * * @param json + * * @return List */ public static List dealJsonStr(String json) { diff --git a/common/src/main/java/pro/tools/data/text/ToolPinYin.java b/common/src/main/java/pro/tools/data/text/ToolPinYin.java index d7ba2e0..0e0c670 100644 --- a/common/src/main/java/pro/tools/data/text/ToolPinYin.java +++ b/common/src/main/java/pro/tools/data/text/ToolPinYin.java @@ -16,13 +16,14 @@ public final class ToolPinYin { private ToolPinYin() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 得到 全拼 * * @param src + * * @return */ public static String getPinYin(String src) throws BadHanyuPinyinOutputFormatCombination { @@ -40,7 +41,7 @@ public static String getPinYin(String src) throws BadHanyuPinyinOutputFormatComb t2 = PinyinHelper.toHanyuPinyinStringArray(aT1, t3); t4.append(t2[0]); } else { - t4.append(Character.toString(aT1)); + t4.append(aT1); } } return t4.toString(); @@ -50,6 +51,7 @@ public static String getPinYin(String src) throws BadHanyuPinyinOutputFormatComb * 得到中文首字母 * * @param str + * * @return */ public static String getPinYinHeadChar(String str) { @@ -71,6 +73,7 @@ public static String getPinYinHeadChar(String str) { * 将字符串转移为ASCII码 * * @param cnStr + * * @return */ public static String getCnASCII(String cnStr) { diff --git a/common/src/main/java/pro/tools/data/text/ToolRandoms.java b/common/src/main/java/pro/tools/data/text/ToolRandoms.java index a0ee85f..a41ecc4 100644 --- a/common/src/main/java/pro/tools/data/text/ToolRandoms.java +++ b/common/src/main/java/pro/tools/data/text/ToolRandoms.java @@ -11,7 +11,7 @@ */ public final class ToolRandoms { private ToolRandoms() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** diff --git a/common/src/main/java/pro/tools/data/text/ToolRegex.java b/common/src/main/java/pro/tools/data/text/ToolRegex.java index a531096..93f2966 100644 --- a/common/src/main/java/pro/tools/data/text/ToolRegex.java +++ b/common/src/main/java/pro/tools/data/text/ToolRegex.java @@ -29,7 +29,7 @@ public final class ToolRegex { private ToolRegex() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -41,7 +41,7 @@ private ToolRegex() { * @return 是返回true, 否则返回false */ public static boolean isInteger(CharSequence input) { - return NumberBo(0, input); + return isNumber(0, input); } /** @@ -53,7 +53,7 @@ public static boolean isInteger(CharSequence input) { * @return 是返回true, 否则返回false */ public static boolean isDecimal(CharSequence input) { - return NumberBo(1, input); + return isNumber(1, input); } @@ -67,7 +67,7 @@ public static boolean isDecimal(CharSequence input) { * * @return 是返回true, 否则返回false */ - private static boolean NumberBo(int type, CharSequence str) { + private static boolean isNumber(int type, CharSequence str) { if (ToolStr.isBlank(str.toString())) { return false; } diff --git a/common/src/main/java/pro/tools/data/text/ToolStr.java b/common/src/main/java/pro/tools/data/text/ToolStr.java index 4e6cb4b..cfb9ca5 100644 --- a/common/src/main/java/pro/tools/data/text/ToolStr.java +++ b/common/src/main/java/pro/tools/data/text/ToolStr.java @@ -10,7 +10,7 @@ public final class ToolStr { private ToolStr() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } diff --git a/common/src/main/java/pro/tools/data/text/ToolStrCompress.java b/common/src/main/java/pro/tools/data/text/ToolStrCompress.java new file mode 100644 index 0000000..7c6e505 --- /dev/null +++ b/common/src/main/java/pro/tools/data/text/ToolStrCompress.java @@ -0,0 +1,79 @@ +package pro.tools.data.text; + +import pro.tools.constant.StrConst; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +/** + * 对字符串的压缩及解压 + * + * @author SeanDragon + */ +public class ToolStrCompress { + + private ToolStrCompress() { + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); + } + + /** + * 字符串的压缩 + * + * @param str 待压缩的字符串 + * + * @return 返回压缩后的字符串 + * + * @throws IOException + */ + public static String compress(String str) throws IOException { + if (null == str || str.length() <= 0) { + return str; + } + try ( + // 创建一个新的 byte 数组输出流 + ByteArrayOutputStream out = new ByteArrayOutputStream(); + // 使用默认缓冲区大小创建新的输出流 + GZIPOutputStream gzip = new GZIPOutputStream(out);) { + // 将 b.length 个字节写入此输出流 + gzip.write(str.getBytes()); + // 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串 + return out.toString(StrConst.DEFAULT_CHARSET_NAME); + } + } + + /** + * 字符串的解压 + * + * @param str 对字符串解压 + * + * @return 返回解压缩后的字符串 + * + * @throws IOException + */ + public static String unCompress(String str) throws IOException { + if (null == str || str.length() <= 0) { + return str; + } + try ( + // 创建一个新的 byte 数组输出流 + ByteArrayOutputStream out = new ByteArrayOutputStream(); + // 创建一个 ByteArrayInputStream,使用 buf 作为其缓冲区数组 + ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes(StrConst.DEFAULT_CHARSET_NAME)); + // 使用默认缓冲区大小创建新的输入流 + GZIPInputStream gzip = new GZIPInputStream(in);) { + byte[] buffer = new byte[256]; + int n = 0; + // 将未压缩数据读入字节数组 + while ((n = gzip.read(buffer)) >= 0) { + // 将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此 byte数组输出流 + out.write(buffer, 0, n); + } + // 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串 + return out.toString(StrConst.DEFAULT_CHARSET_NAME); + } + } + +} diff --git a/common/src/main/java/pro/tools/data/text/json/TypeBuilder.java b/common/src/main/java/pro/tools/data/text/json/TypeBuilder.java index 76b9e2b..74f434d 100644 --- a/common/src/main/java/pro/tools/data/text/json/TypeBuilder.java +++ b/common/src/main/java/pro/tools/data/text/json/TypeBuilder.java @@ -8,6 +8,9 @@ import java.lang.reflect.Type; import java.util.List; +/** + * @author SeanDragon + */ public class TypeBuilder { private final TypeBuilder parent; private final Class raw; @@ -33,7 +36,7 @@ public TypeBuilder beginSubType(Class raw) { return newInstance(raw, this); } - public TypeBuilder endSubType() { + public TypeBuilder endSubType() throws TypeException { if (parent == null) { throw new TypeException("expect beginSubType() before endSubType()"); } diff --git a/common/src/main/java/pro/tools/data/text/json/TypeToken.java b/common/src/main/java/pro/tools/data/text/json/TypeToken.java index a004a33..48c034f 100644 --- a/common/src/main/java/pro/tools/data/text/json/TypeToken.java +++ b/common/src/main/java/pro/tools/data/text/json/TypeToken.java @@ -8,7 +8,7 @@ /** * @author SeanDragon */ -public abstract class TypeToken { +public final class TypeToken { private final Type type; public TypeToken() { diff --git a/common/src/main/java/pro/tools/data/text/json/exception/TypeException.java b/common/src/main/java/pro/tools/data/text/json/exception/TypeException.java index 6812225..05a3721 100644 --- a/common/src/main/java/pro/tools/data/text/json/exception/TypeException.java +++ b/common/src/main/java/pro/tools/data/text/json/exception/TypeException.java @@ -1,5 +1,8 @@ package pro.tools.data.text.json.exception; +/** + * @author SeanDragon + */ public class TypeException extends RuntimeException { public TypeException() { } diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/ABasicTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/BaseTypeAdapter.java similarity index 74% rename from common/src/main/java/pro/tools/data/text/json/typeadapter/ABasicTypeAdapter.java rename to common/src/main/java/pro/tools/data/text/json/typeadapter/BaseTypeAdapter.java index 4ddd0d9..e5938eb 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/ABasicTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/BaseTypeAdapter.java @@ -1,14 +1,17 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.TypeAdapter; -import org.google.gson.stream.JsonReader; -import org.google.gson.stream.JsonToken; -import org.google.gson.stream.JsonWriter; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; import java.io.IOException; -public abstract class ABasicTypeAdapter extends TypeAdapter { - public ABasicTypeAdapter() { +/** + * @author SeanDragon + */ +public abstract class BaseTypeAdapter extends TypeAdapter { + BaseTypeAdapter() { } @Override @@ -25,8 +28,28 @@ public void write(JsonWriter jsonWriter, T value) throws IOException { } } + /** + * 读取值 + * + * @param jsonReader + * gson的阅读器 + * + * @return 返回值 + * + * @throws IOException + */ public abstract T reading(JsonReader jsonReader) throws IOException; + /** + * 赋值 + * + * @param jsonWriter + * gson的书写器 + * @param value + * 想要赋上的值 + * + * @throws IOException + */ public abstract void writing(JsonWriter jsonWriter, T value) throws IOException; protected boolean compareToken(JsonToken currentToken, JsonToken targetToken) { diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/BigDecimalTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/BigDecimalTypeAdapter.java index 3c8a766..8245abe 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/BigDecimalTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/BigDecimalTypeAdapter.java @@ -1,12 +1,15 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.stream.JsonReader; -import org.google.gson.stream.JsonWriter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.math.BigDecimal; -public class BigDecimalTypeAdapter extends ABasicTypeAdapter { +/** + * @author SeanDragon + */ +public class BigDecimalTypeAdapter extends BaseTypeAdapter { @Override public BigDecimal reading(JsonReader jsonReader) throws IOException { diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/DatePlusTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/DatePlusTypeAdapter.java index 17c87e5..5c7200b 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/DatePlusTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/DatePlusTypeAdapter.java @@ -1,7 +1,7 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.stream.JsonReader; -import org.google.gson.stream.JsonWriter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; import pro.tools.time.DatePlus; import pro.tools.time.ToolDatePlus; @@ -13,7 +13,7 @@ * * @author sd */ -public class DatePlusTypeAdapter extends ABasicTypeAdapter { +public class DatePlusTypeAdapter extends BaseTypeAdapter { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS"); diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/DecimalTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/DecimalTypeAdapter.java index 26f47be..46cad33 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/DecimalTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/DecimalTypeAdapter.java @@ -1,12 +1,15 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.stream.JsonReader; -import org.google.gson.stream.JsonWriter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; import pro.tools.data.decimal.Decimal; import java.io.IOException; -public class DecimalTypeAdapter extends ABasicTypeAdapter { +/** + * @author SeanDragon + */ +public class DecimalTypeAdapter extends BaseTypeAdapter { @Override public Decimal reading(JsonReader jsonReader) throws IOException { diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTimeTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTimeTypeAdapter.java index e909a55..89b9627 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTimeTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTimeTypeAdapter.java @@ -1,7 +1,7 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.stream.JsonReader; -import org.google.gson.stream.JsonWriter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.sql.Timestamp; @@ -11,7 +11,7 @@ /** * @author SeanDragon */ -public class LocalDateTimeTypeAdapter extends ABasicTypeAdapter { +public class LocalDateTimeTypeAdapter extends BaseTypeAdapter { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS"); diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTypeAdapter.java index 4421fb8..fde79e2 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/LocalDateTypeAdapter.java @@ -1,14 +1,17 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.stream.JsonReader; -import org.google.gson.stream.JsonWriter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.sql.Date; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -public class LocalDateTypeAdapter extends ABasicTypeAdapter { +/** + * @author SeanDragon + */ +public class LocalDateTypeAdapter extends BaseTypeAdapter { public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); diff --git a/common/src/main/java/pro/tools/data/text/json/typeadapter/TreeMapTypeAdapter.java b/common/src/main/java/pro/tools/data/text/json/typeadapter/TreeMapTypeAdapter.java index a1214bf..de305a1 100644 --- a/common/src/main/java/pro/tools/data/text/json/typeadapter/TreeMapTypeAdapter.java +++ b/common/src/main/java/pro/tools/data/text/json/typeadapter/TreeMapTypeAdapter.java @@ -1,10 +1,10 @@ package pro.tools.data.text.json.typeadapter; -import org.google.gson.JsonDeserializationContext; -import org.google.gson.JsonDeserializer; -import org.google.gson.JsonElement; -import org.google.gson.JsonParseException; -import org.google.gson.JsonPrimitive; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; import java.lang.reflect.Type; import java.util.TreeMap; @@ -14,7 +14,7 @@ *

* Create By 2017-10-24 17:14 */ -public class TreeMapTypeAdapter implements JsonDeserializer> { +public class TreeMapTypeAdapter implements JsonDeserializer> { @Override public TreeMap deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { diff --git a/common/src/main/java/pro/tools/file/FileType.java b/common/src/main/java/pro/tools/file/FileType.java index 55a7bae..9768280 100644 --- a/common/src/main/java/pro/tools/file/FileType.java +++ b/common/src/main/java/pro/tools/file/FileType.java @@ -2,6 +2,8 @@ /** * 文件类型枚取 + * + * @author SeanDragon */ public enum FileType { diff --git a/common/src/main/java/pro/tools/file/ToolFile.java b/common/src/main/java/pro/tools/file/ToolFile.java index b697560..0eb71d9 100644 --- a/common/src/main/java/pro/tools/file/ToolFile.java +++ b/common/src/main/java/pro/tools/file/ToolFile.java @@ -5,19 +5,7 @@ import pro.tools.data.text.ToolConvert; import pro.tools.data.text.ToolStr; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; +import java.io.*; import java.nio.charset.Charset; import java.security.DigestInputStream; import java.security.MessageDigest; @@ -33,7 +21,7 @@ public final class ToolFile { private ToolFile() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -1107,7 +1095,8 @@ public static String readFile2String(File file, String charsetName) throws IOExc String line; while ((line = reader.readLine()) != null) { - sb.append(line).append("\r\n");// windows系统换行为\r\n,Linux为\n + // windows系统换行为\r\n,Linux为\n + sb.append(line).append("\r\n"); } // 要去除最后的换行符 return sb.delete(sb.length() - 2, sb.length()).toString(); diff --git a/common/src/main/java/pro/tools/file/ToolFileType.java b/common/src/main/java/pro/tools/file/ToolFileType.java index 52ecf6d..b099eca 100644 --- a/common/src/main/java/pro/tools/file/ToolFileType.java +++ b/common/src/main/java/pro/tools/file/ToolFileType.java @@ -9,6 +9,8 @@ /** * 文件类型判断类 + * + * @author SeanDragon */ public final class ToolFileType { /** @@ -17,34 +19,14 @@ public final class ToolFileType { private ToolFileType() { } - ///** - // * 将文件头转换成16进制字符串 - // * - // * @param src - // * @return 16进制字符串 - // */ - //private static String bytesToHexString(byte[] src){ - // - // StringBuilder stringBuilder = new StringBuilder(); - // if (src == null || src.length <= 0) { - // return null; - // } - // for (byte aSrc : src) { - // int v = aSrc & 0xFF; - // String hv = Integer.toHexString(v); - // if (hv.length() < 2) { - // stringBuilder.append(0); - // } - // stringBuilder.append(hv); - // } - // return stringBuilder.toString(); - //} - /** * 得到文件头 * - * @param inputStream 文件路径 + * @param inputStream + * 文件路径 + * * @return 文件头 + * * @throws IOException */ private static String getFileContent(InputStream inputStream) throws IOException { @@ -69,7 +51,9 @@ private static String getFileContent(InputStream inputStream) throws IOException /** * 判断文件类型 * - * @param inputStream 文件流 + * @param inputStream + * 文件流 + * * @return 文件类型 */ public static FileType getType(InputStream inputStream) throws IOException { @@ -95,7 +79,9 @@ public static FileType getType(InputStream inputStream) throws IOException { /** * 判断文件类型 * - * @param filePath 文件路径 + * @param filePath + * 文件路径 + * * @return 文件类型 */ public static FileType getType(String filePath) throws IOException { @@ -105,10 +91,12 @@ public static FileType getType(String filePath) throws IOException { /** * 判断文件类型 * - * @param file 文件 + * @param file + * 文件 + * * @return 文件类型 */ public static FileType getType(File file) throws IOException { return getType(new FileInputStream(file)); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/common/src/main/java/pro/tools/file/ToolZip.java b/common/src/main/java/pro/tools/file/ToolZip.java index 0184347..41fe086 100644 --- a/common/src/main/java/pro/tools/file/ToolZip.java +++ b/common/src/main/java/pro/tools/file/ToolZip.java @@ -34,7 +34,7 @@ public final class ToolZip { private ToolZip() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** diff --git a/common/src/main/java/pro/tools/format/ToolFormat.java b/common/src/main/java/pro/tools/format/ToolFormat.java index eb51343..8dc3a7b 100644 --- a/common/src/main/java/pro/tools/format/ToolFormat.java +++ b/common/src/main/java/pro/tools/format/ToolFormat.java @@ -9,7 +9,7 @@ public final class ToolFormat { private ToolFormat() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** diff --git a/common/src/main/java/pro/tools/format/ToolFormatJson.java b/common/src/main/java/pro/tools/format/ToolFormatJson.java index c48455b..ed3d2e2 100644 --- a/common/src/main/java/pro/tools/format/ToolFormatJson.java +++ b/common/src/main/java/pro/tools/format/ToolFormatJson.java @@ -8,7 +8,7 @@ public final class ToolFormatJson { private ToolFormatJson() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } diff --git a/common/src/main/java/pro/tools/path/ToolPath.java b/common/src/main/java/pro/tools/path/ToolPath.java index 8b49d69..a694d32 100644 --- a/common/src/main/java/pro/tools/path/ToolPath.java +++ b/common/src/main/java/pro/tools/path/ToolPath.java @@ -108,7 +108,7 @@ public static Path reName(Path path, String newName) throws IOException { public static Path createDir(Path path, boolean replace) throws IOException { if (replace) { rmr(path); - if(isDir(path)) { + if (isDir(path)) { path = path.getParent(); } return Files.createDirectories(path); @@ -116,7 +116,7 @@ public static Path createDir(Path path, boolean replace) throws IOException { if (isExists(path)) { return path; } else { - if(isDir(path)) { + if (isDir(path)) { path = path.getParent(); } return Files.createDirectories(path); diff --git a/common/src/main/java/pro/tools/script/ToolScript.java b/common/src/main/java/pro/tools/script/ToolScript.java index aa95462..3c286c2 100644 --- a/common/src/main/java/pro/tools/script/ToolScript.java +++ b/common/src/main/java/pro/tools/script/ToolScript.java @@ -1,11 +1,15 @@ package pro.tools.script; +import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import pro.tools.path.ToolPath; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import java.io.IOException; +import java.nio.file.Paths; import java.util.Map; /** @@ -16,7 +20,7 @@ public final class ToolScript { private ToolScript() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } @@ -27,6 +31,7 @@ private ToolScript() { * * @param templateContent * @param paramMap + * * @return */ public static String render(String templateContent, Map paramMap) throws ScriptException { @@ -66,20 +71,26 @@ public static String render(String templateContent, Map paramMap // } // 取js变量值 - return (String) engine.get("output"); } /** * 生成静态html * - * @param tlPath 模板路径 - * @param paramMap 参数 - * @param htmlPath html文件保存路径 + * @param tlPath + * 模板路径 + * @param paramMap + * 参数 + * @param htmlPath + * html文件保存路径 */ public static void makeHtml(String tlPath, Map paramMap, String htmlPath) throws ScriptException { String html = render(tlPath, paramMap); - //ToolDirFile.createFile(htmlPath, html); + try { + ToolPath.writeStrings(Paths.get(htmlPath), Lists.newArrayList(html), false); + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/common/src/main/java/pro/tools/system/NamedThreadFactory.java b/common/src/main/java/pro/tools/system/NamedThreadFactory.java index 8827506..0a3390e 100644 --- a/common/src/main/java/pro/tools/system/NamedThreadFactory.java +++ b/common/src/main/java/pro/tools/system/NamedThreadFactory.java @@ -18,6 +18,9 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; +/** + * @author SeanDragon + */ public class NamedThreadFactory implements ThreadFactory { private static final AtomicInteger POOL_SEQ = new AtomicInteger(1); diff --git a/common/src/main/java/pro/tools/system/ToolClassSearch.java b/common/src/main/java/pro/tools/system/ToolClassSearch.java index b1a71b7..36d9dc2 100644 --- a/common/src/main/java/pro/tools/system/ToolClassSearch.java +++ b/common/src/main/java/pro/tools/system/ToolClassSearch.java @@ -24,7 +24,7 @@ public final class ToolClassSearch { } private ToolClassSearch() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } public static void init() { @@ -102,4 +102,19 @@ public static Set> getClazzByInterface(Class clazz) { return returnClassList; } + + public static Set> getClazzByParent(Class clazz) { + Set> returnClassList = new HashSet<>(); + + classSet.forEach(one -> { + if (clazz.isAssignableFrom(one)) { + // 本身加不进去 + if (!clazz.equals(one)) { + returnClassList.add(one); + } + } + }); + + return returnClassList; + } } diff --git a/common/src/main/java/pro/tools/system/ToolMaven.java b/common/src/main/java/pro/tools/system/ToolMaven.java index 58bf7e0..b1ed41e 100644 --- a/common/src/main/java/pro/tools/system/ToolMaven.java +++ b/common/src/main/java/pro/tools/system/ToolMaven.java @@ -10,7 +10,7 @@ */ public final class ToolMaven { private ToolMaven() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } public static boolean install(String groupId, String artifactId, String version, String fileName) throws IOException { diff --git a/common/src/main/java/pro/tools/system/ToolOS.java b/common/src/main/java/pro/tools/system/ToolOS.java index 865d387..2fa067f 100644 --- a/common/src/main/java/pro/tools/system/ToolOS.java +++ b/common/src/main/java/pro/tools/system/ToolOS.java @@ -43,10 +43,14 @@ public final class ToolOS { public static final String USER_NAME = getOsSystemProperty("user.name"); // 用户的账户名称 public static final String USER_HOME = getOsSystemProperty("user.home"); // 用户的主目录 public static final String USER_DIR = getOsSystemProperty("user.dir"); // 用户的当前工作目录 - // 系统bean + /** + * 系统Bean + */ private static final OperatingSystemMXBean SYSTEM_MX_BEAN; private static final List LIST; - // K转换M + /** + * K转换M + */ private static final long K2M = 1024L * 1024L; static { @@ -55,13 +59,14 @@ public final class ToolOS { } private ToolOS() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 获取java系统环境变量 * * @param key + * * @return */ public static String getOsSystemProperty(String key) { diff --git a/common/src/main/java/pro/tools/system/ToolShell.java b/common/src/main/java/pro/tools/system/ToolShell.java index 380366d..64e4622 100644 --- a/common/src/main/java/pro/tools/system/ToolShell.java +++ b/common/src/main/java/pro/tools/system/ToolShell.java @@ -17,7 +17,7 @@ public final class ToolShell { private ToolShell() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** diff --git a/common/src/main/java/pro/tools/system/ToolSystem.java b/common/src/main/java/pro/tools/system/ToolSystem.java index 09a73c6..bc25ce5 100644 --- a/common/src/main/java/pro/tools/system/ToolSystem.java +++ b/common/src/main/java/pro/tools/system/ToolSystem.java @@ -12,7 +12,7 @@ public final class ToolSystem { private static Boolean haveDiskD; private ToolSystem() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } public static boolean isWindows() { diff --git a/common/src/main/java/pro/tools/time/DatePlus.java b/common/src/main/java/pro/tools/time/DatePlus.java index a2599e6..f1b8dcb 100644 --- a/common/src/main/java/pro/tools/time/DatePlus.java +++ b/common/src/main/java/pro/tools/time/DatePlus.java @@ -1,15 +1,12 @@ package pro.tools.time; import java.io.Serializable; -import java.time.DayOfWeek; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.Month; +import java.time.*; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; +import java.util.Date; /** * Created on 17/4/8 19:27 星期六. 替代时间类的类 @@ -23,6 +20,7 @@ public class DatePlus implements Serializable, Cloneable { private LocalDateTime localDateTime; //region 初始化区域 + public DatePlus() { this.localDateTime = LocalDateTime.now(); } @@ -81,6 +79,7 @@ public DatePlus(String dateStr, DateTimeFormatter dateTimeFormatter) { } //region 添加属性值 + public DatePlus addYear(long year) { this.localDateTime = this.localDateTime.plusYears(year); return this; @@ -243,7 +242,7 @@ public DatePlus getLastDayOfYear() { } /** - * 获取这个月的最后一天 + * 获取这个月的第一天 * * @return 天 */ @@ -261,7 +260,7 @@ public DatePlus getFirstDayOfYear() { } /** - * 获取这个月的最后一天 + * 获取下个月的第一天 * * @return 天 */ @@ -290,6 +289,7 @@ public boolean isLeapYear() { } //region 属性的比较 + public boolean isBefore(DatePlus datePlus, DateType dateType) { boolean isBefore; switch (dateType) { @@ -345,7 +345,6 @@ public boolean isSame(DatePlus datePlus, DateType dateType) { break; } return isSame; - //return this.localDateTime.isEqual(datePlus.getLocalDateTime()); } public boolean isAfter(DatePlus datePlus, DateType dateType) { @@ -374,7 +373,6 @@ public boolean isAfter(DatePlus datePlus, DateType dateType) { break; } return isAfter; - //return this.localDateTime.isAfter(datePlus.getLocalDateTime()); } public long ofYear(DatePlus datePlus) { @@ -408,6 +406,7 @@ public long ofNanos(DatePlus datePlus) { public long ofDateTime(ChronoUnit chronoUnit, DatePlus datePlus) { return -chronoUnit.between(this.localDateTime, datePlus.localDateTime); } + //endregion @@ -469,7 +468,7 @@ public DatePlus toMaxDate(DateType dateType) { return this; } - public java.util.Date toDate() { + public Date toDate() { return ToolDatePlus.localDateTime2Date(this.localDateTime); } @@ -542,9 +541,17 @@ public String toString() { //region 生肖和星座 + + /** + * 生肖 + */ private static final String[] CHINESE_ZODIAC = {"猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"}; + /** + * 星座 + */ private static final String[] ZODIAC = {"水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座"}; private static final int[] ZODIAC_FLAGS = {20, 19, 21, 21, 21, 22, 23, 23, 23, 24, 23, 22}; + //endregion @Override diff --git a/common/src/main/java/pro/tools/time/DateType.java b/common/src/main/java/pro/tools/time/DateType.java index 6edda79..9513e42 100644 --- a/common/src/main/java/pro/tools/time/DateType.java +++ b/common/src/main/java/pro/tools/time/DateType.java @@ -1,11 +1,34 @@ package pro.tools.time; +/** + * 日期类型 + * + * @author SeanDragon + */ public enum DateType { + /** + * 年 + */ YEAR(1), + /** + * 月 + */ MONTH(2), + /** + * 日 + */ DAY(3), + /** + * 时 + */ HOUR(4), + /** + * 分 + */ MINUTES(5), + /** + * 秒 + */ SECONDS(6); private int mean; diff --git a/common/src/main/java/pro/tools/time/Lunar.java b/common/src/main/java/pro/tools/time/Lunar.java index 2ba50f5..ef5f813 100644 --- a/common/src/main/java/pro/tools/time/Lunar.java +++ b/common/src/main/java/pro/tools/time/Lunar.java @@ -2,6 +2,8 @@ /** * 农历 + * + * @author SeanDragon */ public class Lunar { private boolean isLeap; diff --git a/common/src/main/java/pro/tools/time/Solar.java b/common/src/main/java/pro/tools/time/Solar.java index 50da436..e63d303 100644 --- a/common/src/main/java/pro/tools/time/Solar.java +++ b/common/src/main/java/pro/tools/time/Solar.java @@ -2,6 +2,8 @@ /** * 公历 + * + * @author SeanDragon */ public class Solar { private int solarYear; diff --git a/common/src/main/java/pro/tools/time/ToolDatePlus.java b/common/src/main/java/pro/tools/time/ToolDatePlus.java index 6554f1d..873e84e 100644 --- a/common/src/main/java/pro/tools/time/ToolDatePlus.java +++ b/common/src/main/java/pro/tools/time/ToolDatePlus.java @@ -19,7 +19,7 @@ public final class ToolDatePlus { private ToolDatePlus() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } private static volatile ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); diff --git a/common/src/main/java/pro/tools/time/ToolLunar.java b/common/src/main/java/pro/tools/time/ToolLunar.java index c9ea674..b5c456a 100644 --- a/common/src/main/java/pro/tools/time/ToolLunar.java +++ b/common/src/main/java/pro/tools/time/ToolLunar.java @@ -7,7 +7,7 @@ */ public final class ToolLunar { private ToolLunar() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -59,9 +59,13 @@ private static int getBitInt(int data, int length, int shift) { /** * 从1582年10月开始算 * - * @param y 年 - * @param m 月 - * @param d 日 + * @param y + * 年 + * @param m + * 月 + * @param d + * 日 + * * @return 阳历 */ private static long solartoint(int y, int m, int d) { @@ -71,7 +75,9 @@ private static long solartoint(int y, int m, int d) { } /** - * @param lunarYear 农历年份 + * @param lunarYear + * 农历年份 + * * @return String of Ganzhi: 甲子年 Tiangan:甲乙丙丁戊己庚辛壬癸 * Dizhi: 子丑寅卯辰巳无为申酉戌亥 */ @@ -98,7 +104,9 @@ private static Solar solarfromint(long g) { /** * 农历转公历 * - * @param lunar 农历 + * @param lunar + * 农历 + * * @return 阴历 */ public static Solar lunartosolar(final Lunar lunar) { @@ -134,7 +142,9 @@ public static Solar lunartosolar(final Lunar lunar) { /** * 公历转农历 * - * @param solar 公历 + * @param solar + * 公历 + * * @return 阴历 */ public static Lunar solartolunar(final Solar solar) { diff --git a/common/src/test/java/decimal/TestDecimal.java b/common/src/test/java/decimal/TestDecimal.java deleted file mode 100644 index 7331568..0000000 --- a/common/src/test/java/decimal/TestDecimal.java +++ /dev/null @@ -1,89 +0,0 @@ -package decimal; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import pro.tools.data.decimal.Decimal; -import pro.tools.data.text.ToolJson; -import pro.tools.data.text.ToolRandoms; - -import java.math.MathContext; -import java.math.RoundingMode; -import java.time.LocalDateTime; - -@RunWith(JUnit4.class) -public class TestDecimal { - @Test(timeout = 1000) - public void test1() { - Decimal instance = Decimal.instance(1).div(3); - String s = instance.fullStrValue(); - instance.fullStrValue(2, RoundingMode.HALF_EVEN); - System.out.println(s); - } - - @Test - public void test2() { - LocalDateTime localDateTime = LocalDateTime.now(); - String localDateTimeStr = ToolJson.anyToJson(localDateTime); - System.out.println(localDateTimeStr); - LocalDateTime localDateTime1 = ToolJson.jsonToModel(localDateTimeStr, LocalDateTime.class); - System.out.println(localDateTime1); - } - - @Test - public void test3() { - String s = "{value: \"2017-11-24 18:55:24:373\"}"; - System.out.println(ToolJson.jsonToModel(s, LocalDateTime.class)); - } - - @Test(timeout = 2 * 60 * 1000) - public void test4() { - - String s = ""; - - for (int i = 0; i < 100000; i++) { - s = s.concat(ToolRandoms.getAuthCodeNumber(1)); - } - s = s.concat("."); - for (int i = 0; i < 100000; i++) { - s = s.concat(ToolRandoms.getAuthCodeNumber(1)); - } - - Decimal decimal1 = Decimal.instance(s, MathContext.UNLIMITED); - decimal1.sqrt2(100000); - - System.out.println(decimal1.fullStrValue()); - } - - @Test - public void test5() { - String authCodeAll = ToolRandoms.getAuthCodeAll(2); - System.out.println(authCodeAll); - - System.out.println(ToolRandoms.getAuthCodeAllChar()); - } - - @Test - public void test6() { - Decimal instance = Decimal.instance(3, MathContext.UNLIMITED); - Decimal sqrt2 = instance.sqrt2(10000); - System.out.println(sqrt2); - System.out.println(sqrt2.mul(sqrt2)); - } - - @Test - public void test7() { - Double loanAmountD = 4000D; - Double currentAmountD = 2000D; - - Decimal canBuyAmountD = Decimal.instance(loanAmountD).sub(currentAmountD); - - Decimal buyAfterAmountD = canBuyAmountD.clone().sub(2000); - - System.out.println(canBuyAmountD); - System.out.println(buyAfterAmountD); - - System.out.println(buyAfterAmountD.doubleValue() < 0.00D); - System.out.println(buyAfterAmountD.doubleValue() == 0.00D); - } -} diff --git a/common/src/test/java/file/TestBasic.java b/common/src/test/java/file/TestBasic.java deleted file mode 100644 index cda8f96..0000000 --- a/common/src/test/java/file/TestBasic.java +++ /dev/null @@ -1,158 +0,0 @@ -package file; - -import com.google.common.collect.Lists; -import org.junit.Test; -import org.omg.Messaging.SYNC_WITH_TRANSPORT; -import pro.tools.data.text.ToolJson; -import pro.tools.data.text.ToolRandoms; -import pro.tools.data.text.json.TypeBuilder; -import pro.tools.path.ToolPath; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * @author SeanDragon - *

- * Create By 2017-09-01 11:56 - */ -public class TestBasic { - - public static final String fileName = "d:/2.txt"; - public static final String dirName = "d:/2"; - - @Test - public void testFileIs() { - boolean file = ToolPath.isFile(fileName); - System.out.println(file); - boolean dir = ToolPath.isDir(fileName); - System.out.println(dir); - boolean exists = ToolPath.isExists(fileName); - System.out.println(exists); - boolean canWrite = ToolPath.canWrite(fileName); - System.out.println(canWrite); - boolean canRead = ToolPath.canRead(fileName); - System.out.println(canRead); - } - - @Test - public void testDirIs() { - boolean file = ToolPath.isFile(dirName); - System.out.println(file); - boolean dir = ToolPath.isDir(dirName); - System.out.println(dir); - boolean exists = ToolPath.isExists(dirName); - System.out.println(exists); - boolean canWrite = ToolPath.canWrite(dirName); - System.out.println(canWrite); - boolean canRead = ToolPath.canRead(dirName); - System.out.println(canRead); - } - - @Test - public void testCreateDir() throws IOException { - Path dir = ToolPath.createDir(Paths.get("d:/2"), true); - System.out.println(dir); - } - - @Test - public void testCreateFile() throws IOException { - Path file = ToolPath.createFile(Paths.get("d:/2"), true); - System.out.println(file); - } - - @Test - public void testMove() throws IOException { - Path move = ToolPath.move(Paths.get("d:/2"), Paths.get("c:/"), true); - System.out.println(move); - } - - @Test - public void testRmrDir() throws IOException { - ToolPath.rmr(Paths.get("d:/2")); - } - - @Test - public void testReNameFile() throws IOException { - Path path = ToolPath.reName(fileName, "2.txt"); - System.out.println(path); - } - - @Test - public void testReNameDir() throws IOException { - Path path = ToolPath.reName(dirName, "2"); - System.out.println(path); - } - - @Test - public void testGson() { - int count = 1000; - long begin = 0l; - List ddds = Lists.newArrayListWithCapacity(count); - for (; count > 0; count--) { - ddds.add(new DDD().setI(count).setS(ToolRandoms.getRandomStr())); - } - - System.out.println(ddds); - - String s = ToolJson.anyToJson(ddds); - - begin = System.currentTimeMillis(); - ArrayList arrayList = ToolJson.jsonToArrayList(s); - System.out.println(System.currentTimeMillis() - begin); - - begin = System.currentTimeMillis(); - List maps = ToolJson.jsonToMapList(s); - System.out.println(System.currentTimeMillis() - begin); - - begin = System.currentTimeMillis(); - List modelList = ToolJson.jsonToModelList(s, DDD.class); - System.out.println(System.currentTimeMillis() - begin); - - begin = System.currentTimeMillis(); - List any = ToolJson.jsonToAny(s - , TypeBuilder.newInstance(List.class) - .addTypeParam(DDD.class) - .build()); - System.out.println(System.currentTimeMillis() - begin); - - begin = System.currentTimeMillis(); - List mapList = ToolJson.anyToAny(s, TypeBuilder.newInstance(List.class).addTypeParam(Map.class).build()); - System.out.println(System.currentTimeMillis() - begin); - - begin = System.currentTimeMillis(); - ; - String newS = ToolJson.anyToAny(s, String.class); - System.out.println(System.currentTimeMillis() - begin); - - System.out.println(newS); - } - -} - -class DDD { - private Integer i; - private String s; - - public Integer getI() { - return i; - } - - public DDD setI(Integer i) { - this.i = i; - return this; - } - - public String getS() { - return s; - } - - public DDD setS(String s) { - this.s = s; - return this; - } -} \ No newline at end of file diff --git a/common/src/test/java/package-info.java b/common/src/test/java/package-info.java new file mode 100644 index 0000000..af10c3e --- /dev/null +++ b/common/src/test/java/package-info.java @@ -0,0 +1 @@ +// 该目录不为空时,删除此文件 \ No newline at end of file diff --git a/common/src/test/java/queue/MyQueue.java b/common/src/test/java/queue/MyQueue.java deleted file mode 100644 index 66d4d0b..0000000 --- a/common/src/test/java/queue/MyQueue.java +++ /dev/null @@ -1,82 +0,0 @@ -package queue; - -/** - * Created on 17/9/2 13:28 星期六. - * - * @author sd - */ -public class MyQueue { - - private int[] pQueue; - private int iQueueLen;//队列里面有多少元素 - private int iQueueCapacity;//初始化大小 - private int iHead; - private int iTail; - - public MyQueue(int capacity) { - this.iQueueCapacity = capacity; - this.pQueue = new int[capacity]; - clear(); - } - - /** - * 清空 - */ - public void clear() { - this.iHead = 0; - this.iTail = 0; - this.iQueueLen = 0; - } - - /** - * 判空 - * - * @return - */ - public boolean empty() { - return iQueueLen == 0; - } - - public boolean full() { - return iQueueLen == iQueueCapacity; - } - - /** - * 获取队列长度 - */ - public int length() { - return iQueueLen; - } - - - public boolean in(int element) { - if (full()) { - return false; - } - - this.pQueue[iTail] = element; - iTail = (++iTail) % iQueueCapacity; - iQueueLen++; - return true; - } - - public int out() { - if (empty()) { - throw new NullPointerException(""); - } - - int element = pQueue[iHead]; - iHead = (++iHead) % iQueueCapacity; - iQueueLen--; - return element; - } - - public void traverse() { - System.out.println(); - for (int i = iHead; i < pQueue.length + iHead; i++) { - System.out.println(pQueue[i % iQueueCapacity]); - } - System.out.println(); - } - -} diff --git a/common/src/test/java/queue/test/TestMyQueue.java b/common/src/test/java/queue/test/TestMyQueue.java deleted file mode 100644 index 2a020ce..0000000 --- a/common/src/test/java/queue/test/TestMyQueue.java +++ /dev/null @@ -1,92 +0,0 @@ -package queue.test; - -import org.junit.Test; -import pro.tools.system.ToolClassSearch; -import queue.MyQueue; - -import java.util.Set; -import java.util.concurrent.atomic.LongAdder; - -/** - * Created on 17/9/2 13:48 星期六. - * - * @author sd - */ -public class TestMyQueue { - - @Test - public void test2() { - LongAdder longAdder = new LongAdder(); - longAdder.increment(); - System.out.println(longAdder.longValue()); - longAdder.increment(); - System.out.println(longAdder.longValue()); - System.out.println(longAdder.sum()); - System.out.println(longAdder.toString()); - System.out.println(longAdder.longValue()); - - } - - @Test - public void test4() { - Set allClazz = ToolClassSearch.getAllClazz(); - System.out.println(allClazz); - } - - @Test - public void test3() { - - int A = Integer.MAX_VALUE; - int B = Integer.MAX_VALUE - 129; - - System.out.println(A); - System.out.println(B); - - A = A ^ B; - - B = A ^ B; - - A = A ^ B; - - System.out.println(A); - System.out.println(B); - - - A = A ^ B; - - B = A ^ B; - - A = A ^ B; - - - System.out.println(A); - System.out.println(B); - } - - @Test - public void test1() { - - MyQueue myQueue = new MyQueue(5); - myQueue.in(1); - myQueue.in(2); - myQueue.in(3); - myQueue.in(4); - myQueue.in(5); - - myQueue.traverse(); - - System.out.println(); - - System.out.println(myQueue.out()); - System.out.println(myQueue.out()); - System.out.println(myQueue.out()); - - System.out.println(); - - myQueue.traverse(); - - myQueue.clear(); - myQueue.in(6); - myQueue.traverse(); - } -} diff --git a/common/src/test/java/time/TestLocalDateTime.java b/common/src/test/java/time/TestLocalDateTime.java deleted file mode 100644 index 2887f4e..0000000 --- a/common/src/test/java/time/TestLocalDateTime.java +++ /dev/null @@ -1,82 +0,0 @@ -package time; - -import org.junit.Test; -import pro.tools.data.decimal.Decimal; -import pro.tools.data.text.ToolJson; -import pro.tools.time.DatePlus; -import pro.tools.time.DateType; - -import java.math.MathContext; -import java.time.LocalDate; -import java.time.LocalDateTime; - -/** - * @author SeanDragon - *

- * Create By 2017-10-26 19:38 - */ -public class TestLocalDateTime { - @Test - public void test1() { - LocalDateTime localDateTime = LocalDateTime.now(); - String x = ToolJson.anyToJson(localDateTime); - System.out.println(x); - LocalDateTime localDateTime1 = ToolJson.jsonToAny(x, LocalDateTime.class); - System.out.println(localDateTime1); - } - - @Test - public void test2() { - LocalDateTime localDateTime = LocalDateTime.now(); - System.out.println(ToolJson.anyToJson(localDateTime)); - String s = "2017-10-26 09:22:19:647"; - s = "{\"$timestamp\": \"2017-10-26 20:22:03:720\"}"; - LocalDateTime o = ToolJson.jsonToAny(s, LocalDateTime.class); - System.out.println(o); - } - - @Test - public void test3() { - LocalDate localDate = LocalDate.now(); - String x = ToolJson.anyToJson(localDate); - System.err.println(x); - LocalDate localDate1 = ToolJson.jsonToAny(x, LocalDate.class); - System.out.println(localDate1); - } - - @Test - public void test4() { - DatePlus datePlus = new DatePlus(); - System.out.println(datePlus); - String s = ToolJson.anyToJson(datePlus); - System.out.println(s); - DatePlus t = ToolJson.jsonToAny(s, DatePlus.class); - System.out.println(t); - } - - @Test - public void test5() { - DatePlus datePlus1 = new DatePlus(); - DatePlus datePlus2 = new DatePlus(); - - System.out.println(datePlus1); - System.out.println(datePlus2); - System.out.println(); - - boolean before = datePlus1.isBefore(datePlus2, DateType.SECONDS); - System.out.println(before); - boolean same = datePlus1.isSame(datePlus2, DateType.SECONDS); - System.out.println(same); - boolean after = datePlus1.isAfter(datePlus2, DateType.SECONDS); - System.out.println(after); - } - - @Test - public void test6() { - Decimal decimal = new Decimal(66.66, MathContext.UNLIMITED); - String x = ToolJson.anyToJson(decimal); - System.out.println(x); - Object o = ToolJson.jsonToAny(x, Decimal.class); - System.out.println(o); - } -} diff --git a/http/pom.xml b/http/pom.xml index b556d7f..ef10db8 100644 --- a/http/pom.xml +++ b/http/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - parent + protools pro.tools - 2.0 + 3.0 4.0.0 @@ -15,24 +15,24 @@ pro.tools common - 2.0 + ${project.version} io.netty netty-handler - 4.1.17.Final + ${netty.version} io.netty netty-codec-http - 4.1.17.Final + ${netty.version} com.ning async-http-client - 1.9.40 + ${com.ning.version} netty @@ -48,9 +48,14 @@ com.squareup.okhttp3 okhttp - 3.9.0 + ${okhttp.version} - + + 4.1.86.Final + 1.9.40 + 3.9.0 + + \ No newline at end of file diff --git a/http/src/main/java/pro/tools/http/jdk/ToolHttp.java b/http/src/main/java/pro/tools/http/jdk/ToolHttp.java index feb5ef2..9dee090 100644 --- a/http/src/main/java/pro/tools/http/jdk/ToolHttp.java +++ b/http/src/main/java/pro/tools/http/jdk/ToolHttp.java @@ -37,7 +37,7 @@ public final class ToolHttp { private static HttpBuilder builder = new HttpBuilder(); private ToolHttp() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } public static HttpReceive sendGet(String url) { diff --git a/http/src/main/java/pro/tools/http/netty/clientpool/DefaultClientPool.java b/http/src/main/java/pro/tools/http/netty/clientpool/DefaultClientPool.java index 48ea810..f7cab54 100644 --- a/http/src/main/java/pro/tools/http/netty/clientpool/DefaultClientPool.java +++ b/http/src/main/java/pro/tools/http/netty/clientpool/DefaultClientPool.java @@ -122,7 +122,6 @@ public HttpReceive request(HttpSend httpSend, long timeout, TimeUnit timeUnit) { Future fch = channelPool.acquire(); Channel channel = null; try { - // final Channel channel = fch.syncUninterruptibly().getNow(); channel = fch.get(timeout, timeUnit); ChannelPipeline p = channel.pipeline(); @@ -200,16 +199,6 @@ private FullHttpRequest convertRequest(HttpSend httpSend) { content.deleteCharAt(content.length() - 1); } - // URI sendURI; - // try { - // sendURI = new URI(queryStringEncoder.toString()); - // } catch (URISyntaxException e) { - // if (log.isWarnEnabled()) { - // log.warn(e.getMessage(), e); - // } - // throw new RuntimeException(e); - // } - final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1 , httpMethod , scheme + "://" + host + ":" + port + httpSend.getUrl() @@ -218,19 +207,6 @@ private FullHttpRequest convertRequest(HttpSend httpSend) { , Unpooled.copiedBuffer(content.toString().getBytes()) ); - // FIXME: 2017/7/27 暂未加Cookie - // if (cookies != null) { - // List cookieList = Lists.newArrayListWithCapacity(cookies.size()); - // cookies.forEach((key, value) -> { - // cookieList.add(new DefaultCookie(key, value)); - // }); - // - // request.headers().set( - // HttpHeaderNames.COOKIE, - // ClientCookieEncoder.STRICT.encode(cookieList) - // ); - // } - request.headers().add(DEFAULT_HTTP_HEADERS); if (headers != null) { headers.forEach((key, value) -> { diff --git a/http/src/main/java/pro/tools/http/netty/handler/HttpClientChannelPoolHandler.java b/http/src/main/java/pro/tools/http/netty/handler/HttpClientChannelPoolHandler.java index 5671a3d..33d2672 100644 --- a/http/src/main/java/pro/tools/http/netty/handler/HttpClientChannelPoolHandler.java +++ b/http/src/main/java/pro/tools/http/netty/handler/HttpClientChannelPoolHandler.java @@ -25,10 +25,9 @@ public HttpClientChannelPoolHandler(SslContext sslCtx) { @Override public void channelCreated(Channel channel) { - NioSocketChannel nioSocketChannel = (NioSocketChannel)channel; + NioSocketChannel nioSocketChannel = (NioSocketChannel) channel; nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true); - // final ChannelPipeline p = channel.pipeline(); final ChannelPipeline p = nioSocketChannel.pipeline(); //HTTPS diff --git a/http/src/main/java/pro/tools/http/netty/handler/HttpClientHandler.java b/http/src/main/java/pro/tools/http/netty/handler/HttpClientHandler.java index 9664371..da0fcb3 100644 --- a/http/src/main/java/pro/tools/http/netty/handler/HttpClientHandler.java +++ b/http/src/main/java/pro/tools/http/netty/handler/HttpClientHandler.java @@ -58,7 +58,6 @@ public void channelRead0(final ChannelHandlerContext ctx, final HttpObject msg) } else { if (log.isDebugEnabled()) { log.debug("#HTTP 内容开始{"); - // log.debug("}EOF#"); } } diff --git a/http/src/main/java/pro/tools/http/pojo/HttpDefaultHeaders.java b/http/src/main/java/pro/tools/http/pojo/HttpDefaultHeaders.java index 48212b2..830808e 100644 --- a/http/src/main/java/pro/tools/http/pojo/HttpDefaultHeaders.java +++ b/http/src/main/java/pro/tools/http/pojo/HttpDefaultHeaders.java @@ -10,23 +10,22 @@ * @author sd */ public class HttpDefaultHeaders { - private final static Map defaultHeaders; + private final static Map DEFAULT_HEADERS; static { - defaultHeaders = Maps.newHashMap(); + DEFAULT_HEADERS = Maps.newHashMap(); init(); } private static void init() { - defaultHeaders.put("connection", "keep-alive"); - defaultHeaders.put("accept-encoding", "gzip,deflate"); - // defaultHeaders.put("user-agent", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"); - defaultHeaders.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3191.0 Safari/537.36"); - defaultHeaders.put("DNT", 1); - defaultHeaders.put("cache-control", "max-age=0"); + DEFAULT_HEADERS.put("connection", "keep-alive"); + DEFAULT_HEADERS.put("accept-encoding", "gzip,deflate"); + DEFAULT_HEADERS.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3191.0 Safari/537.36"); + DEFAULT_HEADERS.put("DNT", 1); + DEFAULT_HEADERS.put("cache-control", "max-age=0"); } public static Map getDefaultHeaders() { - return defaultHeaders; + return DEFAULT_HEADERS; } } diff --git a/http/src/main/java/pro/tools/http/pojo/HttpMethod.java b/http/src/main/java/pro/tools/http/pojo/HttpMethod.java index 60c6c7c..a62983c 100644 --- a/http/src/main/java/pro/tools/http/pojo/HttpMethod.java +++ b/http/src/main/java/pro/tools/http/pojo/HttpMethod.java @@ -1,13 +1,43 @@ package pro.tools.http.pojo; +/** + * @author SeanDragon + */ public enum HttpMethod { + /** + * GET请求方式 + */ GET, + /** + * POST请求方式 + */ POST, + /** + * PUT请求方式 + */ PUT, + /** + * TRACE请求方式 + */ TRACE, + /** + * DELETE请求方式 + */ DELETE, + /** + * OPTIONS请求方式 + */ OPTIONS, + /** + * HEAD请求方式 + */ HEAD, + /** + * PATCH请求方式 + */ PATCH, + /** + * CONNECT请求方式 + */ CONNECT, } \ No newline at end of file diff --git a/http/src/main/test/http/TestNetty.java b/http/src/main/test/http/TestNetty.java deleted file mode 100644 index aed1e92..0000000 --- a/http/src/main/test/http/TestNetty.java +++ /dev/null @@ -1,64 +0,0 @@ -package http; - -import org.junit.Test; -import pro.tools.http.netty.clientpool.DefaultClientPool; -import pro.tools.http.pojo.HttpException; -import pro.tools.http.pojo.HttpMethod; -import pro.tools.http.pojo.HttpReceive; -import pro.tools.http.pojo.HttpSend; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author SeanDragon - *

- * Create By 2017-11-28 16:46 - */ -public class TestNetty { - static DefaultClientPool defaultClientPool; - - @Test - public void test1() throws HttpException { - defaultClientPool = new DefaultClientPool("http://localhost:92"); - - int count = 1000; - AtomicInteger finishCount = new AtomicInteger(); - AtomicInteger errCount = new AtomicInteger(); - AtomicInteger okCount = new AtomicInteger(); - - long begin = System.currentTimeMillis(); - for (int i = 0; i < count; i++) { - Thread newThread = new Thread(() -> { - HttpReceive receive = defaultClientPool.request(HttpSend.of("/getService").setMethod(HttpMethod.POST),10, TimeUnit.SECONDS); - // HttpReceive receive = ToolSendHttp.post("http://localhost:92/getService"); - Boolean haveError = receive.getHaveError(); - if (haveError || receive.getStatusCode() != 200) { - System.out.println(finishCount.incrementAndGet() + "-error"); - System.out.println(receive.getErrMsg()); - errCount.incrementAndGet(); - } else { - System.out.println(finishCount.incrementAndGet() + "-ok"); - okCount.incrementAndGet(); - } - }); - newThread.start(); - } - - while (finishCount.get() < count) ; - System.out.println("ERROR:\t\t" + errCount.get()); - System.out.println("OK:\t\t" + okCount.get()); - System.out.println("TIME:\t\t" + (System.currentTimeMillis() - begin) / 1000D + "秒"); - DefaultClientPool.stopAll(); - while (true); - } - - @Test - public void test2() { - StringBuilder stringBuilder = new StringBuilder("123123"); - stringBuilder.deleteCharAt(stringBuilder.length()-1); - - System.out.println(stringBuilder); - System.out.println(stringBuilder.toString()); - } -} diff --git a/http/src/main/test/http/TestURL.java b/http/src/main/test/http/TestURL.java deleted file mode 100644 index 8ecd361..0000000 --- a/http/src/main/test/http/TestURL.java +++ /dev/null @@ -1,165 +0,0 @@ -package http; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import org.junit.BeforeClass; -import org.junit.Test; -import pro.tools.constant.StrConst; -import pro.tools.data.text.ToolJson; -import pro.tools.http.netty.clientpool.DefaultClientPool; -import pro.tools.http.okhttp.ToolSendHttp; -import pro.tools.http.pojo.HttpException; -import pro.tools.http.pojo.HttpMethod; -import pro.tools.http.pojo.HttpReceive; -import pro.tools.http.pojo.HttpSend; - -import java.net.URLDecoder; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Created on 17/9/3 13:12 星期日. - * - * @author sd - */ -public class TestURL { - - @BeforeClass - public static void bc() { - map = ToolJson.jsonToMap("{\n" + - " \"Action\": \"2\",\n" + - " \"DelayTransfer\": \"\",\n" + - " \"LoanJsonList\": \"[{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200000\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200001\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200002\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200003\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200004\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200005\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200006\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200007\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200008\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"900.25\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200009\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000010\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000011\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000012\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000013\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000014\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000015\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000016\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000017\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000018\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000019\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"7001.94\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"p2015\\\",\\\"OrderNo\\\":\\\"20171120171302992842000020\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"1000.0\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"}]\",\n" + - " \"LoanJsonList1\": \"[{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200000\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200001\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200002\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200003\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200004\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200005\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200006\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200007\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200008\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"900.25\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200009\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000010\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000011\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000012\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000013\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000014\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000015\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000016\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000017\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000018\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000019\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"7001.94\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"p2015\\\",\\\"OrderNo\\\":\\\"20171120171302992842000020\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"1000.0\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"}]\",\n" + - " \"LoanJsonList2\": \"[{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200000\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200001\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200002\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200003\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200004\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200005\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200006\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200007\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200008\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"900.25\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200009\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000010\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000011\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000012\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000013\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000014\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000015\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000016\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000017\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000018\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000019\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"7001.94\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"p2015\\\",\\\"OrderNo\\\":\\\"20171120171302992842000020\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"1000.0\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"}]\",\n" + - " \"LoanJsonList3\": \"[{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200000\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200001\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200002\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200003\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200004\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200005\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200006\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200007\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200008\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"900.25\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200009\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000010\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000011\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000012\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000013\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000014\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000015\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000016\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000017\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000018\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000019\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"7001.94\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"p2015\\\",\\\"OrderNo\\\":\\\"20171120171302992842000020\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"1000.0\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"}]\",\n" + - " \"LoanJsonList4\": \"[{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200000\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200001\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200002\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200003\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200004\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200005\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200006\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200007\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200008\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"900.25\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"2017112017130299284200009\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000010\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000011\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000012\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000013\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000014\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000015\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000016\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000017\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"100.03\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000018\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"200.06\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"m121901\\\",\\\"OrderNo\\\":\\\"20171120171302992842000019\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"7001.94\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"},{\\\"LoanOutMoneymoremore\\\":\\\"m121906\\\",\\\"LoanInMoneymoremore\\\":\\\"p2015\\\",\\\"OrderNo\\\":\\\"20171120171302992842000020\\\",\\\"BatchNo\\\":\\\"171120_2\\\",\\\"ExchangeBatchNo\\\":\\\"\\\",\\\"AdvanceBatchNo\\\":\\\"\\\",\\\"Amount\\\":\\\"1000.0\\\",\\\"FullAmount\\\":\\\"10000.0\\\",\\\"TransferName\\\":\\\"2\\\",\\\"Remark\\\":\\\"\\\",\\\"SecondaryJsonList\\\":\\\"\\\"}]\",\n" + - " \"NeedAudit\": \"1\",\n" + - " \"NotifyURL\": \"http://47.94.168.101:83/admin/payPlatform/notify/repayNotify\",\n" + - " \"Remark1\": \"2\",\n" + - " \"Remark2\": \"84\",\n" + - " \"Remark3\": \"\",\n" + - " \"TransferAction\": \"2\",\n" + - " \"TransferType\": \"2\",\n" + - " \"orderNo\": \"20171120171302992842\"\n" + - "}"); - } - - @Test - public void test1() { - String url = "https://baidu.com"; - url = "http://192.168.15.100:92/getService"; - HttpSend httpSend = new HttpSend(url); - HttpReceive send = ToolSendHttp.send(httpSend); - System.out.println(send); - } - - @Test - public void test2() { - ByteBuf buffer = Unpooled.wrappedBuffer("123".getBytes()); - System.out.println(buffer.toString(StrConst.DEFAULT_CHARSET)); - } - - private volatile static Map map; - - @Test - public void test3() throws HttpException { - DefaultClientPool clientPool = new DefaultClientPool("http://192.168.15.22:8888"); - HttpSend httpSend = new HttpSend("/payPlatform/transferServlet"); - httpSend.setParams(map) - .setMethod(HttpMethod.POST); - - HttpReceive post = clientPool.request(httpSend); - - System.out.println(post.getHaveError()); - System.out.println(post.getResponseBody()); - System.out.println(post.getErrMsg()); - System.out.println(post.getStatusCode()); - - post = ToolSendHttp.post("http://192.168.15.22:8888/payPlatform/transferServlet", map); - - System.out.println(post.getHaveError()); - System.out.println(post.getResponseBody()); - System.out.println(post.getErrMsg()); - System.out.println(post.getStatusCode()); - } - - @Test - public void test4() throws Exception { - DefaultClientPool clientPool = new DefaultClientPool("http://localhost:9092"); - HttpSend httpSend = new HttpSend("/test"); - httpSend.setMethod(HttpMethod.POST); - httpSend.setParams(map); - - HttpReceive post = clientPool.request(httpSend); - //HttpReceive post = ToolSendHttp.post("http://localhost:9092/test", map); - - System.out.println(post.getHaveError()); - System.out.println(post.getResponseBody()); - System.out.println(post.getErrMsg()); - System.out.println(post.getStatusCode()); - } - - @Test - public void test5() { - String s = "dHKj71wpcLi8XeLO33T4Y5DoEYE3TjMPcn0tc21hNyJY4J5iOxnu2Fj3iq7xgjrkke3fYq7a6n3R\n" + - "6w8AEQfNxICdpKGCHp6WH67eHWdvR9ae/4j3flA36yq7qEYfszXX27I+sQmVj7fnYwg8R8CQlMwJ\n" + - "Iak4KAN03ggdJoYXpTI=\n"; - - ByteBuf byteBuf = Unpooled.copiedBuffer(s.getBytes()); - System.out.println(byteBuf.toString(StrConst.DEFAULT_CHARSET)); - - StringBuffer stringBuffer = new StringBuffer("123"); - String substring = stringBuffer.substring(0, stringBuffer.length() - 1); - System.out.println(substring); - } - - @Test - public void test6() throws Exception { - - String info = "R8Jgu2qcmomnUjeFDNnx6QQBTy6yIsQu1wFl9L7eCc4fWx3YxFSpDxZHgHg4i9FcblhWc3/L7EbZ\n" + - "w5Nwxm9SKSc2QFSSiOY0riEL57WLjzXdgQUQrzAIrypXN4GJGgSiGQ4oDf2lv3qInWqMIdGoFHSh\n" + - "KfmW8j80yIYzlW68fCQ=\n"; - - String request = "dHKj71wpcLi8XeLO33T4Y5DoEYE3TjMPcn0tc21hNyJY4J5iOxnu2Fj3iq7xgjrkke3fYq7a6n3R\n" + - "6w8AEQfNxICdpKGCHp6WH67eHWdvR9ae/4j3flA36yq7qEYfszXX27I+sQmVj7fnYwg8R8CQlMwJ\n" + - "Iak4KAN03ggdJoYXpTI=\n"; - - System.out.println(request); - String decode = URLDecoder.decode(request, StrConst.DEFAULT_CHARSET_NAME); - System.out.println(decode); -// -// String received = "dHKj71wpcLi8XeLO33T4Y5DoEYE3TjMPcn0tc21hNyJY4J5iOxnu2Fj3iq7xgjrkke3fYq7a6n3R\n" + -// "6w8AEQfNxICdpKGCHp6WH67eHWdvR9ae/4j3flA36yq7qEYfszXX27I sQmVj7fnYwg8R8CQlMwJ\n" + -// "Iak4KAN03ggdJoYXpTI=\n"; - - DefaultClientPool defaultClientPool = new DefaultClientPool("http://192.168.15.22:8888"); - - Map map = new LinkedHashMap<>(); -// String info = "C9C6ALCYDmivbo+eXz8ZRnLMPtXzpFiZTZKGD+K0EoA6gocrCbuofntyzPYlLwMbEUGHeZwRXvpS\n" + -// "xUuejkIwfCwpkUqAxZnbWwZJaWqZxJifz3kCnr2pR6gGppndU2B8xyOD7+CQAYGIfLK1zcVnWNEZ\n" + -// "r+gZvCFp3qee38a45BE="; - -// String info = "jWcKBkO4xGnm/MCD7s9txWXgWuxTEI0DYt6HRfQUk14QMUWJTcEgmN0hlqPjdNKBGpO sb8tNgRN\n" + -// "j5Du2K1zullre4VWd/2MezgQcvcsHJKallmhIalj iBRk868wdDy3vL36LsXNGWKmrqb32LrjhZ2\n" + -// "Yv2L1XpfGtm0tt oY8=\n"; - -// String info = "pSTIEx+Z9Y5E6CyHwz57XBJwhfKcQWTA5IWmLzTW/xNOjID9YWwTqk3EqaCj3nUEO1E7EPstBPPj\n" + -// "KOVJIENAEeriGdmHOCBF9miPuiT1gpDN812hzwRhFg3tGM7A7uqxG6KN3XsT95zSAsCoa4g967v6\n" + -// "N9vbPOU6OHdffhxObuA=\n"; - map.put("data", request); -// map.put("data", info); - -// HttpReceive post = ToolSendHttp.post("http://127.0.0.1:8888/payPlatform/balanceDecodeServlet", map); -// System.out.println("post:" + post.getResponseBody()); - - HttpSend httpSend = new HttpSend("/payPlatform/balanceDecodeServlet"); - httpSend.setParams(map).setMethod(HttpMethod.POST); - HttpReceive post1 = defaultClientPool.request(httpSend); - System.out.println("post1:" + post1.getResponseBody()); - -// HttpReceive httpReceive = ToolHttp.sendGet("http://127.0.0.1:8888/payPlatform/balanceDecodeServlet", map); -// System.err.println("infoResult:" + httpReceive.getResponseBody()); - - } -} diff --git a/http/src/test/java/package-info.java b/http/src/test/java/package-info.java new file mode 100644 index 0000000..af10c3e --- /dev/null +++ b/http/src/test/java/package-info.java @@ -0,0 +1 @@ +// 该目录不为空时,删除此文件 \ No newline at end of file diff --git a/mail/pom.xml b/mail/pom.xml index 1254e0d..692aab7 100644 --- a/mail/pom.xml +++ b/mail/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - parent + protools pro.tools - 2.0 + 3.0 4.0.0 @@ -15,15 +15,19 @@ pro.tools common - 2.0 + ${project.version} com.sun.mail javax.mail - 1.6.0 + ${mail.version} + + 1.6.0 + + \ No newline at end of file diff --git a/mail/src/main/java/pro/tools/mail/pojo/MailSend.java b/mail/src/main/java/pro/tools/mail/pojo/MailSend.java index c2c4a50..5f0105c 100644 --- a/mail/src/main/java/pro/tools/mail/pojo/MailSend.java +++ b/mail/src/main/java/pro/tools/mail/pojo/MailSend.java @@ -9,13 +9,21 @@ */ public class MailSend implements java.io.Serializable { - //接受方邮箱地址列表 + /** + * 接受方邮箱地址列表 + */ private List toList; - //标题 + /** + * 标题 + */ private String subject; - //内容 + /** + * 内容 + */ private String content; - //附件文件列表 + /** + * 附件文件列表 + */ private List attachFiles; diff --git a/mail/src/test/java/package-info.java b/mail/src/test/java/package-info.java new file mode 100644 index 0000000..af10c3e --- /dev/null +++ b/mail/src/test/java/package-info.java @@ -0,0 +1 @@ +// 该目录不为空时,删除此文件 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0bf9c58..4a4a4e7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,38 +6,41 @@ 4.0.0 pro.tools - parent - 2.0 + protools + 3.0 + protools + 历经开发周期两年,并且应用过千万级别项目的工具箱 + https://github.com/SeanDragon/protools + common mail http security - protools + all junit junit - 4.12 + ${junit.version} test + + org.projectlombok + lombok + 1.18.6 + pom - - http://www.tuhaolicai.cc/ - tuhao-team - - sd syl8023who@gmail.com SeanDragon - tuhao-team https://seandragon.github.io +8 @@ -46,13 +49,21 @@ Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt + https://raw.githubusercontent.com/SeanDragon/protools/master/LICENSE repo - + UTF-8 + 1.8 + 1.8 + + 4.13.1 + + 3.6.1 + 3.0.1 + 2.20 @@ -62,22 +73,21 @@ org.apache.maven.plugins maven-compiler-plugin - 3.6.1 + ${compile-plugin.version} - 1.8 - 1.8 - UTF-8 + ${maven.compiler.source} + ${maven.compiler.target} + ${project.build.sourceEncoding} true org.apache.maven.plugins maven-source-plugin - 3.0.1 + ${source-plugin.version} attach-sources - verify jar @@ -87,17 +97,48 @@ org.apache.maven.plugins maven-surefire-plugin - 2.20 + ${surefire-plugin.version} true once - -Dfile.encoding=UTF-8 + -Dfile.encoding=${project.build.sourceEncoding} maven-dependency-plugin + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + - \ No newline at end of file + + + scm:git:git@github.com:SeanDragon/protools.git + scm:git:git@github.com:SeanDragon/protools.git + git@github.com:SeanDragon/protools.git + v${project.version} + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + Maven Central Staging Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + diff --git a/security/pom.xml b/security/pom.xml index 1994b3c..780ce4f 100644 --- a/security/pom.xml +++ b/security/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - parent + protools pro.tools - 2.0 + 3.0 4.0.0 @@ -15,19 +15,23 @@ pro.tools common - 2.0 + ${project.version} org.bouncycastle bcprov-jdk15on - 1.58 + ${jdk15on.version} org.bouncycastle bcprov-ext-jdk15on - 1.58 + ${jdk15on.version} + + + 1.67 + \ No newline at end of file diff --git a/security/src/main/java/pro/tools/security/SecurityUrl.java b/security/src/main/java/pro/tools/security/SecurityUrl.java index a95e21d..2bf312a 100644 --- a/security/src/main/java/pro/tools/security/SecurityUrl.java +++ b/security/src/main/java/pro/tools/security/SecurityUrl.java @@ -22,7 +22,7 @@ public static String encode(String url, Charset charset) { } public static String encode(String url) { - return encode(url,StrConst.DEFAULT_CHARSET); + return encode(url, StrConst.DEFAULT_CHARSET); } public static String decode(String url, Charset charset) { diff --git a/security/src/main/java/pro/tools/security/ToolAES.java b/security/src/main/java/pro/tools/security/ToolAES.java index 243e9c3..37b7837 100644 --- a/security/src/main/java/pro/tools/security/ToolAES.java +++ b/security/src/main/java/pro/tools/security/ToolAES.java @@ -26,10 +26,12 @@ * Jurisdiction Policy Files, 下载包的readme.txt * 有安装说明。就是替换${JAVA_HOME}/jre/lib/security/ * 下面的local_policy.jar和US_export_policy.jar + * + * @author SeanDragon */ public final class ToolAES { private ToolAES() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -47,8 +49,11 @@ private ToolAES() { /** * 转换密钥 * - * @param key 二进制密钥 + * @param key + * 二进制密钥 + * * @return Key 密钥 + * * @throws Exception */ private static Key toKey(byte[] key) { @@ -61,18 +66,22 @@ private static Key toKey(byte[] key) { /** * 解密 * - * @param data 待解密数据 - * @param key 密钥 + * @param data + * 待解密数据 + * @param key + * 密钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { // 还原密钥 Key k = toKey(key); - /* + /* * 实例化 使用PKCS7Padding填充方式,按如下方式实现 Cipher.getInstance(CIPHER_ALGORITHM, "BC"); - */ + */ Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); // 初始化,设置为解密模式 @@ -85,19 +94,23 @@ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingExcept /** * 加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { // 还原密钥 Key k = toKey(key); - /* + /* * 实例化 使用PKCS7Padding填充方式,按如下方式实现 Cipher.getInstance(CIPHER_ALGORITHM, - * "BC"); - */ + * "BC"); + */ Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); // 初始化,设置为加密模式 @@ -111,15 +124,16 @@ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingExcept * 生成密钥
* * @return byte[] 二进制密钥 + * * @throws Exception */ public static byte[] initKey() throws NoSuchAlgorithmException { // 实例化 KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); - /* + /* * AES 要求密钥长度为 128位、192位或 256位 - */ + */ kg.init(256); // 生成秘密密钥 diff --git a/security/src/main/java/pro/tools/security/ToolBase64.java b/security/src/main/java/pro/tools/security/ToolBase64.java index 6255b38..171b04d 100644 --- a/security/src/main/java/pro/tools/security/ToolBase64.java +++ b/security/src/main/java/pro/tools/security/ToolBase64.java @@ -10,17 +10,19 @@ * Base64的加密解密 * * @author SeanDragon - * Create By 2017-04-20 14:43 + * Create By 2017-04-20 14:43 */ public final class ToolBase64 { private ToolBase64() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 功能:编码字符串 * - * @param data 源字符串 + * @param data + * 源字符串 + * * @return String */ public static String encode(String data) { @@ -30,7 +32,9 @@ public static String encode(String data) { /** * 功能:解码字符串 * - * @param data 源字符串 + * @param data + * 源字符串 + * * @return String */ public static String decode(String data) { @@ -40,7 +44,9 @@ public static String decode(String data) { /** * 功能:编码byte[] * - * @param data 源 + * @param data + * 源 + * * @return char[] */ public static char[] encode(byte[] data) { @@ -74,7 +80,9 @@ public static char[] encode(byte[] data) { /** * 功能:解码 * - * @param data 编码后的字符数组 + * @param data + * 编码后的字符数组 + * * @return byte[] */ public static byte[] decode(char[] data) { @@ -85,10 +93,6 @@ public static byte[] decode(char[] data) { --tempLen; // ignore non-valid chars and padding } } - // calculate required length: - // -- 3 bytes for every 4 valid base64 chars - // -- plus 2 bytes if there are 3 extra base64 chars, - // or plus 1 byte if there are 2 extra. int len = (tempLen / 4) * 3; if ((tempLen % 4) == 3) { @@ -100,27 +104,24 @@ public static byte[] decode(char[] data) { } byte[] out = new byte[len]; - int shift = 0; // # of excess bits stored in accum - int accum = 0; // excess bits + int shift = 0; + int accum = 0; int index = 0; - // we now go through the entire array (NOT using the 'tempLen' value) for (char aData : data) { int value = (aData > 255) ? -1 : codes[aData]; - if (value >= 0) { // skip over non-code - accum <<= 6; // bits shift up by 6 each time thru - shift += 6; // loop, with new bits being put in - accum |= value; // at the bottom. - if (shift >= 8) { // whenever there are 8 or more shifted in, - shift -= 8; // write them out (from the top, leaving any - out[index++] = // excess at the bottom for next iteration. - (byte) ((accum >> shift) & 0xff); + if (value >= 0) { + accum <<= 6; + shift += 6; + accum |= value; + if (shift >= 8) { + shift -= 8; + out[index++] = (byte) ((accum >> shift) & 0xff); } } } - // if there is STILL something wrong we just have to throw up now! if (index != out.length) { throw new Error("Miscalculated data length (wrote " + index + " instead of " + out.length + ")"); @@ -132,7 +133,8 @@ public static byte[] decode(char[] data) { /** * 功能:编码文件 * - * @param file 源文件 + * @param file + * 源文件 */ public static void encode(File file) throws IOException { if (!file.exists()) { @@ -147,7 +149,9 @@ public static void encode(File file) throws IOException { /** * 功能:解码文件。 * - * @param file 源文件 + * @param file + * 源文件 + * * @throws IOException */ public static void decode(File file) throws IOException { @@ -160,15 +164,9 @@ public static void decode(File file) throws IOException { } } - // - // code characters for values 0..63 - // private static char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" .toCharArray(); - // - // lookup table for converting base64 characters to value in range 0..63 - // private static byte[] codes = new byte[256]; static { diff --git a/security/src/main/java/pro/tools/security/ToolCertificate.java b/security/src/main/java/pro/tools/security/ToolCertificate.java index 0de52c5..0220050 100644 --- a/security/src/main/java/pro/tools/security/ToolCertificate.java +++ b/security/src/main/java/pro/tools/security/ToolCertificate.java @@ -22,10 +22,12 @@ /** * 证书组件 + * + * @author SeanDragon */ public final class ToolCertificate { private ToolCertificate() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -36,10 +38,15 @@ private ToolCertificate() { /** * 由KeyStore获得私钥 * - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return PrivateKey 私钥 + * * @throws Exception */ private static PrivateKey getPrivateKeyByKeyStore(String keyStorePath, String alias, String password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { @@ -55,8 +62,11 @@ private static PrivateKey getPrivateKeyByKeyStore(String keyStorePath, String al /** * 由Certificate获得公钥 * - * @param certificatePath 证书路径 + * @param certificatePath + * 证书路径 + * * @return PublicKey 公钥 + * * @throws Exception */ private static PublicKey getPublicKeyByCertificate(String certificatePath) throws CertificateException, IOException { @@ -72,8 +82,11 @@ private static PublicKey getPublicKeyByCertificate(String certificatePath) throw /** * 获得Certificate * - * @param certificatePath 证书路径 + * @param certificatePath + * 证书路径 + * * @return Certificate 证书 + * * @throws Exception */ private static Certificate getCertificate(String certificatePath) throws CertificateException, IOException { @@ -96,10 +109,15 @@ private static Certificate getCertificate(String certificatePath) throws Certifi /** * 获得Certificate * - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return Certificate 证书 + * * @throws Exception */ private static Certificate getCertificate(String keyStorePath, String alias, String password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { @@ -114,9 +132,13 @@ private static Certificate getCertificate(String keyStorePath, String alias, Str /** * 获得KeyStore * - * @param keyStorePath 密钥库路径 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param password + * 密码 + * * @return KeyStore 密钥库 + * * @throws Exception */ private static KeyStore getKeyStore(String keyStorePath, String password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { @@ -126,11 +148,17 @@ private static KeyStore getKeyStore(String keyStorePath, String password) throws /** * 私钥加密 * - * @param data 待加密数据 - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param data + * 待加密数据 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPrivateKey(byte[] data, String keyStorePath, String alias, String password) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, UnrecoverableKeyException, CertificateException, KeyStoreException, IOException { @@ -149,11 +177,17 @@ public static byte[] encryptByPrivateKey(byte[] data, String keyStorePath, Strin /** * 私钥解密 * - * @param data 待解密数据 - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param data + * 待解密数据 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPrivateKey(byte[] data, String keyStorePath, String alias, String password) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, UnrecoverableKeyException, CertificateException, KeyStoreException, IOException { @@ -172,9 +206,13 @@ public static byte[] decryptByPrivateKey(byte[] data, String keyStorePath, Strin /** * 公钥加密 * - * @param data 待加密数据 - * @param certificatePath 证书路径 + * @param data + * 待加密数据 + * @param certificatePath + * 证书路径 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPublicKey(byte[] data, String certificatePath) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, CertificateException, IOException { @@ -193,9 +231,13 @@ public static byte[] encryptByPublicKey(byte[] data, String certificatePath) thr /** * 公钥解密 * - * @param data 待解密数据 - * @param certificatePath 证书路径 + * @param data + * 待解密数据 + * @param certificatePath + * 证书路径 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPublicKey(byte[] data, String certificatePath) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, CertificateException, IOException { @@ -214,10 +256,15 @@ public static byte[] decryptByPublicKey(byte[] data, String certificatePath) thr /** * 签名 * - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return byte[] 签名 + * * @throws Exception */ public static byte[] sign(byte[] sign, String keyStorePath, String alias, String password) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException { @@ -242,10 +289,15 @@ public static byte[] sign(byte[] sign, String keyStorePath, String alias, String /** * 验证签名 * - * @param data 数据 - * @param sign 签名 - * @param certificatePath 证书路径 + * @param data + * 数据 + * @param sign + * 签名 + * @param certificatePath + * 证书路径 + * * @return boolean 验证通过为真 + * * @throws Exception */ public static boolean verify(byte[] data, byte[] sign, String certificatePath) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, CertificateException, IOException { diff --git a/security/src/main/java/pro/tools/security/ToolCertificate2.java b/security/src/main/java/pro/tools/security/ToolCertificate2.java index b05e4f3..522039c 100644 --- a/security/src/main/java/pro/tools/security/ToolCertificate2.java +++ b/security/src/main/java/pro/tools/security/ToolCertificate2.java @@ -22,10 +22,12 @@ /** * 证书组件 + * + * @author SeanDragon */ public final class ToolCertificate2 { private ToolCertificate2() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -41,10 +43,15 @@ private ToolCertificate2() { /** * 由KeyStore获得私钥 * - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return PrivateKey 私钥 + * * @throws Exception */ public static PrivateKey getPrivateKeyByKeyStore(String keyStorePath, String alias, String password) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, IOException, CertificateException { @@ -60,8 +67,11 @@ public static PrivateKey getPrivateKeyByKeyStore(String keyStorePath, String ali /** * 由Certificate获得公钥 * - * @param certificatePath 证书路径 + * @param certificatePath + * 证书路径 + * * @return PublicKey 公钥 + * * @throws Exception */ public static PublicKey getPublicKeyByCertificate(String certificatePath) throws CertificateException, IOException { @@ -77,8 +87,11 @@ public static PublicKey getPublicKeyByCertificate(String certificatePath) throws /** * 获得Certificate * - * @param certificatePath 证书路径 + * @param certificatePath + * 证书路径 + * * @return Certificate 证书 + * * @throws Exception */ private static X509Certificate getCertificate(String certificatePath) throws CertificateException, IOException { @@ -98,9 +111,13 @@ private static X509Certificate getCertificate(String certificatePath) throws Cer /** * 获得KeyStore * - * @param keyStorePath 密钥库路径 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param password + * 密码 + * * @return KeyStore 密钥库 + * * @throws Exception */ private static KeyStore getKeyStore(String keyStorePath, String password) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { @@ -120,11 +137,17 @@ private static KeyStore getKeyStore(String keyStorePath, String password) throws /** * 私钥加密 * - * @param data 待加密数据 - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param data + * 待加密数据 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPrivateKey(byte[] data, String keyStorePath, String alias, String password) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException, CertificateException { @@ -143,11 +166,17 @@ public static byte[] encryptByPrivateKey(byte[] data, String keyStorePath, Strin /** * 私钥解密 * - * @param data 待解密数据 - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param data + * 待解密数据 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPrivateKey(byte[] data, String keyStorePath, String alias, String password) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException, CertificateException { @@ -166,9 +195,13 @@ public static byte[] decryptByPrivateKey(byte[] data, String keyStorePath, Strin /** * 公钥加密 * - * @param data 待加密数据 - * @param certificatePath 证书路径 + * @param data + * 待加密数据 + * @param certificatePath + * 证书路径 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPublicKey(byte[] data, String certificatePath) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, CertificateException, IOException { @@ -187,9 +220,13 @@ public static byte[] encryptByPublicKey(byte[] data, String certificatePath) thr /** * 公钥解密 * - * @param data 待解密数据 - * @param certificatePath 证书路径 + * @param data + * 待解密数据 + * @param certificatePath + * 证书路径 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPublicKey(byte[] data, String certificatePath) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, CertificateException, IOException { @@ -208,10 +245,15 @@ public static byte[] decryptByPublicKey(byte[] data, String certificatePath) thr /** * 签名 * - * @param keyStorePath 密钥库路径 - * @param alias 别名 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param alias + * 别名 + * @param password + * 密码 + * * @return byte[] 签名 + * * @throws Exception */ public static byte[] sign(byte[] sign, String keyStorePath, String alias, String password, String certificatePath) throws CertificateException, IOException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, InvalidKeyException, SignatureException { @@ -236,10 +278,15 @@ public static byte[] sign(byte[] sign, String keyStorePath, String alias, String /** * 验证签名 * - * @param data 数据 - * @param sign 签名 - * @param certificatePath 证书路径 + * @param data + * 数据 + * @param sign + * 签名 + * @param certificatePath + * 证书路径 + * * @return boolean 验证通过为真 + * * @throws Exception */ public static boolean verify(byte[] data, byte[] sign, String certificatePath) throws CertificateException, IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { diff --git a/security/src/main/java/pro/tools/security/ToolDES.java b/security/src/main/java/pro/tools/security/ToolDES.java index 3334596..da64ab4 100644 --- a/security/src/main/java/pro/tools/security/ToolDES.java +++ b/security/src/main/java/pro/tools/security/ToolDES.java @@ -16,11 +16,13 @@ /** * DES安全编码组件 + * + * @author SeanDragon */ public final class ToolDES { private ToolDES() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -38,8 +40,11 @@ private ToolDES() { /** * 转换密钥 * - * @param key 二进制密钥 + * @param key + * 二进制密钥 + * * @return Key 密钥 + * * @throws Exception */ private static Key toKey(byte[] key) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException { @@ -59,9 +64,13 @@ private static Key toKey(byte[] key) throws InvalidKeyException, NoSuchAlgorithm /** * 解密 * - * @param data 待解密数据 - * @param key 密钥 + * @param data + * 待解密数据 + * @param key + * 密钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException { @@ -82,9 +91,13 @@ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchAlgorithmExce /** * 加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException { @@ -108,21 +121,19 @@ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchAlgorithmExce * Bouncy Castle 支持64bit密钥
* * @return byte[] 二进制密钥 + * * @throws Exception */ public static byte[] initKey() throws NoSuchAlgorithmException { - /* - * 实例化密钥生成器 - * - * 若要使用64bit密钥注意替换 将下述代码中的KeyGenerator.getInstance(CIPHER_ALGORITHM); - * 替换为KeyGenerator.getInstance(CIPHER_ALGORITHM, "BC"); - */ + /* + 实例化密钥生成器 + 若要使用64bit密钥注意替换 将下述代码中的KeyGenerator.getInstance(CIPHER_ALGORITHM); + 替换为KeyGenerator.getInstance(CIPHER_ALGORITHM, "BC"); + */ KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); - /* - * 初始化密钥生成器 若要使用64bit密钥注意替换 将下述代码kg.init(56); 替换为kg.init(64); - */ + /*初始化密钥生成器 若要使用64bit密钥注意替换 将下述代码kg.init(56); 替换为kg.init(64);*/ kg.init(56, new SecureRandom()); // 生成秘密密钥 diff --git a/security/src/main/java/pro/tools/security/ToolDESede.java b/security/src/main/java/pro/tools/security/ToolDESede.java index df9cbf1..4a4dc02 100644 --- a/security/src/main/java/pro/tools/security/ToolDESede.java +++ b/security/src/main/java/pro/tools/security/ToolDESede.java @@ -15,10 +15,12 @@ /** * DESede安全编码组件 + * + * @author SeanDragon */ public final class ToolDESede { private ToolDESede() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -35,8 +37,11 @@ private ToolDESede() { /** * 转换密钥 * - * @param key 二进制密钥 + * @param key + * 二进制密钥 + * * @return Key 密钥 + * * @throws Exception */ private static Key toKey(byte[] key) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException { @@ -56,9 +61,13 @@ private static Key toKey(byte[] key) throws InvalidKeyException, NoSuchAlgorithm /** * 解密 * - * @param data 待解密数据 - * @param key 密钥 + * @param data + * 待解密数据 + * @param key + * 密钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException { @@ -66,9 +75,9 @@ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchAlgorithmExce // 还原密钥 Key k = toKey(key); - /* + /* * 实例化 使用PKCS7Padding填充方式 Cipher.getInstance(CIPHER_ALGORITHM, "BC"); - */ + */ Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); // 初始化,设置为解密模式 @@ -81,9 +90,13 @@ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchAlgorithmExce /** * 加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException { @@ -91,9 +104,9 @@ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchAlgorithmExce // 还原密钥 Key k = toKey(key); - /* + /* * 实例化 使用PKCS7Padding填充方式 Cipher.getInstance(CIPHER_ALGORITHM, "BC"); - */ + */ Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); // 初始化,设置为加密模式 @@ -107,6 +120,7 @@ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchAlgorithmExce * 生成密钥
* * @return byte[] 二进制密钥 + * * @throws Exception */ public static byte[] initKey() throws NoSuchAlgorithmException { @@ -114,9 +128,9 @@ public static byte[] initKey() throws NoSuchAlgorithmException { // 实例化 KeyGenerator kg = KeyGenerator.getInstance(KEY_ALGORITHM); - /* + /* * DESede 要求密钥长度为 112位或168位 - */ + */ kg.init(168); // 生成秘密密钥 diff --git a/security/src/main/java/pro/tools/security/ToolDH.java b/security/src/main/java/pro/tools/security/ToolDH.java index e5ad0e3..312be8e 100644 --- a/security/src/main/java/pro/tools/security/ToolDH.java +++ b/security/src/main/java/pro/tools/security/ToolDH.java @@ -28,10 +28,12 @@ /** * DH安全编码组件 + * + * @author SeanDragon */ public final class ToolDH { private ToolDH() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -65,6 +67,7 @@ private ToolDH() { * 初始化甲方密钥 * * @return Map 甲方密钥Map + * * @throws Exception */ public static Map initKey() throws NoSuchAlgorithmException { @@ -96,8 +99,11 @@ public static Map initKey() throws NoSuchAlgorithmException { /** * 初始化乙方密钥 * - * @param key 甲方公钥 + * @param key + * 甲方公钥 + * * @return Map 乙方密钥Map + * * @throws Exception */ public static Map initKey(byte[] key) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException { @@ -142,9 +148,13 @@ public static Map initKey(byte[] key) throws NoSuchAlgorithmExce /** * 加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -163,9 +173,13 @@ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingExcept /** * 解密
* - * @param data 待解密数据 - * @param key 密钥 + * @param data + * 待解密数据 + * @param key + * 密钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -184,9 +198,13 @@ public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingExcept /** * 构建密钥 * - * @param publicKey 公钥 - * @param privateKey 私钥 + * @param publicKey + * 公钥 + * @param privateKey + * 私钥 + * * @return byte[] 本地密钥 + * * @throws Exception */ public static byte[] getSecretKey(byte[] publicKey, byte[] privateKey) throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException { @@ -225,8 +243,11 @@ public static byte[] getSecretKey(byte[] publicKey, byte[] privateKey) throws In /** * 取得私钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 私钥 + * * @throws Exception */ public static byte[] getPrivateKey(Map keyMap) { @@ -239,8 +260,11 @@ public static byte[] getPrivateKey(Map keyMap) { /** * 取得公钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 公钥 + * * @throws Exception */ public static byte[] getPublicKey(Map keyMap) { diff --git a/security/src/main/java/pro/tools/security/ToolDSA.java b/security/src/main/java/pro/tools/security/ToolDSA.java index b7d68b8..0e0c18a 100644 --- a/security/src/main/java/pro/tools/security/ToolDSA.java +++ b/security/src/main/java/pro/tools/security/ToolDSA.java @@ -22,10 +22,12 @@ /** * DSA安全编码组件 + * + * @author SeanDragon */ public final class ToolDSA { private ToolDSA() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -56,9 +58,13 @@ private ToolDSA() { /** * 签名 * - * @param data 待签名数据 - * @param privateKey 私钥 + * @param data + * 待签名数据 + * @param privateKey + * 私钥 + * * @return byte[] 数字签名 + * * @throws Exception */ public static byte[] sign(byte[] data, byte[] privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException { @@ -88,10 +94,15 @@ public static byte[] sign(byte[] data, byte[] privateKey) throws NoSuchAlgorithm /** * 校验 * - * @param data 待校验数据 - * @param publicKey 公钥 - * @param sign 数字签名 + * @param data + * 待校验数据 + * @param publicKey + * 公钥 + * @param sign + * 数字签名 + * * @return boolean 校验成功返回true 失败返回false + * * @throws Exception */ public static boolean verify(byte[] data, byte[] publicKey, byte[] sign) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException { @@ -122,6 +133,7 @@ public static boolean verify(byte[] data, byte[] publicKey, byte[] sign) throws * 生成密钥 * * @return 密钥对象 + * * @throws Exception */ public static Map initKey() throws NoSuchAlgorithmException { @@ -150,8 +162,11 @@ public static Map initKey() throws NoSuchAlgorithmException { /** * 取得私钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 私钥 + * * @throws Exception */ public static byte[] getPrivateKey(Map keyMap) { @@ -162,8 +177,11 @@ public static byte[] getPrivateKey(Map keyMap) { /** * 取得公钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 公钥 + * * @throws Exception */ public static byte[] getPublicKey(Map keyMap) { diff --git a/security/src/main/java/pro/tools/security/ToolECDSA.java b/security/src/main/java/pro/tools/security/ToolECDSA.java index db0aca7..6823087 100644 --- a/security/src/main/java/pro/tools/security/ToolECDSA.java +++ b/security/src/main/java/pro/tools/security/ToolECDSA.java @@ -30,10 +30,12 @@ /** * ECDSA安全编码组件 + * + * @author SeanDragon */ public final class ToolECDSA { private ToolECDSA() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -69,6 +71,7 @@ private ToolECDSA() { * 初始化密钥 * * @return Map 密钥Map + * * @throws Exception */ public static Map initKey() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { @@ -120,8 +123,11 @@ public static Map initKey() throws NoSuchAlgorithmException, Inv /** * 取得私钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 私钥 + * * @throws Exception */ public static byte[] getPrivateKey(Map keyMap) { @@ -132,8 +138,11 @@ public static byte[] getPrivateKey(Map keyMap) { /** * 取得公钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 公钥 + * * @throws Exception */ public static byte[] getPublicKey(Map keyMap) { @@ -144,9 +153,13 @@ public static byte[] getPublicKey(Map keyMap) { /** * 签名 * - * @param data 待签名数据 - * @param privateKey 私钥 + * @param data + * 待签名数据 + * @param privateKey + * 私钥 + * * @return byte[] 数字签名 + * * @throws Exception */ public static byte[] sign(byte[] data, byte[] privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException { @@ -178,10 +191,15 @@ public static byte[] sign(byte[] data, byte[] privateKey) throws NoSuchAlgorithm /** * 校验 * - * @param data 待校验数据 - * @param publicKey 公钥 - * @param sign 数字签名 + * @param data + * 待校验数据 + * @param publicKey + * 公钥 + * @param sign + * 数字签名 + * * @return boolean 校验成功返回true 失败返回false + * * @throws Exception */ public static boolean verify(byte[] data, byte[] publicKey, byte[] sign) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException { diff --git a/security/src/main/java/pro/tools/security/ToolElGamal.java b/security/src/main/java/pro/tools/security/ToolElGamal.java index 98c7fcc..3deed4b 100644 --- a/security/src/main/java/pro/tools/security/ToolElGamal.java +++ b/security/src/main/java/pro/tools/security/ToolElGamal.java @@ -29,10 +29,12 @@ /** * ElGamal安全编码组件 + * + * @author SeanDragon */ public final class ToolElGamal { private ToolElGamal() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -60,9 +62,13 @@ private ToolElGamal() { /** * 用私钥解密 * - * @param data 待解密数据 - * @param key 私钥 + * @param data + * 待解密数据 + * @param key + * 私钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -89,9 +95,13 @@ public static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws NoSuchA /** * 用公钥加密 * - * @param data 待加密数据 - * @param key 公钥 + * @param data + * 待加密数据 + * @param key + * 公钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPublicKey(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -119,6 +129,7 @@ public static byte[] encryptByPublicKey(byte[] data, byte[] key) throws NoSuchAl * 生成密钥 * * @return Map 密钥Map + * * @throws Exception */ public static Map initKey() throws NoSuchAlgorithmException, InvalidParameterSpecException, InvalidAlgorithmParameterException { @@ -164,8 +175,11 @@ public static Map initKey() throws NoSuchAlgorithmException, Inv /** * 取得私钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 私钥 + * * @throws Exception */ public static byte[] getPrivateKey(Map keyMap) { @@ -177,7 +191,9 @@ public static byte[] getPrivateKey(Map keyMap) { * 取得公钥 * * @param keyMap + * * @return + * * @throws Exception */ public static byte[] getPublicKey(Map keyMap) { diff --git a/security/src/main/java/pro/tools/security/ToolHTTPS.java b/security/src/main/java/pro/tools/security/ToolHTTPS.java index fe59ca0..37a6ba5 100644 --- a/security/src/main/java/pro/tools/security/ToolHTTPS.java +++ b/security/src/main/java/pro/tools/security/ToolHTTPS.java @@ -17,10 +17,12 @@ /** * HTTPS组件 + * + * @author SeanDragon */ public final class ToolHTTPS { private ToolHTTPS() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -31,9 +33,13 @@ private ToolHTTPS() { /** * 获得KeyStore * - * @param keyStorePath 密钥库路径 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param password + * 密码 + * * @return KeyStore 密钥库 + * * @throws Exception */ static KeyStore getKeyStore(String keyStorePath, String password) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { @@ -56,10 +62,15 @@ static KeyStore getKeyStore(String keyStorePath, String password) throws KeyStor /** * 获得SSLSocektFactory * - * @param password 密码 - * @param keyStorePath 密钥库路径 - * @param trustStorePath 信任库路径 + * @param password + * 密码 + * @param keyStorePath + * 密钥库路径 + * @param trustStorePath + * 信任库路径 + * * @return SSLSocketFactory + * * @throws Exception */ static SSLSocketFactory getSSLSocketFactory(String password, String keyStorePath, String trustStorePath) throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, UnrecoverableKeyException, KeyManagementException { @@ -97,10 +108,15 @@ static SSLSocketFactory getSSLSocketFactory(String password, String keyStorePath /** * 为HttpsURLConnection配置SSLSocketFactory * - * @param conn HttpsURLConnection - * @param password 密码 - * @param keyStorePath 密钥库路径 - * @param trustKeyStorePath 信任库路径 + * @param conn + * HttpsURLConnection + * @param password + * 密码 + * @param keyStorePath + * 密钥库路径 + * @param trustKeyStorePath + * 信任库路径 + * * @throws Exception */ public static void configSSLSocketFactory(HttpsURLConnection conn, String password, String keyStorePath, diff --git a/security/src/main/java/pro/tools/security/ToolHTTPS2.java b/security/src/main/java/pro/tools/security/ToolHTTPS2.java index 556fb9c..ccae7bc 100644 --- a/security/src/main/java/pro/tools/security/ToolHTTPS2.java +++ b/security/src/main/java/pro/tools/security/ToolHTTPS2.java @@ -13,25 +13,30 @@ /** * HTTPS组件 + * + * @author SeanDragon */ public final class ToolHTTPS2 { private ToolHTTPS2() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 获得KeyStore * - * @param keyStorePath 密钥库路径 - * @param password 密码 + * @param keyStorePath + * 密钥库路径 + * @param password + * 密码 + * * @return KeyStore 密钥库 + * * @throws Exception */ private static KeyStore getKeyStore(String keyStorePath, String password) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { // 实例化密钥库 KeyStore ks = KeyStore.getInstance("PKCS12"); - // KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); // 获得密钥库文件流 FileInputStream is = new FileInputStream(keyStorePath); @@ -48,10 +53,15 @@ private static KeyStore getKeyStore(String keyStorePath, String password) throws /** * 获得SSLSocektFactory * - * @param password 密码 - * @param keyStorePath 密钥库路径 - * @param trustStorePath 信任库路径 + * @param password + * 密码 + * @param keyStorePath + * 密钥库路径 + * @param trustStorePath + * 信任库路径 + * * @return SSLSocketFactory + * * @throws Exception */ private static SSLSocketFactory getSSLSocketFactory(String password, String keyStorePath, String trustStorePath) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException { @@ -61,10 +71,15 @@ private static SSLSocketFactory getSSLSocketFactory(String password, String keyS /** * 为HttpsURLConnection配置SSLSocketFactory * - * @param conn HttpsURLConnection - * @param password 密码 - * @param keyStorePath 密钥库路径 - * @param trustKeyStorePath 信任库路径 + * @param conn + * HttpsURLConnection + * @param password + * 密码 + * @param keyStorePath + * 密钥库路径 + * @param trustKeyStorePath + * 信任库路径 + * * @throws Exception */ public static void configSSLSocketFactory(HttpsURLConnection conn, String password, String keyStorePath, diff --git a/security/src/main/java/pro/tools/security/ToolIDEA.java b/security/src/main/java/pro/tools/security/ToolIDEA.java index e05c784..92a8e4c 100644 --- a/security/src/main/java/pro/tools/security/ToolIDEA.java +++ b/security/src/main/java/pro/tools/security/ToolIDEA.java @@ -20,10 +20,12 @@ * IDEA安全编码组件 *

* 国际数据加密标准---IDEA:完全是新突破,几乎同时和AES出现 + * + * @author SeanDragon */ public final class ToolIDEA { private ToolIDEA() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -44,8 +46,11 @@ private ToolIDEA() { /** * 转换密钥 * - * @param key 二进制密钥 + * @param key + * 二进制密钥 + * * @return Key 密钥 + * * @throws Exception */ private static Key toKey(byte[] key) { @@ -58,9 +63,13 @@ private static Key toKey(byte[] key) { /** * 解密 * - * @param data 待解密数据 - * @param key 密钥 + * @param data + * 待解密数据 + * @param key + * 密钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decrypt(byte[] data, byte[] key) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException { @@ -80,9 +89,13 @@ public static byte[] decrypt(byte[] data, byte[] key) throws InvalidKeyException /** * 加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -103,6 +116,7 @@ public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingExcept * 生成密钥
* * @return byte[] 二进制密钥 + * * @throws Exception */ public static byte[] initKey() throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/ToolPBE.java b/security/src/main/java/pro/tools/security/ToolPBE.java index c9cbaa4..05989b7 100644 --- a/security/src/main/java/pro/tools/security/ToolPBE.java +++ b/security/src/main/java/pro/tools/security/ToolPBE.java @@ -20,10 +20,12 @@ *

* 基于口令的加密---PBE:前面的对称加密几乎如出一辙,流程基本一致,PBE综合了对称加密和消息摘要算法的优势,形成对称加密算法的一个特例。没有密钥的概念 * ,使用口令代替密钥 + * + * @author SeanDragon */ public final class ToolPBE { private ToolPBE() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -59,6 +61,7 @@ private ToolPBE() { * 盐长度必须为8字节 * * @return byte[] 盐 + * * @throws Exception */ public static byte[] initSalt() { @@ -69,8 +72,11 @@ public static byte[] initSalt() { /** * 转换密钥 * - * @param password 密码 + * @param password + * 密码 + * * @return Key 密钥 + * * @throws Exception */ private static Key toKey(String password) throws NoSuchAlgorithmException, InvalidKeySpecException { @@ -89,10 +95,15 @@ private static Key toKey(String password) throws NoSuchAlgorithmException, Inval /** * 加密 * - * @param data 数据 - * @param password 密码 - * @param salt 盐 + * @param data + * 数据 + * @param password + * 密码 + * @param salt + * 盐 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encrypt(byte[] data, String password, byte[] salt) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -117,10 +128,15 @@ public static byte[] encrypt(byte[] data, String password, byte[] salt) throws I /** * 解密 * - * @param data 数据 - * @param password 密码 - * @param salt 盐 + * @param data + * 数据 + * @param password + * 密码 + * @param salt + * 盐 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decrypt(byte[] data, String password, byte[] salt) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { diff --git a/security/src/main/java/pro/tools/security/ToolPBE2.java b/security/src/main/java/pro/tools/security/ToolPBE2.java index 32f8905..4338070 100644 --- a/security/src/main/java/pro/tools/security/ToolPBE2.java +++ b/security/src/main/java/pro/tools/security/ToolPBE2.java @@ -16,7 +16,7 @@ */ public final class ToolPBE2 { private ToolPBE2() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } private static final String PBKDF2_ALGORITHM = "PBKDF2WithHmacSHA1"; @@ -39,26 +39,35 @@ private ToolPBE2() { /** * 对输入的密码进行验证 * - * @param attemptedPassword 待验证的密码 - * @param encryptedPassword 密文 - * @param salt 盐值 + * @param attemptedPassword + * 待验证的密码 + * @param encryptedPassword + * 密文 + * @param salt + * 盐值 + * * @return 是否验证成功 + * * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ public static boolean authenticate(String attemptedPassword, String encryptedPassword, String salt) throws InvalidKeySpecException, NoSuchAlgorithmException { - // 用相同的盐值对用户输入的密码进行加密 + // 用相同的盐值对用户输入的密码进行加密 String encryptedAttemptedPassword = getEncryptedPassword(attemptedPassword, salt); - // 把加密后的密文和原密文进行比较,相同则验证成功,否则失败 + // 把加密后的密文和原密文进行比较,相同则验证成功,否则失败 return encryptedAttemptedPassword.equals(encryptedPassword); } /** * 生成密文 * - * @param password 明文密码 - * @param salt 盐值 + * @param password + * 明文密码 + * @param salt + * 盐值 + * * @return + * * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ @@ -73,6 +82,7 @@ public static String getEncryptedPassword(String password, String salt) throws N * 通过提供加密的强随机数生成器 生成盐 * * @return + * * @throws NoSuchAlgorithmException */ public static String generateSalt() throws NoSuchAlgorithmException { @@ -85,7 +95,9 @@ public static String generateSalt() throws NoSuchAlgorithmException { /** * 十六进制字符串转二进制字符串 * - * @param hex the hex string + * @param hex + * the hex string + * * @return the hex string decoded into a byte array */ private static byte[] fromHex(String hex) { @@ -99,16 +111,19 @@ private static byte[] fromHex(String hex) { /** * 二进制字符串转十六进制字符串 * - * @param array the byte array to ToolJson + * @param array + * the byte array to ToolJson + * * @return a length*2 character string encoding the byte array */ private static String toHex(byte[] array) { BigInteger bi = new BigInteger(1, array); String hex = bi.toString(16); int paddingLength = (array.length * 2) - hex.length(); - if (paddingLength > 0) + if (paddingLength > 0) { return String.format("%0" + paddingLength + "d", 0) + hex; - else + } else { return hex; + } } } \ No newline at end of file diff --git a/security/src/main/java/pro/tools/security/ToolPbkdf2.java b/security/src/main/java/pro/tools/security/ToolPbkdf2.java index 162c234..f0a7cc1 100644 --- a/security/src/main/java/pro/tools/security/ToolPbkdf2.java +++ b/security/src/main/java/pro/tools/security/ToolPbkdf2.java @@ -20,10 +20,12 @@ * 2.当认证用户的时候,从数据库中取出盐和密文,将他们和明文密码同时传给authenticate(),根据返回结果判断是否认证成功。 *

* 3.当用户修改密码的时候,仍然可以使用原来的盐,只需要调用getEncryptedPassword()方法重新生成密文就可以了。 + * + * @author SeanDragon */ public final class ToolPbkdf2 { private ToolPbkdf2() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } public static boolean authenticate(String attemptedPassword, byte[] encryptedPassword, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException { diff --git a/security/src/main/java/pro/tools/security/ToolRSA.java b/security/src/main/java/pro/tools/security/ToolRSA.java index e22201d..70e8b60 100644 --- a/security/src/main/java/pro/tools/security/ToolRSA.java +++ b/security/src/main/java/pro/tools/security/ToolRSA.java @@ -23,11 +23,12 @@ /** * RSA安全编码组件 + * * @author SeanDragon */ public final class ToolRSA { private ToolRSA() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** @@ -53,9 +54,13 @@ private ToolRSA() { /** * 私钥解密 * - * @param data 待解密数据 - * @param key 私钥 + * @param data + * 待解密数据 + * @param key + * 私钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -78,9 +83,13 @@ public static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws NoSuchA /** * 公钥解密 * - * @param data 待解密数据 - * @param key 公钥 + * @param data + * 待解密数据 + * @param key + * 公钥 + * * @return byte[] 解密数据 + * * @throws Exception */ public static byte[] decryptByPublicKey(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -104,9 +113,13 @@ public static byte[] decryptByPublicKey(byte[] data, byte[] key) throws NoSuchAl /** * 公钥加密 * - * @param data 待加密数据 - * @param key 公钥 + * @param data + * 待加密数据 + * @param key + * 公钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPublicKey(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -128,9 +141,13 @@ public static byte[] encryptByPublicKey(byte[] data, byte[] key) throws NoSuchAl /** * 私钥加密 * - * @param data 待加密数据 - * @param key 私钥 + * @param data + * 待加密数据 + * @param key + * 私钥 + * * @return byte[] 加密数据 + * * @throws Exception */ public static byte[] encryptByPrivateKey(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { @@ -153,8 +170,11 @@ public static byte[] encryptByPrivateKey(byte[] data, byte[] key) throws NoSuchA /** * 取得私钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 私钥 + * * @throws Exception */ public static byte[] getPrivateKey(Map keyMap) { @@ -165,8 +185,11 @@ public static byte[] getPrivateKey(Map keyMap) { /** * 取得公钥 * - * @param keyMap 密钥Map + * @param keyMap + * 密钥Map + * * @return byte[] 公钥 + * * @throws Exception */ public static byte[] getPublicKey(Map keyMap) { @@ -178,6 +201,7 @@ public static byte[] getPublicKey(Map keyMap) { * 初始化密钥 * * @return Map 密钥Map + * * @throws Exception */ public static Map initKey() throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolHmacRipeMD.java b/security/src/main/java/pro/tools/security/md/ToolHmacRipeMD.java index 91829e9..d403776 100644 --- a/security/src/main/java/pro/tools/security/md/ToolHmacRipeMD.java +++ b/security/src/main/java/pro/tools/security/md/ToolHmacRipeMD.java @@ -14,17 +14,20 @@ /** * HmacRipeMD系列加密组件
* HmacRipeMD128、HmacRipeMD160共2种算法 + * + * @author SeanDragon */ public final class ToolHmacRipeMD { private ToolHmacRipeMD() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 初始化HmacRipeMD128密钥 * * @return byte[] 密钥 + * * @throws NoSuchAlgorithmException */ public static byte[] initHmacRipeMD128Key() throws NoSuchAlgorithmException { @@ -45,9 +48,13 @@ public static byte[] initHmacRipeMD128Key() throws NoSuchAlgorithmException { /** * HmacRipeMD128消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacRipeMD128(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException { @@ -71,9 +78,13 @@ public static byte[] encodeHmacRipeMD128(byte[] data, byte[] key) throws NoSuchA /** * HmacRipeMD128Hex消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeHmacRipeMD128Hex(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { @@ -89,6 +100,7 @@ public static String encodeHmacRipeMD128Hex(byte[] data, byte[] key) throws Inva * 初始化HmacRipeMD160密钥 * * @return byte[] 密钥 + * * @throws Exception */ public static byte[] initHmacRipeMD160Key() throws NoSuchAlgorithmException { @@ -109,9 +121,13 @@ public static byte[] initHmacRipeMD160Key() throws NoSuchAlgorithmException { /** * HmacRipeMD160消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacRipeMD160(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException { @@ -135,9 +151,13 @@ public static byte[] encodeHmacRipeMD160(byte[] data, byte[] key) throws NoSuchA /** * HmacRipeMD160Hex消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return String 消息摘要 + * * @throws Exception */ public static String encodeHmacRipeMD160Hex(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolMAC.java b/security/src/main/java/pro/tools/security/md/ToolMAC.java index 9ec7a9c..d288bca 100644 --- a/security/src/main/java/pro/tools/security/md/ToolMAC.java +++ b/security/src/main/java/pro/tools/security/md/ToolMAC.java @@ -10,17 +10,20 @@ /** * MAC加密组件 + * + * @author SeanDragon */ public final class ToolMAC { private ToolMAC() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 初始化HmacMD5密钥 * * @return + * * @throws Exception */ public static byte[] initHmacMD5Key() throws NoSuchAlgorithmException { @@ -38,9 +41,13 @@ public static byte[] initHmacMD5Key() throws NoSuchAlgorithmException { /** * HmacMD5加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacMD5(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException { @@ -62,6 +69,7 @@ public static byte[] encodeHmacMD5(byte[] data, byte[] key) throws NoSuchAlgorit * 初始化HmacSHA1密钥 * * @return + * * @throws Exception */ public static byte[] initHmacSHAKey() throws NoSuchAlgorithmException { @@ -79,9 +87,13 @@ public static byte[] initHmacSHAKey() throws NoSuchAlgorithmException { /** * HmacSHA1加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacSHA(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException { @@ -99,13 +111,11 @@ public static byte[] encodeHmacSHA(byte[] data, byte[] key) throws NoSuchAlgorit return mac.doFinal(data); } -// // 根据所安装的 JCE 仲裁策略文件,返回指定转换的最大密钥长度。 -// public final static int getMaxAllowedKeyLength(String transformation) - /** * 初始化HmacSHA256密钥 * * @return + * * @throws Exception */ public static byte[] initHmacSHA256Key() throws NoSuchAlgorithmException { @@ -123,9 +133,13 @@ public static byte[] initHmacSHA256Key() throws NoSuchAlgorithmException { /** * HmacSHA256加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacSHA256(byte[] data, byte[] key) @@ -148,6 +162,7 @@ public static byte[] encodeHmacSHA256(byte[] data, byte[] key) * 初始化HmacSHA384密钥 * * @return + * * @throws Exception */ public static byte[] initHmacSHA384Key() throws NoSuchAlgorithmException { @@ -165,9 +180,13 @@ public static byte[] initHmacSHA384Key() throws NoSuchAlgorithmException { /** * HmacSHA384加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacSHA384(byte[] data, byte[] key) @@ -190,6 +209,7 @@ public static byte[] encodeHmacSHA384(byte[] data, byte[] key) * 初始化HmacSHA512密钥 * * @return + * * @throws Exception */ public static byte[] initHmacSHA512Key() throws NoSuchAlgorithmException { @@ -207,9 +227,13 @@ public static byte[] initHmacSHA512Key() throws NoSuchAlgorithmException { /** * HmacSHA512加密 * - * @param data 待加密数据 - * @param key 密钥 + * @param data + * 待加密数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacSHA512(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException { diff --git a/security/src/main/java/pro/tools/security/md/ToolMAC_BCP.java b/security/src/main/java/pro/tools/security/md/ToolMAC_BCP.java index bb519c8..3579d74 100644 --- a/security/src/main/java/pro/tools/security/md/ToolMAC_BCP.java +++ b/security/src/main/java/pro/tools/security/md/ToolMAC_BCP.java @@ -13,17 +13,20 @@ /** * MAC消息摘要组件 + * + * @author SeanDragon */ public final class ToolMAC_BCP { private ToolMAC_BCP() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * 初始化HmacMD2密钥 * * @return byte[] 密钥 + * * @throws Exception */ public static byte[] initHmacMD2Key() throws NoSuchAlgorithmException { @@ -44,9 +47,13 @@ public static byte[] initHmacMD2Key() throws NoSuchAlgorithmException { /** * HmacMD2消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacMD2(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException { @@ -70,9 +77,13 @@ public static byte[] encodeHmacMD2(byte[] data, byte[] key) throws NoSuchAlgorit /** * HmacMD2Hex消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeHmacMD2Hex(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { @@ -88,6 +99,7 @@ public static String encodeHmacMD2Hex(byte[] data, byte[] key) throws InvalidKey * 初始化HmacMD4密钥 * * @return byte[] 密钥 + * * @throws Exception */ public static byte[] initHmacMD4Key() throws NoSuchAlgorithmException { @@ -108,9 +120,13 @@ public static byte[] initHmacMD4Key() throws NoSuchAlgorithmException { /** * HmacMD4消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeHmacMD4(byte[] data, byte[] key) @@ -135,9 +151,13 @@ public static byte[] encodeHmacMD4(byte[] data, byte[] key) /** * HmacMD4Hex消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return String 消息摘要 + * * @throws Exception */ public static String encodeHmacMD4Hex(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { @@ -153,6 +173,7 @@ public static String encodeHmacMD4Hex(byte[] data, byte[] key) throws InvalidKey * 初始化HmacSHA224密钥 * * @return byte[] 密钥 + * * @throws Exception */ public static byte[] initHmacSHA224Key() throws NoSuchAlgorithmException { @@ -173,9 +194,13 @@ public static byte[] initHmacSHA224Key() throws NoSuchAlgorithmException { /** * HmacSHA224消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return byte[] 消息摘要 + * * @throws NoSuchAlgorithmException * @throws InvalidKeyException */ @@ -200,9 +225,13 @@ public static byte[] encodeHmacSHA224(byte[] data, byte[] key) throws NoSuchAlgo /** * HmacSHA224Hex消息摘要 * - * @param data 待做消息摘要处理的数据 - * @param key 密钥 + * @param data + * 待做消息摘要处理的数据 + * @param key + * 密钥 + * * @return String 消息摘要 + * * @throws Exception */ public static String encodeHmacSHA224Hex(byte[] data, byte[] key) throws InvalidKeyException, NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolMD.java b/security/src/main/java/pro/tools/security/md/ToolMD.java index bdebcaf..f154dd6 100644 --- a/security/src/main/java/pro/tools/security/md/ToolMD.java +++ b/security/src/main/java/pro/tools/security/md/ToolMD.java @@ -10,19 +10,24 @@ /** * MD系列加密组件
* Tiger、Whirlpool和GOST3411共3种算法 + * + * @author SeanDragon */ public final class ToolMD { private ToolMD() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * Tiger加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeTiger(byte[] data) throws NoSuchAlgorithmException { @@ -40,8 +45,11 @@ public static byte[] encodeTiger(byte[] data) throws NoSuchAlgorithmException { /** * TigerHex加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeTigerHex(byte[] data) throws NoSuchAlgorithmException { @@ -56,8 +64,11 @@ public static String encodeTigerHex(byte[] data) throws NoSuchAlgorithmException /** * Whirlpool加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeWhirlpool(byte[] data) throws NoSuchAlgorithmException { @@ -75,8 +86,11 @@ public static byte[] encodeWhirlpool(byte[] data) throws NoSuchAlgorithmExceptio /** * WhirlpoolHex加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeWhirlpoolHex(byte[] data) throws NoSuchAlgorithmException { @@ -91,8 +105,11 @@ public static String encodeWhirlpoolHex(byte[] data) throws NoSuchAlgorithmExcep /** * GOST3411加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeGOST3411(byte[] data) throws NoSuchAlgorithmException { @@ -110,8 +127,11 @@ public static byte[] encodeGOST3411(byte[] data) throws NoSuchAlgorithmException /** * GOST3411Hex加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeGOST3411Hex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolMD2.java b/security/src/main/java/pro/tools/security/md/ToolMD2.java index 55885e7..742bbe3 100644 --- a/security/src/main/java/pro/tools/security/md/ToolMD2.java +++ b/security/src/main/java/pro/tools/security/md/ToolMD2.java @@ -7,17 +7,22 @@ /** * MD加密组件 + * + * @author SeanDragon */ public final class ToolMD2 { private ToolMD2() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * MD2加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeMD2(byte[] data) throws NoSuchAlgorithmException { @@ -31,8 +36,11 @@ public static byte[] encodeMD2(byte[] data) throws NoSuchAlgorithmException { /** * MD2加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeMD2Hex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolMD4.java b/security/src/main/java/pro/tools/security/md/ToolMD4.java index d0e738f..f538c6d 100644 --- a/security/src/main/java/pro/tools/security/md/ToolMD4.java +++ b/security/src/main/java/pro/tools/security/md/ToolMD4.java @@ -9,17 +9,22 @@ /** * MD4加密组件 + * + * @author SeanDragon */ public final class ToolMD4 { private ToolMD4() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * MD4加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeMD4(byte[] data) throws NoSuchAlgorithmException { @@ -37,8 +42,11 @@ public static byte[] encodeMD4(byte[] data) throws NoSuchAlgorithmException { /** * MD4加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return String 消息摘要 + * * @throws Exception */ public static String encodeMD4Hex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolMD5.java b/security/src/main/java/pro/tools/security/md/ToolMD5.java index 43141fa..9718689 100644 --- a/security/src/main/java/pro/tools/security/md/ToolMD5.java +++ b/security/src/main/java/pro/tools/security/md/ToolMD5.java @@ -9,17 +9,22 @@ /** * MD5加密组件 + * + * @author SeanDragon */ public final class ToolMD5 { private ToolMD5() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * MD5加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws NoSuchAlgorithmException */ public static byte[] encodeMD5(byte[] data) throws NoSuchAlgorithmException { @@ -36,8 +41,11 @@ public static byte[] encodeMD5(byte[] data) throws NoSuchAlgorithmException { /** * MD5加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return String 消息摘要 + * * @throws NoSuchAlgorithmException */ public static String encodeMD5Hex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolRipeMD.java b/security/src/main/java/pro/tools/security/md/ToolRipeMD.java index 80147a8..57f31ea 100644 --- a/security/src/main/java/pro/tools/security/md/ToolRipeMD.java +++ b/security/src/main/java/pro/tools/security/md/ToolRipeMD.java @@ -10,17 +10,22 @@ /** * RipeMD系列消息摘要组件
* 包含RipeMD128、RipeMD160、RipeMD256和RipeMD320共4种RipeMD系列算法 + * + * @author SeanDragon */ public final class ToolRipeMD { private ToolRipeMD() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * RipeMD128消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeRipeMD128(byte[] data) throws NoSuchAlgorithmException { @@ -38,8 +43,11 @@ public static byte[] encodeRipeMD128(byte[] data) throws NoSuchAlgorithmExceptio /** * RipeMD128Hex消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeRipeMD128Hex(byte[] data) throws NoSuchAlgorithmException { @@ -54,8 +62,11 @@ public static String encodeRipeMD128Hex(byte[] data) throws NoSuchAlgorithmExcep /** * RipeMD160消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeRipeMD160(byte[] data) throws NoSuchAlgorithmException { @@ -73,8 +84,11 @@ public static byte[] encodeRipeMD160(byte[] data) throws NoSuchAlgorithmExceptio /** * RipeMD160Hex消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeRipeMD160Hex(byte[] data) throws NoSuchAlgorithmException { @@ -89,8 +103,11 @@ public static String encodeRipeMD160Hex(byte[] data) throws NoSuchAlgorithmExcep /** * RipeMD256消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeRipeMD256(byte[] data) throws NoSuchAlgorithmException { @@ -108,8 +125,11 @@ public static byte[] encodeRipeMD256(byte[] data) throws NoSuchAlgorithmExceptio /** * RipeMD256Hex消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeRipeMD256Hex(byte[] data) throws NoSuchAlgorithmException { @@ -124,8 +144,11 @@ public static String encodeRipeMD256Hex(byte[] data) throws NoSuchAlgorithmExcep /** * RipeMD320消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeRipeMD320(byte[] data) throws NoSuchAlgorithmException { @@ -143,8 +166,11 @@ public static byte[] encodeRipeMD320(byte[] data) throws NoSuchAlgorithmExceptio /** * RipeMD320Hex消息摘要 * - * @param data 待做消息摘要处理的数据 + * @param data + * 待做消息摘要处理的数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeRipeMD320Hex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolSHA1.java b/security/src/main/java/pro/tools/security/md/ToolSHA1.java index abe1b35..7a8479b 100644 --- a/security/src/main/java/pro/tools/security/md/ToolSHA1.java +++ b/security/src/main/java/pro/tools/security/md/ToolSHA1.java @@ -7,17 +7,22 @@ /** * SHA-1加密 + * + * @author SeanDragon */ public final class ToolSHA1 { private ToolSHA1() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * SHA-1加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeSHA(byte[] data) throws NoSuchAlgorithmException { @@ -31,8 +36,11 @@ public static byte[] encodeSHA(byte[] data) throws NoSuchAlgorithmException { /** * SHA-1加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeSHAHex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/md/ToolSHA2.java b/security/src/main/java/pro/tools/security/md/ToolSHA2.java index 77d9189..ce530ad 100644 --- a/security/src/main/java/pro/tools/security/md/ToolSHA2.java +++ b/security/src/main/java/pro/tools/security/md/ToolSHA2.java @@ -9,17 +9,22 @@ /** * SHA-2 的变种 SHA- 224、 SHA- 256、 SHA-384 、 SHA-512 + * + * @author SeanDragon */ public final class ToolSHA2 { private ToolSHA2() { - throw new UnsupportedOperationException("u can't instantiate me..."); + throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); } /** * SHA-224加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeSHA224(byte[] data) throws NoSuchAlgorithmException { @@ -36,8 +41,11 @@ public static byte[] encodeSHA224(byte[] data) throws NoSuchAlgorithmException { /** * SHA-224加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeSHA224Hex(byte[] data) throws NoSuchAlgorithmException { @@ -51,8 +59,11 @@ public static String encodeSHA224Hex(byte[] data) throws NoSuchAlgorithmExceptio /** * SHA-256加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeSHA256(byte[] data) throws NoSuchAlgorithmException { @@ -66,8 +77,11 @@ public static byte[] encodeSHA256(byte[] data) throws NoSuchAlgorithmException { /** * SHA-256加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeSHA256Hex(byte[] data) throws NoSuchAlgorithmException { @@ -81,8 +95,11 @@ public static String encodeSHA256Hex(byte[] data) throws NoSuchAlgorithmExceptio /** * SHA-384加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeSHA384(byte[] data) throws NoSuchAlgorithmException { @@ -96,8 +113,11 @@ public static byte[] encodeSHA384(byte[] data) throws NoSuchAlgorithmException { /** * SHA-384加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeSHA384Hex(byte[] data) throws NoSuchAlgorithmException { @@ -111,8 +131,11 @@ public static String encodeSHA384Hex(byte[] data) throws NoSuchAlgorithmExceptio /** * SHA-512加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static byte[] encodeSHA512(byte[] data) throws NoSuchAlgorithmException { @@ -126,8 +149,11 @@ public static byte[] encodeSHA512(byte[] data) throws NoSuchAlgorithmException { /** * SHA-512加密 * - * @param data 待加密数据 + * @param data + * 待加密数据 + * * @return byte[] 消息摘要 + * * @throws Exception */ public static String encodeSHA512Hex(byte[] data) throws NoSuchAlgorithmException { diff --git a/security/src/main/java/pro/tools/security/sm/SM2.java b/security/src/main/java/pro/tools/security/sm/SM2.java new file mode 100644 index 0000000..3f7c594 --- /dev/null +++ b/security/src/main/java/pro/tools/security/sm/SM2.java @@ -0,0 +1,729 @@ +package pro.tools.security.sm; + +import org.bouncycastle.crypto.params.ECDomainParameters; +import org.bouncycastle.math.ec.ECCurve; +import org.bouncycastle.math.ec.ECPoint; + +import java.io.*; +import java.math.BigInteger; +import java.security.SecureRandom; +import java.util.Arrays; + +/** + * SM2公钥加密算法实现 包括 -签名,验签 -密钥交换 -公钥加密,私钥解密 + * + * @author SeanDragon + */ +public class SM2 { + private static final int DIGEST_LENGTH = 32; + private static BigInteger n = new BigInteger( + "FFFFFFFE" + "FFFFFFFF" + "FFFFFFFF" + "FFFFFFFF" + "7203DF6B" + "21C6052B" + "53BBF409" + "39D54123", 16); + private static BigInteger p = new BigInteger( + "FFFFFFFE" + "FFFFFFFF" + "FFFFFFFF" + "FFFFFFFF" + "FFFFFFFF" + "00000000" + "FFFFFFFF" + "FFFFFFFF", 16); + private static BigInteger a = new BigInteger( + "FFFFFFFE" + "FFFFFFFF" + "FFFFFFFF" + "FFFFFFFF" + "FFFFFFFF" + "00000000" + "FFFFFFFF" + "FFFFFFFC", 16); + private static BigInteger b = new BigInteger( + "28E9FA9E" + "9D9F5E34" + "4D5A9E4B" + "CF6509A7" + "F39789F5" + "15AB8F92" + "DDBCBD41" + "4D940E93", 16); + private static BigInteger gx = new BigInteger( + "32C4AE2C" + "1F198119" + "5F990446" + "6A39C994" + "8FE30BBF" + "F2660BE1" + "715A4589" + "334C74C7", 16); + private static BigInteger gy = new BigInteger( + "BC3736A2" + "F4F6779C" + "59BDCEE3" + "6B692153" + "D0A9877C" + "C62A4740" + "02DF32E5" + "2139F0A0", 16); + private static ECDomainParameters ecc_bc_spec; + private static int w = (int) Math.ceil(n.bitLength() * 1.0 / 2) - 1; + private static BigInteger _2w = new BigInteger("2").pow(w); + private static SecureRandom random = new SecureRandom(); + private static ECCurve.Fp curve; + private static ECPoint G; + + public SM2() { + curve = new ECCurve.Fp(p, // q + a, // a + b); // b + G = curve.createPoint(gx, gy); + ecc_bc_spec = new ECDomainParameters(curve, G, n); + } + + /** + * 以16进制打印字节数组 + * + * @param bytes + */ + private static void printHexString(byte[] bytes) { + for (byte b : bytes) { + String hex = Integer.toHexString(b & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + System.out.print(hex.toUpperCase()); + } + System.out.println(); + } + + /** + * 随机数生成器 + * + * @param max + * @return + */ + private static BigInteger random(BigInteger max) { + BigInteger r = new BigInteger(256, random); + while (r.compareTo(max) >= 0) { + r = new BigInteger(128, random); + } + return r; + } + + /** + * 字节数组拼接 + * + * @param params + * @return + */ + private static byte[] join(byte[]... params) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] res = null; + try { + for (int i = 0; i < params.length; i++) { + baos.write(params[i]); + } + res = baos.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + } + return res; + } + + /** + * sm3摘要 + * + * @param params + * @return + */ + private static byte[] sm3hash(byte[]... params) { + byte[] res = null; + try { + res = SM3.hash(join(params)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return res; + } + + // /** + // * SHA摘要 + // * @param x2 + // * @param M + // * @param y2 + // * @return + // */ + // private byte[] calculateHash(BigInteger x2, byte[] M, BigInteger y2) { + // ShortenedDigest digest = new ShortenedDigest(new SHA256Digest(), + // DIGEST_LENGTH); + // byte[] buf = x2.toByteArray(); + // digest.update(buf, 0, buf.length); + // digest.update(M, 0, M.length); + // buf = y2.toByteArray(); + // digest.update(buf, 0, buf.length); + // + // buf = new byte[DIGEST_LENGTH]; + // digest.doFinal(buf, 0); + // + // return buf; + // } + + /** + * 取得用户标识字节数组 + * + * @param IDA + * @param aPublicKey + * @return + */ + private static byte[] ZA(String IDA, ECPoint aPublicKey) { + byte[] idaBytes = IDA.getBytes(); + int entlenA = idaBytes.length * 8; + byte[] ENTLA = new byte[]{(byte) (entlenA & 0xFF00), (byte) (entlenA & 0x00FF)}; + byte[] ZA = sm3hash(ENTLA, idaBytes, a.toByteArray(), b.toByteArray(), gx.toByteArray(), gy.toByteArray(), + aPublicKey.getXCoord().toBigInteger().toByteArray(), + aPublicKey.getYCoord().toBigInteger().toByteArray()); + return ZA; + } + + /** + * 密钥派生函数 + * + * @param Z + * @param klen 生成klen字节数长度的密钥 + * @return + */ + private static byte[] KDF(byte[] Z, int klen) { + int ct = 1; + int end = (int) Math.ceil(klen * 1.0 / 32); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + for (int i = 1; i < end; i++) { + baos.write(sm3hash(Z, SM3.toByteArray(ct))); + ct++; + } + byte[] last = sm3hash(Z, SM3.toByteArray(ct)); + if (klen % 32 == 0) { + baos.write(last); + } else { + baos.write(last, 0, klen % 32); + } + return baos.toByteArray(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 判断字节数组是否全0 + * + * @param buffer + * @return + */ + private boolean allZero(byte[] buffer) { + for (byte aBuffer : buffer) { + if (aBuffer != 0) { + return false; + } + } + return true; + } + + /** + * 公钥加密 + * + * @param input 加密原文 + * @param publicKey 公钥 + * @return + */ + public byte[] encrypt(String input, ECPoint publicKey) { + + byte[] inputBuffer = input.getBytes(); + + byte[] C1Buffer; + ECPoint kpb; + byte[] t; + do { + /* 1 产生随机数k,k属于[1, n-1] */ + BigInteger k = random(n); + + /* 2 计算椭圆曲线点C1 = [k]G = (x1, y1) */ + ECPoint C1 = G.multiply(k); + C1Buffer = C1.getEncoded(false); + + /* + * 3 计算椭圆曲线点 S = [h]Pb + */ + BigInteger h = ecc_bc_spec.getH(); + if (h != null) { + ECPoint S = publicKey.multiply(h); + if (S.isInfinity()) { + throw new IllegalStateException(); + } + } + + /* 4 计算 [k]PB = (x2, y2) */ + kpb = publicKey.multiply(k).normalize(); + + /* 5 计算 t = KDF(x2||y2, klen) */ + byte[] kpbBytes = kpb.getEncoded(false); + t = KDF(kpbBytes, inputBuffer.length); + // DerivationFunction kdf = new KDF1BytesGenerator(new + // ShortenedDigest(new SHA256Digest(), DIGEST_LENGTH)); + // + // t = new byte[inputBuffer.length]; + // kdf.init(new ISO18033KDFParameters(kpbBytes)); + // kdf.generateBytes(t, 0, t.length); + } while (allZero(t)); + + /* 6 计算C2=M^t */ + byte[] C2 = new byte[inputBuffer.length]; + for (int i = 0; i < inputBuffer.length; i++) { + C2[i] = (byte) (inputBuffer[i] ^ t[i]); + } + + /* 7 计算C3 = Hash(x2 || M || y2) */ + byte[] C3 = sm3hash(kpb.getXCoord().toBigInteger().toByteArray(), inputBuffer, + kpb.getYCoord().toBigInteger().toByteArray()); + + /* 8 输出密文 C=C1 || C2 || C3 */ + + byte[] encryptResult = new byte[C1Buffer.length + C2.length + C3.length]; + + System.arraycopy(C1Buffer, 0, encryptResult, 0, C1Buffer.length); + System.arraycopy(C2, 0, encryptResult, C1Buffer.length, C2.length); + System.arraycopy(C3, 0, encryptResult, C1Buffer.length + C2.length, C3.length); + + return encryptResult; + } + + /** + * 私钥解密 + * + * @param encryptData 密文数据字节数组 + * @param privateKey 解密私钥 + * @return + */ + public String decrypt(byte[] encryptData, BigInteger privateKey) { + + byte[] C1Byte = new byte[65]; + System.arraycopy(encryptData, 0, C1Byte, 0, C1Byte.length); + + ECPoint C1 = curve.decodePoint(C1Byte).normalize(); + + /* + * 计算椭圆曲线点 S = [h]C1 是否为无穷点 + */ + BigInteger h = ecc_bc_spec.getH(); + if (h != null) { + ECPoint S = C1.multiply(h); + if (S.isInfinity()) { + throw new IllegalStateException(); + } + } + /* 计算[dB]C1 = (x2, y2) */ + ECPoint dBC1 = C1.multiply(privateKey).normalize(); + + /* 计算t = KDF(x2 || y2, klen) */ + byte[] dBC1Bytes = dBC1.getEncoded(false); + int klen = encryptData.length - 65 - DIGEST_LENGTH; + byte[] t = KDF(dBC1Bytes, klen); + // DerivationFunction kdf = new KDF1BytesGenerator(new + // ShortenedDigest(new SHA256Digest(), DIGEST_LENGTH)); + // if (debug) + // System.out.println("klen = " + klen); + // kdf.init(new ISO18033KDFParameters(dBC1Bytes)); + // kdf.generateBytes(t, 0, t.length); + + if (allZero(t)) { + System.err.println("all zero"); + throw new IllegalStateException(); + } + + /* 5 计算M'=C2^t */ + byte[] M = new byte[klen]; + for (int i = 0; i < M.length; i++) { + M[i] = (byte) (encryptData[C1Byte.length + i] ^ t[i]); + } + /* 6 计算 u = Hash(x2 || M' || y2) 判断 u == C3是否成立 */ + byte[] C3 = new byte[DIGEST_LENGTH]; + + System.arraycopy(encryptData, encryptData.length - DIGEST_LENGTH, C3, 0, DIGEST_LENGTH); + byte[] u = sm3hash(dBC1.getXCoord().toBigInteger().toByteArray(), M, + dBC1.getYCoord().toBigInteger().toByteArray()); + if (Arrays.equals(u, C3)) { + try { + return new String(M, "UTF8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } else { + return null; + } + + } + + /** + * 判断是否在范围内 + * + * @param param + * @param min + * @param max + * @return + */ + private boolean between(BigInteger param, BigInteger min, BigInteger max) { + if (param.compareTo(min) >= 0 && param.compareTo(max) < 0) { + return true; + } else { + return false; + } + } + + /** + * 判断生成的公钥是否合法 + * + * @param publicKey + * @return + */ + private boolean checkPublicKey(ECPoint publicKey) { + + if (!publicKey.isInfinity()) { + + BigInteger x = publicKey.getXCoord().toBigInteger(); + BigInteger y = publicKey.getYCoord().toBigInteger(); + + if (between(x, new BigInteger("0"), p) && between(y, new BigInteger("0"), p)) { + + BigInteger xResult = x.pow(3).add(a.multiply(x)).add(b).mod(p); + + BigInteger yResult = y.pow(2).mod(p); + + return yResult.equals(xResult) && publicKey.multiply(n).isInfinity(); + } + } + return false; + } + + /** + * 生成密钥对 + * + * @return + */ + public SM2KeyPair generateKeyPair() { + + BigInteger d = random(n.subtract(new BigInteger("1"))); + + SM2KeyPair keyPair = new SM2KeyPair(G.multiply(d).normalize(), d); + + if (checkPublicKey(keyPair.getPublicKey())) { + return keyPair; + } else { + return null; + } + } + + /** + * 导出公钥到本地 + * + * @param publicKey + * @param path + */ + public void exportPublicKey(ECPoint publicKey, String path) { + File file = new File(path); + try { + if (!file.exists()) { + file.createNewFile(); + } + byte buffer[] = publicKey.getEncoded(false); + FileOutputStream fos = new FileOutputStream(file); + fos.write(buffer); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 从本地导入公钥 + * + * @param path + * @return + */ + public ECPoint importPublicKey(String path) { + File file = new File(path); + try { + if (!file.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(file); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + byte buffer[] = new byte[16]; + int size; + while ((size = fis.read(buffer)) != -1) { + baos.write(buffer, 0, size); + } + fis.close(); + return curve.decodePoint(baos.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 导出私钥到本地 + * + * @param privateKey + * @param path + */ + public void exportPrivateKey(BigInteger privateKey, String path) { + File file = new File(path); + try { + if (!file.exists()) { + file.createNewFile(); + } + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); + oos.writeObject(privateKey); + oos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 从本地导入私钥 + * + * @param path + * @return + */ + public BigInteger importPrivateKey(String path) { + File file = new File(path); + try { + if (!file.exists()) { + return null; + } + FileInputStream fis = new FileInputStream(file); + ObjectInputStream ois = new ObjectInputStream(fis); + BigInteger res = (BigInteger) (ois.readObject()); + ois.close(); + fis.close(); + return res; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 签名 + * + * @param M 签名信息 + * @param IDA 签名方唯一标识 + * @param keyPair 签名方密钥对 + * @return 签名 + */ + public Signature sign(String M, String IDA, SM2KeyPair keyPair) { + byte[] ZA = ZA(IDA, keyPair.getPublicKey()); + byte[] M_ = join(ZA, M.getBytes()); + BigInteger e = new BigInteger(1, sm3hash(M_)); + // BigInteger k = new BigInteger( + // "6CB28D99 385C175C 94F94E93 4817663F C176D925 DD72B727 260DBAAE + // 1FB2F96F".replace(" ", ""), 16); + BigInteger k; + BigInteger r; + do { + k = random(n); + ECPoint p1 = G.multiply(k).normalize(); + BigInteger x1 = p1.getXCoord().toBigInteger(); + r = e.add(x1); + r = r.mod(n); + } while (r.equals(BigInteger.ZERO) || r.add(k).equals(n)); + + BigInteger s = ((keyPair.getPrivateKey().add(BigInteger.ONE).modInverse(n)) + .multiply((k.subtract(r.multiply(keyPair.getPrivateKey()))).mod(n))).mod(n); + + return new Signature(r, s); + } + + /** + * 验签 + * + * @param M 签名信息 + * @param signature 签名 + * @param IDA 签名方唯一标识 + * @param aPublicKey 签名方公钥 + * @return true or false + */ + public boolean verify(String M, Signature signature, String IDA, ECPoint aPublicKey) { + if (!between(signature.r, BigInteger.ONE, n)) { + return false; + } + if (!between(signature.s, BigInteger.ONE, n)) { + return false; + } + + byte[] M_ = join(ZA(IDA, aPublicKey), M.getBytes()); + BigInteger e = new BigInteger(1, sm3hash(M_)); + BigInteger t = signature.r.add(signature.s).mod(n); + + if (t.equals(BigInteger.ZERO)) { + return false; + } + + ECPoint p1 = G.multiply(signature.s).normalize(); + ECPoint p2 = aPublicKey.multiply(t).normalize(); + BigInteger x1 = p1.add(p2).normalize().getXCoord().toBigInteger(); + BigInteger R = e.add(x1).mod(n); + if (R.equals(signature.r)) { + return true; + } + return false; + } + + /** + * 传输实体类 + * + * @author SeanDragon + */ + private static class TransportEntity implements Serializable { + final byte[] R; //R点 + final byte[] S; //验证S + final byte[] Z; //用户标识 + final byte[] K; //公钥 + + public TransportEntity(byte[] r, byte[] s, byte[] z, ECPoint pKey) { + R = r; + S = s; + Z = z; + K = pKey.getEncoded(false); + } + } + + /** + * 密钥协商辅助类 + * + * @author SeanDragon + */ + public static class KeyExchange { + BigInteger rA; + ECPoint RA; + ECPoint V; + byte[] Z; + byte[] key; + + String ID; + SM2KeyPair keyPair; + + public KeyExchange(String ID, SM2KeyPair keyPair) { + this.ID = ID; + this.keyPair = keyPair; + this.Z = ZA(ID, keyPair.getPublicKey()); + } + + /** + * 密钥协商发起第一步 + * + * @return + */ + public TransportEntity keyExchange_1() { + rA = random(n); + // rA=new BigInteger("83A2C9C8 B96E5AF7 0BD480B4 72409A9A 327257F1 + // EBB73F5B 073354B2 48668563".replace(" ", ""),16); + RA = G.multiply(rA).normalize(); + return new TransportEntity(RA.getEncoded(false), null, Z, keyPair.getPublicKey()); + } + + /** + * 密钥协商响应方 + * + * @param entity 传输实体 + * @return + */ + public TransportEntity keyExchange_2(TransportEntity entity) { + BigInteger rB = random(n); + // BigInteger rB=new BigInteger("33FE2194 0342161C 55619C4A 0C060293 + // D543C80A F19748CE 176D8347 7DE71C80".replace(" ", ""),16); + ECPoint RB = G.multiply(rB).normalize(); + + this.rA = rB; + this.RA = RB; + + BigInteger x2 = RB.getXCoord().toBigInteger(); + x2 = _2w.add(x2.and(_2w.subtract(BigInteger.ONE))); + + BigInteger tB = keyPair.getPrivateKey().add(x2.multiply(rB)).mod(n); + ECPoint RA = curve.decodePoint(entity.R).normalize(); + + BigInteger x1 = RA.getXCoord().toBigInteger(); + x1 = _2w.add(x1.and(_2w.subtract(BigInteger.ONE))); + + ECPoint aPublicKey = curve.decodePoint(entity.K).normalize(); + ECPoint temp = aPublicKey.add(RA.multiply(x1).normalize()).normalize(); + ECPoint V = temp.multiply(ecc_bc_spec.getH().multiply(tB)).normalize(); + if (V.isInfinity()) { + throw new IllegalStateException(); + } + this.V = V; + + byte[] xV = V.getXCoord().toBigInteger().toByteArray(); + byte[] yV = V.getYCoord().toBigInteger().toByteArray(); + byte[] KB = KDF(join(xV, yV, entity.Z, this.Z), 16); + key = KB; + System.out.print("协商得B密钥:"); + printHexString(KB); + byte[] sB = sm3hash(new byte[]{0x02}, yV, + sm3hash(xV, entity.Z, this.Z, RA.getXCoord().toBigInteger().toByteArray(), + RA.getYCoord().toBigInteger().toByteArray(), RB.getXCoord().toBigInteger().toByteArray(), + RB.getYCoord().toBigInteger().toByteArray())); + return new TransportEntity(RB.getEncoded(false), sB, this.Z, keyPair.getPublicKey()); + } + + /** + * 密钥协商发起方第二步 + * + * @param entity 传输实体 + */ + public TransportEntity keyExchange_3(TransportEntity entity) { + BigInteger x1 = RA.getXCoord().toBigInteger(); + x1 = _2w.add(x1.and(_2w.subtract(BigInteger.ONE))); + + BigInteger tA = keyPair.getPrivateKey().add(x1.multiply(rA)).mod(n); + ECPoint RB = curve.decodePoint(entity.R).normalize(); + + BigInteger x2 = RB.getXCoord().toBigInteger(); + x2 = _2w.add(x2.and(_2w.subtract(BigInteger.ONE))); + + ECPoint bPublicKey = curve.decodePoint(entity.K).normalize(); + ECPoint temp = bPublicKey.add(RB.multiply(x2).normalize()).normalize(); + ECPoint U = temp.multiply(ecc_bc_spec.getH().multiply(tA)).normalize(); + if (U.isInfinity()) { + throw new IllegalStateException(); + } + this.V = U; + + byte[] xU = U.getXCoord().toBigInteger().toByteArray(); + byte[] yU = U.getYCoord().toBigInteger().toByteArray(); + byte[] KA = KDF(join(xU, yU, + this.Z, entity.Z), 16); + key = KA; + System.out.print("协商得A密钥:"); + printHexString(KA); + byte[] s1 = sm3hash(new byte[]{0x02}, yU, + sm3hash(xU, this.Z, entity.Z, RA.getXCoord().toBigInteger().toByteArray(), + RA.getYCoord().toBigInteger().toByteArray(), RB.getXCoord().toBigInteger().toByteArray(), + RB.getYCoord().toBigInteger().toByteArray())); + if (Arrays.equals(entity.S, s1)) { + System.out.println("B->A 密钥确认成功"); + } else { + System.out.println("B->A 密钥确认失败"); + } + byte[] sA = sm3hash(new byte[]{0x03}, yU, + sm3hash(xU, this.Z, entity.Z, RA.getXCoord().toBigInteger().toByteArray(), + RA.getYCoord().toBigInteger().toByteArray(), RB.getXCoord().toBigInteger().toByteArray(), + RB.getYCoord().toBigInteger().toByteArray())); + + return new TransportEntity(RA.getEncoded(false), sA, this.Z, keyPair.getPublicKey()); + } + + /** + * 密钥确认最后一步 + * + * @param entity 传输实体 + */ + public void keyExchange_4(TransportEntity entity) { + byte[] xV = V.getXCoord().toBigInteger().toByteArray(); + byte[] yV = V.getYCoord().toBigInteger().toByteArray(); + ECPoint RA = curve.decodePoint(entity.R).normalize(); + byte[] s2 = sm3hash(new byte[]{0x03}, yV, + sm3hash(xV, entity.Z, this.Z, RA.getXCoord().toBigInteger().toByteArray(), + RA.getYCoord().toBigInteger().toByteArray(), this.RA.getXCoord().toBigInteger().toByteArray(), + this.RA.getYCoord().toBigInteger().toByteArray())); + if (Arrays.equals(entity.S, s2)) { + System.out.println("A->B 密钥确认成功"); + } else { + System.out.println("A->B 密钥确认失败"); + } + } + } + + public static class Signature { + BigInteger r; + BigInteger s; + + Signature(BigInteger r, BigInteger s) { + this.r = r; + this.s = s; + } + + @Override + public String toString() { + return r.toString(16) + "," + s.toString(16); + } + } +} \ No newline at end of file diff --git a/security/src/main/java/pro/tools/security/sm/SM2KeyPair.java b/security/src/main/java/pro/tools/security/sm/SM2KeyPair.java new file mode 100644 index 0000000..ceea124 --- /dev/null +++ b/security/src/main/java/pro/tools/security/sm/SM2KeyPair.java @@ -0,0 +1,30 @@ +package pro.tools.security.sm; + +import org.bouncycastle.math.ec.ECPoint; + +import java.math.BigInteger; + +/** + * SM2密钥对 + * + * @author SeanDragon + */ +public class SM2KeyPair { + + private final ECPoint publicKey; + private final BigInteger privateKey; + + SM2KeyPair(ECPoint publicKey, BigInteger privateKey) { + this.publicKey = publicKey; + this.privateKey = privateKey; + } + + public ECPoint getPublicKey() { + return publicKey; + } + + public BigInteger getPrivateKey() { + return privateKey; + } + +} \ No newline at end of file diff --git a/security/src/main/java/pro/tools/security/sm/SM3.java b/security/src/main/java/pro/tools/security/sm/SM3.java new file mode 100644 index 0000000..471a646 --- /dev/null +++ b/security/src/main/java/pro/tools/security/sm/SM3.java @@ -0,0 +1,207 @@ +package pro.tools.security.sm; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.util.Arrays; + +/** + * SM3杂凑算法实现 + * + * @author SeanDragon + */ +public class SM3 { + + private static final String ivHexStr = "7380166f 4914b2b9 172442d7 da8a0600 a96f30bc 163138aa e38dee4d b0fb0e4e"; + private static final BigInteger IV = new BigInteger(ivHexStr.replaceAll(" ", + ""), 16); + private static final Integer Tj15 = Integer.valueOf("79cc4519", 16); + private static final Integer Tj63 = Integer.valueOf("7a879d8a", 16); + private static final byte[] FirstPadding = {(byte) 0x80}; + private static final byte[] ZeroPadding = {(byte) 0x00}; + private static char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + + private static int T(int j) { + if (j >= 0 && j <= 15) { + return Tj15; + } else if (j >= 16 && j <= 63) { + return Tj63; + } else { + throw new RuntimeException("data invalid"); + } + } + + private static Integer FF(Integer x, Integer y, Integer z, int j) { + if (j >= 0 && j <= 15) { + return x ^ y ^ z; + } else if (j >= 16 && j <= 63) { + return (x & y) + | (x & z) + | (y & z); + } else { + throw new RuntimeException("data invalid"); + } + } + + private static Integer GG(Integer x, Integer y, Integer z, int j) { + if (j >= 0 && j <= 15) { + return x ^ y ^ z; + } else if (j >= 16 && j <= 63) { + return (x & y) | (~x & z); + } else { + throw new RuntimeException("data invalid"); + } + } + + private static Integer P0(Integer x) { + return x + ^ Integer.rotateLeft(x, 9) + ^ Integer.rotateLeft(x, 17); + } + + private static Integer P1(Integer x) { + return x + ^ Integer.rotateLeft(x, 15) + ^ Integer.rotateLeft(x, 23); + } + + private static byte[] padding(byte[] source) throws IOException { + long l = source.length * 8; + long k = 448 - (l + 1) % 512; + if (k < 0) { + k = k + 512; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write(source); + baos.write(FirstPadding); + long i = k - 7; + while (i > 0) { + baos.write(ZeroPadding); + i -= 8; + } + baos.write(long2bytes(l)); + return baos.toByteArray(); + } + + private static byte[] long2bytes(long l) { + byte[] bytes = new byte[8]; + for (int i = 0; i < 8; i++) { + bytes[i] = (byte) (l >>> ((7 - i) * 8)); + } + return bytes; + } + + static byte[] hash(byte[] source) throws IOException { + byte[] m1 = padding(source); + int n = m1.length / (512 / 8); + byte[] b; + byte[] vi = IV.toByteArray(); + byte[] vi1 = null; + for (int i = 0; i < n; i++) { + b = Arrays.copyOfRange(m1, i * 64, (i + 1) * 64); + vi1 = CF(vi, b); + vi = vi1; + } + return vi1; + } + + private static byte[] CF(byte[] vi, byte[] bi) throws IOException { + int a, b, c, d, e, f, g, h; + a = toInteger(vi, 0); + b = toInteger(vi, 1); + c = toInteger(vi, 2); + d = toInteger(vi, 3); + e = toInteger(vi, 4); + f = toInteger(vi, 5); + g = toInteger(vi, 6); + h = toInteger(vi, 7); + + int[] w = new int[68]; + int[] w1 = new int[64]; + for (int i = 0; i < 16; i++) { + w[i] = toInteger(bi, i); + } + for (int j = 16; j < 68; j++) { + w[j] = P1(w[j - 16] ^ w[j - 9] ^ Integer.rotateLeft(w[j - 3], 15)) + ^ Integer.rotateLeft(w[j - 13], 7) ^ w[j - 6]; + } + for (int j = 0; j < 64; j++) { + w1[j] = w[j] ^ w[j + 4]; + } + int ss1, ss2, tt1, tt2; + for (int j = 0; j < 64; j++) { + ss1 = Integer + .rotateLeft( + Integer.rotateLeft(a, 12) + e + + Integer.rotateLeft(T(j), j), 7); + ss2 = ss1 ^ Integer.rotateLeft(a, 12); + tt1 = FF(a, b, c, j) + d + ss2 + w1[j]; + tt2 = GG(e, f, g, j) + h + ss1 + w[j]; + d = c; + c = Integer.rotateLeft(b, 9); + b = a; + a = tt1; + h = g; + g = Integer.rotateLeft(f, 19); + f = e; + e = P0(tt2); + } + byte[] v = toByteArray(a, b, c, d, e, f, g, h); + for (int i = 0; i < v.length; i++) { + v[i] = (byte) (v[i] ^ vi[i]); + } + return v; + } + + private static int toInteger(byte[] source, int index) { + StringBuilder valueStr = new StringBuilder(); + for (int i = 0; i < 4; i++) { + valueStr.append(hexDigits[(byte) ((source[index * 4 + i] & 0xF0) >> 4)]); + valueStr.append(hexDigits[(byte) (source[index * 4 + i] & 0x0F)]); + } + return Long.valueOf(valueStr.toString(), 16).intValue(); + + } + + private static byte[] toByteArray(int a, int b, int c, int d, int e, int f, + int g, int h) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(32); + baos.write(toByteArray(a)); + baos.write(toByteArray(b)); + baos.write(toByteArray(c)); + baos.write(toByteArray(d)); + baos.write(toByteArray(e)); + baos.write(toByteArray(f)); + baos.write(toByteArray(g)); + baos.write(toByteArray(h)); + return baos.toByteArray(); + } + + static byte[] toByteArray(int i) { + byte[] byteArray = new byte[4]; + byteArray[0] = (byte) (i >>> 24); + byteArray[1] = (byte) ((i & 0xFFFFFF) >>> 16); + byteArray[2] = (byte) ((i & 0xFFFF) >>> 8); + byteArray[3] = (byte) (i & 0xFF); + return byteArray; + } + + private static String byteToHexString(byte b) { + int n = b; + if (n < 0) { + n = 256 + n; + } + int d1 = n / 16; + int d2 = n % 16; + return "" + hexDigits[d1] + hexDigits[d2]; + } + + public static String byteArrayToHexString(byte[] b) { + StringBuilder resultSb = new StringBuilder(); + for (byte aB : b) { + resultSb.append(byteToHexString(aB)); + } + return resultSb.toString(); + } +} \ No newline at end of file diff --git a/security/src/main/test/TestMd5.java b/security/src/main/test/TestMd5.java deleted file mode 100644 index 1ac45eb..0000000 --- a/security/src/main/test/TestMd5.java +++ /dev/null @@ -1,40 +0,0 @@ -import com.google.common.hash.HashCode; -import com.google.common.hash.HashFunction; -import com.google.common.hash.Hasher; -import com.google.common.hash.Hashing; -import org.bouncycastle.util.encoders.Hex; -import org.junit.Test; -import pro.tools.constant.StrConst; -import pro.tools.data.text.ToolJson; -import pro.tools.security.md.ToolMD5; - -import java.security.NoSuchAlgorithmException; - -/** - * @author SeanDragon - *

- * Create By 2017-11-30 16:58 - */ -public class TestMd5 { - @Test - public void test1() throws NoSuchAlgorithmException { - byte [] data = "123456".getBytes(); - long begin = System.currentTimeMillis(); - String result = ToolMD5.encodeMD5Hex(data); - System.out.println(System.currentTimeMillis()-begin); - System.out.println(result); - begin = System.currentTimeMillis(); - HashFunction hashFunction = Hashing.md5(); - Hasher hasher = hashFunction.newHasher(); - hasher.putString("123456", StrConst.DEFAULT_CHARSET); - HashCode hash = hasher.hash(); - System.out.println(System.currentTimeMillis()-begin); - System.out.println(hash.toString()); - System.out.println(Hex.toHexString(hash.asBytes())); - } - - @Test - public void test2() { - System.out.println(ToolJson.anyToJson(null)); - } -} diff --git a/security/src/test/java/TestBarCode.java b/security/src/test/java/TestBarCode.java new file mode 100644 index 0000000..c18a1e8 --- /dev/null +++ b/security/src/test/java/TestBarCode.java @@ -0,0 +1,34 @@ +import com.google.zxing.NotFoundException; +import com.google.zxing.WriterException; +import org.junit.Test; +import pro.tools.data.image.ToolBarCode; + +import java.io.IOException; +import java.util.UUID; + +public class TestBarCode { + + String path = "E:/qrcode.png"; + + @Test + public void test1() throws IOException, WriterException { + String str = "425a6839314159265359ad39bc0700007c9ef910067ff03f5f3cf0800a7fffffffffffffff8fe0c0028ec803308654d264d469ea3d2613d434da9899909a3469b44310302000c800d326401a212a7e9e421a53c189a053c34d29e991906a0068c0264320034c118d0e343434340340620680c800034d000d00c80000061228224d3d28fd468434d3ca07a9a32680680001a64f500d34343d468d3d13ca1f2cdf9ebe471be7a9cea7bb0401a2e36812750372948f21a98c90585c1648283a0d41438c2e680e14466e33384322a4e64d126e04084a311b4e522638c46b15d8bb06d99b684060229c03f28129a81080c5b86a1cc38aadc65672230e040525c0b068bc6d32eae630af32fad739b62a475b4ba04a62542106585fc58418633777187460a00d6bff773e0b57bf7e1671c3599661e6414ca081abe6c54bf85f7e562a530d67356877fc70c69307c14d570d7781fcead859b82cd963c320a5f9c70de9dda42e211080c4129fa2b96dd02b9b89c04134e65a47c73cc97b4ea5966cca4ab41bbb48393ed576cd6a985d37f0e6cf31354f32e4236064b6f045291c3a02363e918b146191181796790d0916f655d2ad1d4dd1422be572baab405693c8ca5c00e7e89098c1978d0b3cd2649257273793880b428deb16a5a5495486a4a1a99899c5b704c845254050178c8d2fb44aa18439646ab0bf060e0d2b4de7940ed366546de2d5c695b4c05773b1444a596a1633b48de2536a878ba9d62483fc8439bcdc9dfca91a6c20011626380e24601c271d295196fcd858ac50ed4a7fa42aeabfc94e4a585dfb0b9525e52bf73e82224d929d13b746180ca1472c487f5eba5c592e8f29e0b45428061c63c0c4cd2cf29c554964e16550a54e476f57d1e7157d349ac93f45aa280ab262c5f7a04456935302837002446f1d9f32e753b5830251890e6860cef5b076e013c1c753db2e4a38e4274a0881b45933e09b5dbc599d649051a453723ad56875210b14152b821d6b835eb3c0781523cfe9cf7aecc7f1cfaafcd26cb1823051664a5854a3694edb18537e11403cd27dcc524165305eacd4932e50ff177245385090ad39bc07"; +// ToolBarCode.encode(str,1000,1000,"PNG",path); + ToolBarCode.encodeLogo(str, 1000, 1000, "E:/guohui.jfif", "PNG", path); + } + + @Test + public void test2() throws IOException, NotFoundException { + String decode = ToolBarCode.decode(path); + System.out.println(decode); + } + + @Test + public void test3() { + int num = 50; + for (int i = 0; i < num; i++) { + String one = UUID.randomUUID().toString().toUpperCase().replace("-", ""); + System.out.println(one); + } + } +} \ No newline at end of file diff --git a/security/src/test/java/package-info.java b/security/src/test/java/package-info.java new file mode 100644 index 0000000..af10c3e --- /dev/null +++ b/security/src/test/java/package-info.java @@ -0,0 +1 @@ +// 该目录不为空时,删除此文件 \ No newline at end of file