diff --git a/CHANGELOG.md b/CHANGELOG.md
index bddb9c5..18e14aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,49 @@
===========================
+## [2.3.2](https://github.com/buession/buession-security/releases/tag/v2.3.2) (2023-12-27)
+
+### 🔨依赖升级
+
+- [依赖库版本升级和安全漏洞修复](https://github.com/buession/buession-parent/releases/tag/v2.3.2)
+- [owasp antisamy](https://github.com/nahsra/antisamy) 版本升级至 1.7.4
+
+
+### ⭐ 新特性
+
+- **buession-security-captcha:** GeetestClient 增加 v3、v4 版本判断方法
+- **buession-security-shiro:** 增加判断是否具备所有权限 Tag HasAllPermissionsTag
+
+
+### 🔔 变化
+
+- **buession-security-shiro:** 依赖 javax.servlet.jsp-api 更换为 jakarta.servlet.jsp-api
+
+
+### 🐞 Bug 修复
+
+- **buession-security-pac4j:** 修复 webflux 模式下 PrincipalMethodArgumentResolver 继承了错误类的 BUG
+
+
+### 漏洞修复
+
+- [owasp antisamy](https://github.com/nahsra/antisamy) 修复 [CVE-2023-43643] 漏洞
+
+
+### ⏪ 优化
+
+- **buession-security-captcha:** 代码质量优化
+- **buession-security-pac4j:** 代码质量优化
+
+
+### 📔 文档
+
+- **buession-security-shiro:** 完善注释
+
+
+---
+
+
## [2.3.1](https://github.com/buession/buession-security/releases/tag/v2.3.1) (2023-11-17)
### 🔨依赖升级
diff --git a/buession-security-captcha/pom.xml b/buession-security-captcha/pom.xml
index ab17bb3..9386b31 100644
--- a/buession-security-captcha/pom.xml
+++ b/buession-security-captcha/pom.xml
@@ -7,7 +7,7 @@
com.buession.security
buession-security-parent
../buession-security-parent
- 2.3.1
+ 2.3.2
buession-security-captcha
https://security.buession.com/
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/aliyun/AliYunCaptchaClient.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/aliyun/AliYunCaptchaClient.java
index f6a2750..ec0cf6b 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/aliyun/AliYunCaptchaClient.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/aliyun/AliYunCaptchaClient.java
@@ -224,21 +224,10 @@ public String getEndpoint() {
* @return 检测结果
*/
private static boolean checkParam(final AliYunRequestData requestData) throws RequiredParameterCaptchaException {
- if(Validate.hasText(requestData.getToken()) == false){
- throw new RequiredParameterCaptchaException("Token");
- }
-
- if(Validate.hasText(requestData.getSig()) == false){
- throw new RequiredParameterCaptchaException("Sig");
- }
-
- if(Validate.hasText(requestData.getSessionId()) == false){
- throw new RequiredParameterCaptchaException("SessionId");
- }
-
- if(Validate.hasText(requestData.getScene()) == false){
- throw new RequiredParameterCaptchaException("Scene");
- }
+ Assert.isBlank(requestData.getToken(), ()->new RequiredParameterCaptchaException("Token"));
+ Assert.isBlank(requestData.getSig(), ()->new RequiredParameterCaptchaException("Sig"));
+ Assert.isBlank(requestData.getSessionId(), ()->new RequiredParameterCaptchaException("SessionId"));
+ Assert.isBlank(requestData.getScene(), ()->new RequiredParameterCaptchaException("Scene"));
return true;
}
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/core/RequiredParameterCaptchaException.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/core/RequiredParameterCaptchaException.java
index 4f545fe..677fae9 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/core/RequiredParameterCaptchaException.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/core/RequiredParameterCaptchaException.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.security.captcha.core;
@@ -34,27 +34,28 @@ public class RequiredParameterCaptchaException extends CaptchaException {
private final String parameter;
- public RequiredParameterCaptchaException(String parameter){
+ public RequiredParameterCaptchaException(String parameter) {
super("Parameter \"" + parameter + "\" cloud not be empty or null.");
this.parameter = parameter;
}
- public RequiredParameterCaptchaException(String parameter, String message){
+ public RequiredParameterCaptchaException(String parameter, String message) {
super(message);
this.parameter = parameter;
}
- public RequiredParameterCaptchaException(String parameter, Throwable cause){
+ public RequiredParameterCaptchaException(String parameter, Throwable cause) {
super("Parameter \"" + parameter + "\" cloud not be empty or null.", cause);
this.parameter = parameter;
}
- public RequiredParameterCaptchaException(String parameter, String message, Throwable cause){
+ public RequiredParameterCaptchaException(String parameter, String message, Throwable cause) {
super(message, cause);
this.parameter = parameter;
}
- public String getParameter(){
+ public String getParameter() {
return parameter;
}
+
}
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/GeetestClient.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/GeetestClient.java
index ecfb811..d113776 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/GeetestClient.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/GeetestClient.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.security.captcha.geetest;
@@ -37,8 +37,30 @@ public interface GeetestClient extends CaptchaClient {
void setHttpClient(HttpClient httpClient);
@Override
- default Manufacturer getManufacturer(){
+ default Manufacturer getManufacturer() {
return Manufacturer.GEETEST;
}
+ /**
+ * 返回是否为 V3 版本
+ *
+ * @return true / false
+ *
+ * @since 2.3.2
+ */
+ default boolean isV3() {
+ return "v3".equalsIgnoreCase(getVersion());
+ }
+
+ /**
+ * 返回是否为 V3 版本
+ *
+ * @return true / false
+ *
+ * @since 2.3.2
+ */
+ default boolean isV4() {
+ return "v4".equalsIgnoreCase(getVersion());
+ }
+
}
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v3/GeetestV3Client.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v3/GeetestV3Client.java
index c43f1ab..ece2d3b 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v3/GeetestV3Client.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v3/GeetestV3Client.java
@@ -26,6 +26,7 @@
import com.buession.core.builder.MapBuilder;
import com.buession.core.id.SimpleIdGenerator;
+import com.buession.core.utils.Assert;
import com.buession.core.validator.Validate;
import com.buession.httpclient.HttpClient;
import com.buession.httpclient.core.Response;
@@ -189,17 +190,9 @@ public String getVersion() {
*/
private static boolean checkParam(final GeetestV3RequestData requestData)
throws RequiredParameterCaptchaException {
- if(Validate.hasText(requestData.getChallenge()) == false){
- throw new RequiredParameterCaptchaException("challenge");
- }
-
- if(Validate.hasText(requestData.getValidate()) == false){
- throw new RequiredParameterCaptchaException("validate");
- }
-
- if(Validate.hasText(requestData.getSeccode()) == false){
- throw new RequiredParameterCaptchaException("seccode");
- }
+ Assert.isBlank(requestData.getChallenge(), ()->new RequiredParameterCaptchaException("challenge"));
+ Assert.isBlank(requestData.getValidate(), ()->new RequiredParameterCaptchaException("validate"));
+ Assert.isBlank(requestData.getSeccode(), ()->new RequiredParameterCaptchaException("seccode"));
return true;
}
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v4/GeetestV4Client.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v4/GeetestV4Client.java
index 8dab159..b2fb019 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v4/GeetestV4Client.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/geetest/api/v4/GeetestV4Client.java
@@ -25,7 +25,7 @@
package com.buession.security.captcha.geetest.api.v4;
import com.buession.core.builder.MapBuilder;
-import com.buession.core.validator.Validate;
+import com.buession.core.utils.Assert;
import com.buession.httpclient.HttpClient;
import com.buession.httpclient.core.EncodedFormRequestBody;
import com.buession.httpclient.core.Response;
@@ -62,7 +62,7 @@ public final class GeetestV4Client extends AbstractGeetestClient {
* @param secretKey
* 私钥
*/
- public GeetestV4Client(final String appId, final String secretKey){
+ public GeetestV4Client(final String appId, final String secretKey) {
super(appId, secretKey);
}
@@ -76,12 +76,12 @@ public GeetestV4Client(final String appId, final String secretKey){
* @param httpClient
* {@link HttpClient}
*/
- public GeetestV4Client(final String appId, final String secretKey, final HttpClient httpClient){
+ public GeetestV4Client(final String appId, final String secretKey, final HttpClient httpClient) {
super(appId, secretKey, httpClient);
}
@Override
- public InitResponse initialize(RequestData requestData){
+ public InitResponse initialize(RequestData requestData) {
if(logger.isDebugEnabled()){
logger.debug("验证初始化");
}
@@ -90,7 +90,7 @@ public InitResponse initialize(RequestData requestData){
}
@Override
- public Status validate(RequestData requestData) throws CaptchaException{
+ public Status validate(RequestData requestData) throws CaptchaException {
if(logger.isDebugEnabled()){
logger.debug("二次验证, 请求参数:{}.", requestData);
}
@@ -134,7 +134,7 @@ public Status validate(RequestData requestData) throws CaptchaException{
}
@Override
- public String getVersion(){
+ public String getVersion() {
return "v4";
}
@@ -147,22 +147,11 @@ public String getVersion(){
* @return 检测结果
*/
private static boolean checkParam(final GeetestV4RequestData requestData)
- throws RequiredParameterCaptchaException{
- if(Validate.hasText(requestData.getLotNumber()) == false){
- throw new RequiredParameterCaptchaException("lot_number");
- }
-
- if(Validate.hasText(requestData.getCaptchaOutput()) == false){
- throw new RequiredParameterCaptchaException("captcha_output");
- }
-
- if(Validate.hasText(requestData.getPassToken()) == false){
- throw new RequiredParameterCaptchaException("pass_token");
- }
-
- if(Validate.hasText(requestData.getGenTime()) == false){
- throw new RequiredParameterCaptchaException("gen_time");
- }
+ throws RequiredParameterCaptchaException {
+ Assert.isBlank(requestData.getLotNumber(), ()->new RequiredParameterCaptchaException("lot_number"));
+ Assert.isBlank(requestData.getCaptchaOutput(), ()->new RequiredParameterCaptchaException("captcha_output"));
+ Assert.isBlank(requestData.getPassToken(), ()->new RequiredParameterCaptchaException("pass_token"));
+ Assert.isBlank(requestData.getGenTime(), ()->new RequiredParameterCaptchaException("gen_time"));
return true;
}
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/tencent/TencentCaptchaClient.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/tencent/TencentCaptchaClient.java
index fcd8e07..6adb23c 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/tencent/TencentCaptchaClient.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/tencent/TencentCaptchaClient.java
@@ -25,7 +25,6 @@
package com.buession.security.captcha.tencent;
import com.buession.core.utils.Assert;
-import com.buession.core.validator.Validate;
import com.buession.httpclient.HttpClient;
import com.buession.httpclient.core.Response;
import com.buession.lang.Status;
@@ -71,7 +70,7 @@ public class TencentCaptchaClient extends AbstractCaptchaClient {
* @param secretKey
* 原始的 SecretKey
*/
- public TencentCaptchaClient(final String secretId, final String secretKey){
+ public TencentCaptchaClient(final String secretId, final String secretKey) {
Assert.isBlank(secretId, "Secret Id cloud not be empty or null");
Assert.isBlank(secretKey, "Secret Key cloud not be empty or null");
this.secretId = secretId;
@@ -88,13 +87,13 @@ public TencentCaptchaClient(final String secretId, final String secretKey){
* @param httpClient
* {@link HttpClient} 实例
*/
- public TencentCaptchaClient(final String secretId, final String secretKey, final HttpClient httpClient){
+ public TencentCaptchaClient(final String secretId, final String secretKey, final HttpClient httpClient) {
this(secretId, secretKey);
setHttpClient(httpClient);
}
@Override
- public Status validate(RequestData requestData) throws CaptchaException{
+ public Status validate(RequestData requestData) throws CaptchaException {
if(logger.isDebugEnabled()){
logger.debug("二次验证, 请求参数:{}.", requestData);
}
@@ -135,12 +134,12 @@ public Status validate(RequestData requestData) throws CaptchaException{
}
@Override
- public Manufacturer getManufacturer(){
+ public Manufacturer getManufacturer() {
return Manufacturer.TENCENT;
}
@Override
- public String getVersion(){
+ public String getVersion() {
return "2019-07-22";
}
@@ -153,14 +152,9 @@ public String getVersion(){
* @return 检测结果
*/
private static boolean checkParam(final TencentRequestData requestData)
- throws RequiredParameterCaptchaException{
- if(Validate.hasText(requestData.getTicket()) == false){
- throw new RequiredParameterCaptchaException("Ticket");
- }
-
- if(Validate.hasText(requestData.getRandstr()) == false){
- throw new RequiredParameterCaptchaException("Randstr");
- }
+ throws RequiredParameterCaptchaException {
+ Assert.isBlank(requestData.getTicket(), ()->new RequiredParameterCaptchaException("Ticket"));
+ Assert.isBlank(requestData.getRandstr(), ()->new RequiredParameterCaptchaException("Randstr"));
return true;
}
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/reactive/ReactiveGeetestCaptchaValidator.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/reactive/ReactiveGeetestCaptchaValidator.java
index e9f72ee..293e4f6 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/reactive/ReactiveGeetestCaptchaValidator.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/reactive/ReactiveGeetestCaptchaValidator.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.security.captcha.validator.reactive;
@@ -57,15 +57,15 @@ public class ReactiveGeetestCaptchaValidator extends GeetestCaptchaValidator imp
* {@link GeetestParameter} 实例
*/
public ReactiveGeetestCaptchaValidator(final GeetestCaptchaClient geetestCaptchaClient,
- final GeetestParameter parameter){
+ final GeetestParameter parameter) {
super(geetestCaptchaClient, parameter);
}
@Override
- public Status validate(final ServerHttpRequest request) throws CaptchaException{
+ public Status validate(final ServerHttpRequest request) throws CaptchaException {
MultiValueMap parameters = request.getQueryParams();
- if("v3".equals(captchaClient.getVersion())){
+ if(captchaClient.isV3()){
final GeetestV3Parameter geetestV3Parameter = (GeetestV3Parameter) parameter;
final GeetestV3RequestData requestData = new GeetestV3RequestData();
@@ -84,7 +84,7 @@ public Status validate(final ServerHttpRequest request) throws CaptchaException{
}
return validate(requestData);
- }else if("v4".equals(captchaClient.getVersion())){
+ }else if(captchaClient.isV4()){
final GeetestV4Parameter geetestV4Parameter = (GeetestV4Parameter) parameter;
final GeetestV4RequestData requestData = new GeetestV4RequestData();
diff --git a/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/servlet/ServletGeetestCaptchaValidator.java b/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/servlet/ServletGeetestCaptchaValidator.java
index 1d9f873..e676621 100644
--- a/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/servlet/ServletGeetestCaptchaValidator.java
+++ b/buession-security-captcha/src/main/java/com/buession/security/captcha/validator/servlet/ServletGeetestCaptchaValidator.java
@@ -19,7 +19,7 @@
* +-------------------------------------------------------------------------------------------------------+
* | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
* | Author: Yong.Teng |
- * | Copyright @ 2013-2022 Buession.com Inc. |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.security.captcha.validator.servlet;
@@ -57,13 +57,13 @@ public class ServletGeetestCaptchaValidator extends GeetestCaptchaValidator impl
* {@link GeetestParameter} 实例
*/
public ServletGeetestCaptchaValidator(final GeetestCaptchaClient geetestCaptchaClient,
- final GeetestParameter parameter){
+ final GeetestParameter parameter) {
super(geetestCaptchaClient, parameter);
}
@Override
- public Status validate(final HttpServletRequest request) throws CaptchaException{
- if("v3".equals(captchaClient.getVersion())){
+ public Status validate(final HttpServletRequest request) throws CaptchaException {
+ if(captchaClient.isV3()){
final GeetestV3Parameter geetestV3Parameter = (GeetestV3Parameter) parameter;
final GeetestV3RequestData requestData = new GeetestV3RequestData();
@@ -82,7 +82,7 @@ public Status validate(final HttpServletRequest request) throws CaptchaException
}
return validate(requestData);
- }else if("v4".equals(captchaClient.getVersion())){
+ }else if(captchaClient.isV4()){
final GeetestV4Parameter geetestV4Parameter = (GeetestV4Parameter) parameter;
final GeetestV4RequestData requestData = new GeetestV4RequestData();
diff --git a/buession-security-core/pom.xml b/buession-security-core/pom.xml
index cce58a2..72aad15 100644
--- a/buession-security-core/pom.xml
+++ b/buession-security-core/pom.xml
@@ -7,7 +7,7 @@
com.buession.security
buession-security-parent
../buession-security-parent
- 2.3.1
+ 2.3.2
buession-security-core
https://security.buession.com/
diff --git a/buession-security-crypto/pom.xml b/buession-security-crypto/pom.xml
index 589d129..3f6042e 100644
--- a/buession-security-crypto/pom.xml
+++ b/buession-security-crypto/pom.xml
@@ -7,7 +7,7 @@
com.buession.security
buession-security-parent
../buession-security-parent
- 2.3.1
+ 2.3.2
buession-security-crypto
https://security.buession.com/
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/AESCrypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/AESCrypto.java
new file mode 100644
index 0000000..b3f6b07
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/AESCrypto.java
@@ -0,0 +1,345 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ * =================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.utils.Assert;
+import com.buession.security.crypto.internal.SymmetricalCrypto;
+
+import java.nio.charset.Charset;
+import java.security.GeneralSecurityException;
+
+/**
+ * AES 加密对象
+ * slat 不足 16 位,以空格填充;slat 超过 16 位将截取前 16 位
+ * 加密结果以 Base64 返回
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class AESCrypto extends AbstractCrypto {
+
+ /**
+ * 加密模式
+ */
+ private Mode mode = Mode.ECB;
+
+ /**
+ * 补码方式
+ */
+ private Padding padding = Padding.PKCS5;
+
+ /**
+ * 构造函数
+ */
+ public AESCrypto() {
+ super(Algorithm.AES);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public AESCrypto(final String salt) {
+ super(Algorithm.AES, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public AESCrypto(final Charset charset) {
+ super(Algorithm.AES, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public AESCrypto(final String characterEncoding, final String salt) {
+ super(Algorithm.AES, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public AESCrypto(final Charset charset, final String salt) {
+ super(Algorithm.AES, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param mode
+ * 加密模式
+ */
+ public AESCrypto(final Mode mode) {
+ this();
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public AESCrypto(final String salt, final Mode mode) {
+ this(salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param mode
+ * 加密模式
+ */
+ public AESCrypto(final Charset charset, final Mode mode) {
+ this(charset);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public AESCrypto(final String characterEncoding, final String salt, final Mode mode) {
+ this(characterEncoding, salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public AESCrypto(final Charset charset, final String salt, final Mode mode) {
+ this(charset, salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final Padding padding) {
+ this();
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final String salt, final Padding padding) {
+ this(salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final Charset charset, final Padding padding) {
+ this(charset);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final String characterEncoding, final String salt, final Padding padding) {
+ this(characterEncoding, salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final Charset charset, final String salt, final Padding padding) {
+ this(charset, salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final Mode mode, final Padding padding) {
+ this(mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final String salt, final Mode mode, final Padding padding) {
+ this(salt, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final Charset charset, final Mode mode, final Padding padding) {
+ this(charset, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final String characterEncoding, final String salt, final Mode mode, final Padding padding) {
+ this(characterEncoding, salt, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public AESCrypto(final Charset charset, final String salt, final Mode mode, final Padding padding) {
+ this(charset, salt, mode);
+ this.padding = padding;
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null");
+
+ try{
+ SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding, getProvider(),
+ getSalt());
+ return crypto.encrypt(object);
+ }catch(GeneralSecurityException e){
+ logger.error(e.getMessage());
+ throw new SecurityException(e);
+ }
+ }
+
+ @Override
+ public String decrypt(final CharSequence cs) {
+ Assert.isNull(cs, "Mcrypt decrypt object could not be null");
+
+ try{
+ SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding,
+ getProvider(), getSalt());
+ return crypto.decrypt(cs);
+ }catch(GeneralSecurityException e){
+ logger.error(e.getMessage());
+ throw new SecurityException(e);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractCrypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractCrypto.java
index ec332bb..fabbc78 100644
--- a/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractCrypto.java
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractCrypto.java
@@ -102,6 +102,20 @@ public AbstractCrypto(final Algorithm algorithm, final Charset charset) {
this.charset = charset;
}
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 加密算法
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public AbstractCrypto(final Algorithm algorithm, final String characterEncoding, final String salt) {
+ this(algorithm, Charset.forName(characterEncoding), salt);
+ }
+
/**
* 构造函数
*
@@ -130,6 +144,21 @@ public AbstractCrypto(final Algorithm algorithm, final Provider provider) {
this.provider = provider;
}
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 加密算法
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public AbstractCrypto(final Algorithm algorithm, final String salt, final Provider provider) {
+ this(algorithm, salt);
+ this.provider = provider;
+ }
+
/**
* 构造函数
*
@@ -150,13 +179,16 @@ public AbstractCrypto(final Algorithm algorithm, final Charset charset, final Pr
*
* @param algorithm
* 加密算法
+ * @param characterEncoding
+ * 字符编码
* @param salt
* 加密密钥
* @param provider
* 信息摘要对象的提供者
*/
- public AbstractCrypto(final Algorithm algorithm, final String salt, final Provider provider) {
- this(algorithm, salt);
+ public AbstractCrypto(final Algorithm algorithm, final String characterEncoding, final String salt,
+ final Provider provider) {
+ this(algorithm, Charset.forName(characterEncoding), salt);
this.provider = provider;
}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractHmacCrypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractHmacCrypto.java
new file mode 100644
index 0000000..dbfcc33
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/AbstractHmacCrypto.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.utils.Assert;
+import com.buession.security.crypto.utils.ObjectUtils;
+import org.apache.commons.codec.digest.HmacAlgorithms;
+import org.apache.commons.codec.digest.HmacUtils;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac 加解密
+ *
+ * @author Yong.Teng
+ * @since 2.3.0
+ */
+public abstract class AbstractHmacCrypto extends AbstractCrypto {
+
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 加密算法
+ */
+ public AbstractHmacCrypto(final Algorithm algorithm) {
+ super(algorithm);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 请求算法的名称
+ * @param salt
+ * 加密密钥
+ */
+ public AbstractHmacCrypto(final Algorithm algorithm, final String salt) {
+ super(algorithm, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 请求算法的名称
+ * @param charset
+ * 字符编码
+ */
+ public AbstractHmacCrypto(final Algorithm algorithm, final Charset charset) {
+ super(algorithm, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 加密算法
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public AbstractHmacCrypto(final Algorithm algorithm, final String characterEncoding, final String salt) {
+ super(algorithm, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param algorithm
+ * 加密算法
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public AbstractHmacCrypto(final Algorithm algorithm, final Charset charset, final String salt) {
+ super(algorithm, charset, salt);
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null");
+ Assert.isNull(getAlgorithm(), "Algo could not be null");
+
+ HmacUtils hmacUtils = new HmacUtils(getHmacAlgorithms(), getRealSalt().getBytes(getCharset()));
+ return hmacUtils.hmacHex(ObjectUtils.toBytes(object, getCharset()));
+ }
+
+ protected abstract HmacAlgorithms getHmacAlgorithms();
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Base64Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Base64Crypto.java
new file mode 100644
index 0000000..65cfd93
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Base64Crypto.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ * =================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.utils.Assert;
+import com.buession.security.crypto.utils.ObjectUtils;
+
+import java.nio.charset.Charset;
+import java.util.Base64;
+
+/**
+ * base64 编码、解码
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Base64Crypto extends AbstractCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Base64Crypto() {
+ super(Algorithm.BASE64);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Base64Crypto(final String salt) {
+ super(Algorithm.BASE64, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Base64Crypto(final Charset charset) {
+ super(Algorithm.BASE64, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Base64Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.BASE64, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Base64Crypto(final Charset charset, final String salt) {
+ super(Algorithm.BASE64, charset, salt);
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null.");
+ return Base64.getEncoder()
+ .encodeToString((ObjectUtils.toString(object) + getRealSalt()).getBytes(getCharset()));
+ }
+
+ @Override
+ public String decrypt(final CharSequence cs) {
+ Assert.isNull(cs, "Mcrypt decrypt object could not be null.");
+ return new String(Base64.getDecoder().decode(cs.toString()), getCharset());
+ }
+
+}
\ No newline at end of file
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/DESCrypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/DESCrypto.java
new file mode 100644
index 0000000..1e7fbb6
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/DESCrypto.java
@@ -0,0 +1,359 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ * =================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.utils.Assert;
+import com.buession.security.crypto.internal.SymmetricalCrypto;
+
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import java.nio.charset.Charset;
+import java.security.GeneralSecurityException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+
+/**
+ * DES 加密对象
+ * slat 不足 16 位,以空格填充;slat 超过 16 位将截取前 16 位
+ * 加密结果以 Base64 返回
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class DESCrypto extends AbstractCrypto {
+
+ /**
+ * 加密模式
+ */
+ private Mode mode = Mode.ECB;
+
+ /**
+ * 补码方式
+ */
+ private Padding padding = Padding.PKCS5;
+
+ /**
+ * 构造函数
+ */
+ public DESCrypto() {
+ super(Algorithm.AES);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public DESCrypto(final String salt) {
+ super(Algorithm.AES, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public DESCrypto(final Charset charset) {
+ super(Algorithm.AES, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public DESCrypto(final String characterEncoding, final String salt) {
+ super(Algorithm.AES, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public DESCrypto(final Charset charset, final String salt) {
+ super(Algorithm.AES, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param mode
+ * 加密模式
+ */
+ public DESCrypto(final Mode mode) {
+ this();
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public DESCrypto(final String salt, final Mode mode) {
+ this(salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param mode
+ * 加密模式
+ */
+ public DESCrypto(final Charset charset, final Mode mode) {
+ this(charset);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public DESCrypto(final String characterEncoding, final String salt, final Mode mode) {
+ this(characterEncoding, salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public DESCrypto(final Charset charset, final String salt, final Mode mode) {
+ this(charset, salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final Padding padding) {
+ this();
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final String salt, final Padding padding) {
+ this(salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final Charset charset, final Padding padding) {
+ this(charset);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final String characterEncoding, final String salt, final Padding padding) {
+ this(characterEncoding, salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final Charset charset, final String salt, final Padding padding) {
+ this(charset, salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final Mode mode, final Padding padding) {
+ this(mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final String salt, final Mode mode, final Padding padding) {
+ this(salt, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final Charset charset, final Mode mode, final Padding padding) {
+ this(charset, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final String characterEncoding, final String salt, final Mode mode, final Padding padding) {
+ this(characterEncoding, salt, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public DESCrypto(final Charset charset, final String salt, final Mode mode, final Padding padding) {
+ this(charset, salt, mode);
+ this.padding = padding;
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null");
+
+ try{
+ SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding,
+ getProvider(), getKey());
+ return crypto.encrypt(object);
+ }catch(GeneralSecurityException e){
+ logger.error(e.getMessage());
+ throw new SecurityException(e);
+ }
+ }
+
+ @Override
+ public String decrypt(final CharSequence cs) {
+ Assert.isNull(cs, "Mcrypt decrypt object could not be null");
+
+ try{
+ SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding,
+ getProvider(), getKey());
+ return crypto.decrypt(cs);
+ }catch(GeneralSecurityException e){
+ logger.error(e.getMessage());
+ throw new SecurityException(e);
+ }
+ }
+
+ private Key getKey() throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {
+ final DESKeySpec dks = new DESKeySpec(getRealSalt().getBytes());
+ final SecretKeyFactory secretKeyFactory = getProvider() == null ?
+ SecretKeyFactory.getInstance(getAlgorithmName()) : SecretKeyFactory.getInstance(getAlgorithmName(),
+ getProvider());
+ return secretKeyFactory.generateSecret(dks);
+ }
+
+}
\ No newline at end of file
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/DiscuzCrypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/DiscuzCrypto.java
new file mode 100644
index 0000000..8c5e0e4
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/DiscuzCrypto.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ * =================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.datetime.DateTime;
+import com.buession.core.utils.Assert;
+import com.buession.core.utils.StringUtils;
+import com.buession.lang.Constants;
+import com.buession.security.crypto.utils.ObjectUtils;
+
+import java.nio.charset.Charset;
+import java.util.Optional;
+
+/**
+ * Discuz 版加解密
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class DiscuzCrypto extends AbstractCrypto {
+
+ private final static int KEY_LENGTH = 4;
+
+ /**
+ * 构造函数
+ */
+ public DiscuzCrypto() {
+ super(null);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public DiscuzCrypto(final String salt) {
+ super(null, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public DiscuzCrypto(final Charset charset) {
+ super(null, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public DiscuzCrypto(final String characterEncoding, final String salt) {
+ super(null, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public DiscuzCrypto(final Charset charset, final String salt) {
+ super(null, charset, salt);
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null");
+
+ Base64Crypto crypto = new Base64Crypto();
+ String s = ObjectUtils.toString(object);
+
+ String key = md5(md5(getRealSalt()));
+ String keya = md5(StringUtils.substr(key, 16, 16));
+ String keyb = StringUtils.substr(md5(StringUtils.replace(DateTime.microtime(), Constants.SPACING_STRING, ".")),
+ -4);
+ String keyc = getResultKey(key, keyb);
+
+ s = StringUtils.repeat('0', 10) + StringUtils.substr(md5(s + keya), 0, 16) + s;
+ s = StringUtils.replace(crypto.encrypt(mod(s, keyc)), "=", Constants.EMPTY_STRING);
+
+ return keyb + s;
+ }
+
+ @Override
+ public String decrypt(final CharSequence cs) {
+ Assert.isNull(cs, "Mcrypt decrypt object could not be null");
+
+ Base64Crypto crypto = new Base64Crypto();
+ String s = cs.toString();
+
+ String key = md5(md5(getRealSalt()));
+ String keya = md5(StringUtils.substr(key, 16, 16));
+ String keyb = StringUtils.substr(cs.toString(), 0, KEY_LENGTH);
+ String keyc = getResultKey(key, keyb);
+
+ s = crypto.decrypt(StringUtils.substr(s, KEY_LENGTH));
+
+ String result = mod(s, keyc);
+
+ String s1 = StringUtils.substr(result, 0, 10);
+ String s2 = StringUtils.substr(result, 26);
+ long j = Long.parseLong(s1);
+ String k1 = md5(s2 + keya);
+ long timestamp = DateTime.unixtime();
+
+ return (j == 0 || j - timestamp > 0) && StringUtils.substr(result, 10, 16).equals(StringUtils.substr(k1, 0,
+ 16)) ? s2 : Constants.EMPTY_STRING;
+ }
+
+ private static String md5(final String str) {
+ MD5Crypto crypto = new MD5Crypto();
+ return crypto.encrypt(Optional.ofNullable(str).orElse(Constants.EMPTY_STRING)).toLowerCase();
+ }
+
+ private static String getResultKey(final String str, final String key) {
+ if(key.length() <= 16){
+ return md5(key + StringUtils.substr(str, 0, 16) + StringUtils.substr(str, 16));
+ }else{
+ return md5(StringUtils.substr(key, 0, 16) + StringUtils.substr(key, 0, 16) + (StringUtils.substr(key, 16)) +
+ StringUtils.substr(str, 16));
+ }
+ }
+
+ private static String mod(final String str, final String key) {
+ int strLength = str.length();
+ char[] result = new char[strLength];
+
+ for(int i = 0; i < strLength; i++){
+ int j = str.charAt(i);
+ int k = key.charAt(i % 32);
+
+ result[i] = (char) (j ^ k);
+ }
+
+ return new String(result);
+ }
+
+}
\ No newline at end of file
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacMD5Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacMD5Crypto.java
new file mode 100644
index 0000000..7d10a17
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacMD5Crypto.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import org.apache.commons.codec.digest.HmacAlgorithms;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac MD5 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class HmacMD5Crypto extends AbstractHmacCrypto implements HmacCrypto {
+
+ /**
+ * 构造函数
+ */
+ public HmacMD5Crypto() {
+ super(Algorithm.HMAC_MD5);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public HmacMD5Crypto(final String salt) {
+ super(Algorithm.HMAC_MD5, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public HmacMD5Crypto(final Charset charset) {
+ super(Algorithm.HMAC_MD5, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacMD5Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.HMAC_MD5, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacMD5Crypto(final Charset charset, final String salt) {
+ super(Algorithm.HMAC_MD5, charset, salt);
+ }
+
+ @Override
+ protected HmacAlgorithms getHmacAlgorithms() {
+ return HmacAlgorithms.HMAC_MD5;
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha1Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha1Crypto.java
new file mode 100644
index 0000000..1c383cd
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha1Crypto.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import org.apache.commons.codec.digest.HmacAlgorithms;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac SHA-1 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class HmacSha1Crypto extends AbstractHmacCrypto implements HmacCrypto {
+
+ /**
+ * 构造函数
+ */
+ public HmacSha1Crypto() {
+ super(Algorithm.HMAC_SHA1);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha1Crypto(final String salt) {
+ super(Algorithm.HMAC_SHA1, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public HmacSha1Crypto(final Charset charset) {
+ super(Algorithm.HMAC_SHA1, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha1Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.HMAC_SHA1, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha1Crypto(final Charset charset, final String salt) {
+ super(Algorithm.HMAC_SHA1, charset, salt);
+ }
+
+ @Override
+ protected HmacAlgorithms getHmacAlgorithms() {
+ return HmacAlgorithms.HMAC_SHA_1;
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha224Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha224Crypto.java
new file mode 100644
index 0000000..e0c863a
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha224Crypto.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import org.apache.commons.codec.digest.HmacAlgorithms;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac SHA-224 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class HmacSha224Crypto extends AbstractHmacCrypto implements HmacCrypto {
+
+ /**
+ * 构造函数
+ */
+ public HmacSha224Crypto() {
+ super(Algorithm.HMAC_SHA224);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha224Crypto(final String salt) {
+ super(Algorithm.HMAC_SHA224, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public HmacSha224Crypto(final Charset charset) {
+ super(Algorithm.HMAC_SHA224, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha224Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.HMAC_SHA224, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha224Crypto(final Charset charset, final String salt) {
+ super(Algorithm.HMAC_SHA224, charset, salt);
+ }
+
+ @Override
+ protected HmacAlgorithms getHmacAlgorithms() {
+ return HmacAlgorithms.HMAC_SHA_224;
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha256Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha256Crypto.java
new file mode 100644
index 0000000..9e82657
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha256Crypto.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import org.apache.commons.codec.digest.HmacAlgorithms;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac SHA-256 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class HmacSha256Crypto extends AbstractHmacCrypto implements HmacCrypto {
+
+ /**
+ * 构造函数
+ */
+ public HmacSha256Crypto() {
+ super(Algorithm.HMAC_SHA256);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha256Crypto(final String salt) {
+ super(Algorithm.HMAC_SHA256, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public HmacSha256Crypto(final Charset charset) {
+ super(Algorithm.HMAC_SHA256, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha256Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.HMAC_SHA256, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha256Crypto(final Charset charset, final String salt) {
+ super(Algorithm.HMAC_SHA256, charset, salt);
+ }
+
+ @Override
+ protected HmacAlgorithms getHmacAlgorithms() {
+ return HmacAlgorithms.HMAC_SHA_256;
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha384Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha384Crypto.java
new file mode 100644
index 0000000..33890e3
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha384Crypto.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import org.apache.commons.codec.digest.HmacAlgorithms;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac SHA-384 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class HmacSha384Crypto extends AbstractHmacCrypto implements HmacCrypto {
+
+ /**
+ * 构造函数
+ */
+ public HmacSha384Crypto() {
+ super(Algorithm.HMAC_SHA384);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha384Crypto(final String salt) {
+ super(Algorithm.HMAC_SHA384, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public HmacSha384Crypto(final Charset charset) {
+ super(Algorithm.HMAC_SHA384, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha384Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.HMAC_SHA384, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha384Crypto(final Charset charset, final String salt) {
+ super(Algorithm.HMAC_SHA384, charset, salt);
+ }
+
+ @Override
+ protected HmacAlgorithms getHmacAlgorithms() {
+ return HmacAlgorithms.HMAC_SHA_384;
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha512Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha512Crypto.java
new file mode 100644
index 0000000..1541e00
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/HmacSha512Crypto.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import org.apache.commons.codec.digest.HmacAlgorithms;
+
+import java.nio.charset.Charset;
+
+/**
+ * Hmac SHA-512 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class HmacSha512Crypto extends AbstractHmacCrypto implements HmacCrypto {
+
+ /**
+ * 构造函数
+ */
+ public HmacSha512Crypto() {
+ super(Algorithm.HMAC_SHA512);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha512Crypto(final String salt) {
+ super(Algorithm.HMAC_SHA512, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public HmacSha512Crypto(final Charset charset) {
+ super(Algorithm.HMAC_SHA512, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha512Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.HMAC_SHA512, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public HmacSha512Crypto(final Charset charset, final String salt) {
+ super(Algorithm.HMAC_SHA512, charset, salt);
+ }
+
+ @Override
+ protected HmacAlgorithms getHmacAlgorithms() {
+ return HmacAlgorithms.HMAC_SHA_512;
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/MD5Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/MD5Crypto.java
new file mode 100644
index 0000000..75875b0
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/MD5Crypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * MD5 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class MD5Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public MD5Crypto() {
+ super(Algorithm.MD5);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public MD5Crypto(final String salt) {
+ super(Algorithm.MD5, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public MD5Crypto(final Charset charset) {
+ super(Algorithm.MD5, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public MD5Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.MD5, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public MD5Crypto(final Charset charset, final String salt) {
+ super(Algorithm.MD5, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public MD5Crypto(final Provider provider) {
+ super(Algorithm.MD5, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public MD5Crypto(final String salt, final Provider provider) {
+ super(Algorithm.MD5, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public MD5Crypto(final Charset charset, final Provider provider) {
+ super(Algorithm.MD5, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public MD5Crypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.MD5, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public MD5Crypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.MD5, charset, salt, provider);
+ }
+
+}
\ No newline at end of file
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha1Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha1Crypto.java
new file mode 100644
index 0000000..de3ace0
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha1Crypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * SHA-1 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sha1Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Sha1Crypto() {
+ super(Algorithm.SHA1);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sha1Crypto(final String salt) {
+ super(Algorithm.SHA1, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sha1Crypto(final Charset charset) {
+ super(Algorithm.SHA1, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha1Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SHA1, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha1Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SHA1, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha1Crypto(final Provider provider) {
+ super(Algorithm.SHA1, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha1Crypto(final String salt, final Provider provider) {
+ super(Algorithm.SHA1, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha1Crypto(final Charset charset, final Provider provider) {
+ super(Algorithm.SHA1, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha1Crypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.SHA1, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha1Crypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.SHA1, charset, salt, provider);
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha224Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha224Crypto.java
new file mode 100644
index 0000000..27a7340
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha224Crypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * SHA-224 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sha224Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Sha224Crypto() {
+ super(Algorithm.SHA224);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sha224Crypto(final String salt) {
+ super(Algorithm.SHA224, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sha224Crypto(final Charset charset) {
+ super(Algorithm.SHA224, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha224Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SHA224, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha224Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SHA224, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha224Crypto(final Provider provider) {
+ super(Algorithm.SHA224, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha224Crypto(final String salt, final Provider provider) {
+ super(Algorithm.SHA224, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha224Crypto(final Charset charset, final Provider provider) {
+ super(Algorithm.SHA224, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha224Crypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.SHA224, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha224Crypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.SHA224, charset, salt, provider);
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha256Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha256Crypto.java
new file mode 100644
index 0000000..54df673
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha256Crypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * SHA-256 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sha256Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Sha256Crypto() {
+ super(Algorithm.SHA256);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sha256Crypto(final String salt) {
+ super(Algorithm.SHA256, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sha256Crypto(final Charset charset) {
+ super(Algorithm.SHA256, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha256Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SHA256, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha256Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SHA256, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha256Crypto(final Provider provider) {
+ super(Algorithm.SHA256, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha256Crypto(final String salt, final Provider provider) {
+ super(Algorithm.SHA256, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha256Crypto(final Charset charset, final Provider provider) {
+ super(Algorithm.SHA256, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha256Crypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.SHA256, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha256Crypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.SHA256, charset, salt, provider);
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha384Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha384Crypto.java
new file mode 100644
index 0000000..ce8e0db
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha384Crypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * SHA-384 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sha384Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Sha384Crypto() {
+ super(Algorithm.SHA384);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sha384Crypto(final String salt) {
+ super(Algorithm.SHA384, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sha384Crypto(final Charset charset) {
+ super(Algorithm.SHA384, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha384Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SHA384, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha384Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SHA384, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha384Crypto(final Provider provider) {
+ super(Algorithm.SHA384, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha384Crypto(final String salt, final Provider provider) {
+ super(Algorithm.SHA384, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha384Crypto(final Charset charset, final Provider provider) {
+ super(Algorithm.SHA384, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha384Crypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.SHA384, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha384Crypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.SHA384, charset, salt, provider);
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha512Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha512Crypto.java
new file mode 100644
index 0000000..f076718
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sha512Crypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * Sha-512 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sha512Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Sha512Crypto() {
+ super(Algorithm.SHA512);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sha512Crypto(final String salt) {
+ super(Algorithm.SHA512, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sha512Crypto(final Charset charset) {
+ super(Algorithm.SHA512, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha512Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SHA512, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sha512Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SHA512, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha512Crypto(final Provider provider) {
+ super(Algorithm.SHA512, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha512Crypto(final String salt, final Provider provider) {
+ super(Algorithm.SHA512, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha512Crypto(final Charset charset, final Provider provider) {
+ super(Algorithm.SHA512, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha512Crypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.SHA512, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public Sha512Crypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.SHA512, charset, salt, provider);
+ }
+
+}
\ No newline at end of file
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/ShaCrypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/ShaCrypto.java
new file mode 100644
index 0000000..8bae20a
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/ShaCrypto.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import java.nio.charset.Charset;
+import java.security.Provider;
+
+/**
+ * SHA 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class ShaCrypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public ShaCrypto() {
+ super(Algorithm.SHA);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public ShaCrypto(final String salt) {
+ super(Algorithm.SHA, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public ShaCrypto(final Charset charset) {
+ super(Algorithm.SHA, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public ShaCrypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SHA, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public ShaCrypto(final Charset charset, final String salt) {
+ super(Algorithm.SHA, charset, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public ShaCrypto(final Provider provider) {
+ super(Algorithm.SHA, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public ShaCrypto(final String salt, final Provider provider) {
+ super(Algorithm.SHA, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public ShaCrypto(final Charset charset, final Provider provider) {
+ super(Algorithm.SHA, charset, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public ShaCrypto(final String characterEncoding, final String salt, final Provider provider) {
+ super(Algorithm.SHA, characterEncoding, salt, provider);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param provider
+ * 信息摘要对象的提供者
+ */
+ public ShaCrypto(final Charset charset, final String salt, final Provider provider) {
+ super(Algorithm.SHA, charset, salt, provider);
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sm3Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sm3Crypto.java
new file mode 100644
index 0000000..41d2117
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sm3Crypto.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.utils.Assert;
+import com.buession.security.crypto.utils.ObjectUtils;
+import org.apache.commons.codec.binary.Base64;
+import org.bouncycastle.crypto.digests.SM3Digest;
+
+import java.nio.charset.Charset;
+
+/**
+ * SM3 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sm3Crypto extends AbstractCrypto implements HashCrypto {
+
+ /**
+ * 构造函数
+ */
+ public Sm3Crypto() {
+ super(Algorithm.SM3);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sm3Crypto(final String salt) {
+ super(Algorithm.SM3, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sm3Crypto(final Charset charset) {
+ super(Algorithm.SM3, charset);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sm3Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SM3, characterEncoding, salt);
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sm3Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SM3, charset, salt);
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null");
+
+ SM3Digest sm3Digest = new SM3Digest();
+ byte[] salt = ObjectUtils.toBytes(getSalt(), getCharset());
+ byte[] in = ObjectUtils.toBytes(object, getCharset());
+
+ byte[] data = new byte[salt.length + in.length];
+ System.arraycopy(salt, 0, data, 0, salt.length);
+ System.arraycopy(in, 0, data, salt.length, in.length);
+
+ sm3Digest.update(data, 0, data.length);
+ byte[] hash = new byte[sm3Digest.getDigestSize()];
+ sm3Digest.doFinal(hash, 0);
+
+ return Base64.encodeBase64String(hash);
+ }
+
+}
diff --git a/buession-security-crypto/src/main/java/com/buession/security/crypto/Sm4Crypto.java b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sm4Crypto.java
new file mode 100644
index 0000000..25ce535
--- /dev/null
+++ b/buession-security-crypto/src/main/java/com/buession/security/crypto/Sm4Crypto.java
@@ -0,0 +1,343 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+ * See the NOTICE file distributed with this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and limitations under the License.
+ *
+ * =========================================================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals on behalf of the
+ * Apache Software Foundation. For more information on the Apache Software Foundation, please see
+ * .
+ *
+ * +-------------------------------------------------------------------------------------------------------+
+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt |
+ * | Author: Yong.Teng |
+ * | Copyright @ 2013-2023 Buession.com Inc. |
+ * +-------------------------------------------------------------------------------------------------------+
+ */
+package com.buession.security.crypto;
+
+import com.buession.core.utils.Assert;
+import com.buession.security.crypto.internal.SymmetricalCrypto;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+
+import java.nio.charset.Charset;
+import java.security.GeneralSecurityException;
+
+/**
+ * SM4 加密对象
+ *
+ * @author Yong.Teng
+ * @since 2.3.2
+ */
+public final class Sm4Crypto extends AbstractCrypto {
+
+ /**
+ * 加密模式
+ */
+ private Mode mode = Mode.ECB;
+
+ /**
+ * 补码方式
+ */
+ private Padding padding = Padding.PKCS5;
+
+ /**
+ * 构造函数
+ */
+ public Sm4Crypto() {
+ super(Algorithm.SM4, new BouncyCastleProvider());
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ */
+ public Sm4Crypto(final String salt) {
+ super(Algorithm.SM4, salt, new BouncyCastleProvider());
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ */
+ public Sm4Crypto(final Charset charset) {
+ super(Algorithm.SM4, charset, new BouncyCastleProvider());
+ }
+
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sm4Crypto(final String characterEncoding, final String salt) {
+ super(Algorithm.SM4, characterEncoding, salt, new BouncyCastleProvider());
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ */
+ public Sm4Crypto(final Charset charset, final String salt) {
+ super(Algorithm.SM4, charset, salt, new BouncyCastleProvider());
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param mode
+ * 加密模式
+ */
+ public Sm4Crypto(final Mode mode) {
+ this();
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public Sm4Crypto(final String salt, final Mode mode) {
+ this(salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param mode
+ * 加密模式
+ */
+ public Sm4Crypto(final Charset charset, final Mode mode) {
+ this(charset);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public Sm4Crypto(final String characterEncoding, final String salt, final Mode mode) {
+ this(characterEncoding, salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ */
+ public Sm4Crypto(final Charset charset, final String salt, final Mode mode) {
+ this(charset, salt);
+ this.mode = mode;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final Padding padding) {
+ this();
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final String salt, final Padding padding) {
+ this(salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final Charset charset, final Padding padding) {
+ this(charset);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final String characterEncoding, final String salt, final Padding padding) {
+ this(characterEncoding, salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final Charset charset, final String salt, final Padding padding) {
+ this(charset, salt);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final Mode mode, final Padding padding) {
+ this(mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final String salt, final Mode mode, final Padding padding) {
+ this(salt, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final Charset charset, final Mode mode, final Padding padding) {
+ this(charset, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param characterEncoding
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final String characterEncoding, final String salt, final Mode mode, final Padding padding) {
+ this(characterEncoding, salt, mode);
+ this.padding = padding;
+ }
+
+ /**
+ * 构造函数
+ *
+ * @param charset
+ * 字符编码
+ * @param salt
+ * 加密密钥
+ * @param mode
+ * 加密模式
+ * @param padding
+ * 补码方式
+ */
+ public Sm4Crypto(final Charset charset, final String salt, final Mode mode, final Padding padding) {
+ this(charset, salt, mode);
+ this.padding = padding;
+ }
+
+ @Override
+ public String encrypt(final Object object) {
+ Assert.isNull(object, "Mcrypt encrypt object could not be null");
+
+ try{
+ SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding, getProvider(),
+ getSalt());
+ return crypto.encrypt(object);
+ }catch(GeneralSecurityException e){
+ logger.error(e.getMessage());
+ throw new SecurityException(e);
+ }
+ }
+
+ @Override
+ public String decrypt(final CharSequence cs) {
+ Assert.isNull(cs, "Mcrypt decrypt object could not be null");
+
+ try{
+ SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding, getProvider(),
+ getSalt());
+ return crypto.decrypt(cs);
+ }catch(GeneralSecurityException e){
+ logger.error(e.getMessage());
+ throw new SecurityException(e);
+ }
+ }
+
+}
diff --git a/buession-security-mcrypt/pom.xml b/buession-security-mcrypt/pom.xml
index 5e14f14..56d2a3a 100644
--- a/buession-security-mcrypt/pom.xml
+++ b/buession-security-mcrypt/pom.xml
@@ -7,7 +7,7 @@
com.buession.security
buession-security-parent
../buession-security-parent
- 2.3.1
+ 2.3.2
buession-security-mcrypt
https://security.buession.com/
diff --git a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/AESMcrypt.java b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/AESMcrypt.java
index 5244b15..72865fa 100644
--- a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/AESMcrypt.java
+++ b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/AESMcrypt.java
@@ -26,11 +26,9 @@
*/
package com.buession.security.mcrypt;
-import com.buession.core.utils.Assert;
-import com.buession.security.crypto.internal.SymmetricalCrypto;
+import com.buession.security.crypto.AESCrypto;
import java.nio.charset.Charset;
-import java.security.GeneralSecurityException;
/**
* AES 加密对象
@@ -550,30 +548,14 @@ public AESMcrypt(final Charset charset, final String salt, final com.buession.se
@Override
public String encrypt(final Object object) {
- Assert.isNull(object, "Mcrypt encrypt object could not be null");
-
- try{
- SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding, getProvider(),
- getSalt());
- return crypto.encrypt(object);
- }catch(GeneralSecurityException e){
- logger.error(e.getMessage());
- throw new SecurityException(e);
- }
+ final AESCrypto crypto = new AESCrypto(getCharset(), getSalt(), mode, padding);
+ return crypto.encrypt(object);
}
@Override
public String decrypt(final CharSequence cs) {
- Assert.isNull(cs, "Mcrypt decrypt object could not be null");
-
- try{
- SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding,
- getProvider(), getSalt());
- return crypto.decrypt(cs);
- }catch(GeneralSecurityException e){
- logger.error(e.getMessage());
- throw new SecurityException(e);
- }
+ final AESCrypto crypto = new AESCrypto(getCharset(), getSalt(), mode, padding);
+ return crypto.decrypt(cs);
}
/**
diff --git a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Base64Mcrypt.java b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Base64Mcrypt.java
index d15c553..359b4e0 100644
--- a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Base64Mcrypt.java
+++ b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Base64Mcrypt.java
@@ -26,10 +26,7 @@
*/
package com.buession.security.mcrypt;
-import com.buession.core.utils.Assert;
-import com.buession.security.crypto.utils.ObjectUtils;
-
-import java.util.Base64;
+import com.buession.security.crypto.Base64Crypto;
import java.nio.charset.Charset;
@@ -94,15 +91,14 @@ public Base64Mcrypt(final Charset charset, final String salt) {
@Override
public String encrypt(final Object object) {
- Assert.isNull(object, "Mcrypt encrypt object could not be null.");
- return Base64.getEncoder()
- .encodeToString((ObjectUtils.toString(object) + getRealSalt()).getBytes(getCharset()));
+ final Base64Crypto crypto = new Base64Crypto(getCharset(), getSalt());
+ return crypto.encrypt(object);
}
@Override
public String decrypt(final CharSequence cs) {
- Assert.isNull(cs, "Mcrypt decrypt object could not be null.");
- return new String(Base64.getDecoder().decode(cs.toString()), getCharset());
+ final Base64Crypto crypto = new Base64Crypto(getCharset(), getSalt());
+ return crypto.decrypt(cs);
}
}
\ No newline at end of file
diff --git a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DESMcrypt.java b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DESMcrypt.java
index 9c6e408..4ad633a 100644
--- a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DESMcrypt.java
+++ b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DESMcrypt.java
@@ -26,17 +26,9 @@
*/
package com.buession.security.mcrypt;
-import com.buession.core.utils.Assert;
-import com.buession.security.crypto.internal.SymmetricalCrypto;
+import com.buession.security.crypto.DESCrypto;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.DESKeySpec;
import java.nio.charset.Charset;
-import java.security.GeneralSecurityException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.spec.InvalidKeySpecException;
/**
* DES 加密对象
@@ -554,38 +546,14 @@ public DESMcrypt(final Charset charset, final String salt, final com.buession.se
@Override
public String encrypt(final Object object) {
- Assert.isNull(object, "Mcrypt encrypt object could not be null");
-
- try{
- SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding,
- getProvider(), getKey());
- return crypto.encrypt(object);
- }catch(GeneralSecurityException e){
- logger.error(e.getMessage());
- throw new SecurityException(e);
- }
+ final DESCrypto crypto = new DESCrypto(getCharset(), getSalt(), mode, padding);
+ return crypto.encrypt(object);
}
@Override
public String decrypt(final CharSequence cs) {
- Assert.isNull(cs, "Mcrypt decrypt object could not be null");
-
- try{
- SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding,
- getProvider(), getKey());
- return crypto.decrypt(cs);
- }catch(GeneralSecurityException e){
- logger.error(e.getMessage());
- throw new SecurityException(e);
- }
- }
-
- private Key getKey() throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {
- final DESKeySpec dks = new DESKeySpec(getRealSalt().getBytes());
- final SecretKeyFactory secretKeyFactory = getProvider() == null ?
- SecretKeyFactory.getInstance(getAlgorithmName()) : SecretKeyFactory.getInstance(getAlgorithmName(),
- getProvider());
- return secretKeyFactory.generateSecret(dks);
+ final DESCrypto crypto = new DESCrypto(getCharset(), getSalt(), mode, padding);
+ return crypto.decrypt(cs);
}
/**
diff --git a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DiscuzMycrypt.java b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DiscuzMycrypt.java
index 8d85e3f..e6db3eb 100644
--- a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DiscuzMycrypt.java
+++ b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/DiscuzMycrypt.java
@@ -26,12 +26,8 @@
*/
package com.buession.security.mcrypt;
-import com.buession.core.datetime.DateTime;
-import com.buession.core.utils.Assert;
-import com.buession.core.utils.StringUtils;
-import com.buession.lang.Constants;
import com.buession.security.crypto.Algorithm;
-import com.buession.security.crypto.utils.ObjectUtils;
+import com.buession.security.crypto.DiscuzCrypto;
import java.nio.charset.Charset;
@@ -42,8 +38,6 @@
*/
public final class DiscuzMycrypt extends AbstractMcrypt {
- private final static int KEY_LENGTH = 4;
-
/**
* 构造函数
*/
@@ -98,75 +92,14 @@ public DiscuzMycrypt(final Charset charset, final String salt) {
@Override
public String encrypt(final Object object) {
- Assert.isNull(object, "Mcrypt encrypt object could not be null");
-
- Base64Mcrypt base64Mcrypt = new Base64Mcrypt();
- String s = ObjectUtils.toString(object);
-
- String key = md5(md5(getRealSalt()));
- String keya = md5(StringUtils.substr(key, 16, 16));
- String keyb = StringUtils.substr(md5(StringUtils.replace(DateTime.microtime(), Constants.SPACING_STRING, ".")),
- -4);
- String keyc = getResultKey(key, keyb);
-
- s = StringUtils.repeat('0', 10) + StringUtils.substr(md5(s + keya), 0, 16) + s;
- s = StringUtils.replace(base64Mcrypt.encode(mod(s, keyc)), "=", Constants.EMPTY_STRING);
-
- return keyb + s;
+ final DiscuzCrypto crypto = new DiscuzCrypto(getCharset(), getSalt());
+ return crypto.encrypt(object);
}
@Override
public String decrypt(final CharSequence cs) {
- Assert.isNull(cs, "Mcrypt decrypt object could not be null");
-
- Base64Mcrypt base64Mcrypt = new Base64Mcrypt();
- String s = cs.toString();
-
- String key = md5(md5(getRealSalt()));
- String keya = md5(StringUtils.substr(key, 16, 16));
- String keyb = StringUtils.substr(cs.toString(), 0, KEY_LENGTH);
- String keyc = getResultKey(key, keyb);
-
- s = base64Mcrypt.decrypt(StringUtils.substr(s, KEY_LENGTH));
-
- String result = mod(s, keyc);
-
- String s1 = StringUtils.substr(result, 0, 10);
- String s2 = StringUtils.substr(result, 26);
- long j = Long.parseLong(s1);
- String k1 = md5(s2 + keya);
- long timestamp = DateTime.unixtime();
-
- return (j == 0 || j - timestamp > 0) && StringUtils.substr(result, 10, 16).equals(StringUtils.substr(k1, 0,
- 16)) ? s2 : Constants.EMPTY_STRING;
- }
-
- private static String md5(final String str) {
- MD5Mcrypt md5Mcrypt = new MD5Mcrypt();
- return md5Mcrypt.encrypt(str == null ? Constants.EMPTY_STRING : str).toLowerCase();
- }
-
- private static String getResultKey(final String str, final String key) {
- if(key.length() <= 16){
- return md5(key + StringUtils.substr(str, 0, 16) + StringUtils.substr(str, 16));
- }else{
- return md5(StringUtils.substr(key, 0, 16) + StringUtils.substr(key, 0, 16) + (StringUtils.substr(key, 16)) +
- StringUtils.substr(str, 16));
- }
- }
-
- private static String mod(final String str, final String key) {
- int strLength = str.length();
- char[] result = new char[strLength];
-
- for(int i = 0; i < strLength; i++){
- int j = str.charAt(i);
- int k = key.charAt(i % 32);
-
- result[i] = (char) (j ^ k);
- }
-
- return new String(result);
+ final DiscuzCrypto crypto = new DiscuzCrypto(getCharset(), getSalt());
+ return crypto.decrypt(cs);
}
}
\ No newline at end of file
diff --git a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm3Mcrypt.java b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm3Mcrypt.java
index 50da930..3cdac14 100644
--- a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm3Mcrypt.java
+++ b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm3Mcrypt.java
@@ -24,11 +24,8 @@
*/
package com.buession.security.mcrypt;
-import com.buession.core.utils.Assert;
import com.buession.security.crypto.HashCrypto;
-import com.buession.security.crypto.utils.ObjectUtils;
-import org.apache.commons.codec.binary.Base64;
-import org.bouncycastle.crypto.digests.SM3Digest;
+import com.buession.security.crypto.Sm3Crypto;
import java.nio.charset.Charset;
@@ -94,21 +91,8 @@ public Sm3Mcrypt(final Charset charset, final String salt) {
@Override
public String encrypt(final Object object) {
- Assert.isNull(object, "Mcrypt encrypt object could not be null");
-
- SM3Digest sm3Digest = new SM3Digest();
- byte[] salt = ObjectUtils.toBytes(getSalt(), getCharset());
- byte[] in = ObjectUtils.toBytes(object, getCharset());
-
- byte[] data = new byte[salt.length + in.length];
- System.arraycopy(salt, 0, data, 0, salt.length);
- System.arraycopy(in, 0, data, salt.length, in.length);
-
- sm3Digest.update(data, 0, data.length);
- byte[] hash = new byte[sm3Digest.getDigestSize()];
- sm3Digest.doFinal(hash, 0);
-
- return Base64.encodeBase64String(hash);
+ final Sm3Crypto crypto = new Sm3Crypto(getCharset(), getSalt());
+ return crypto.encrypt(object);
}
}
diff --git a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm4Mcrypt.java b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm4Mcrypt.java
index 5825894..a44a231 100644
--- a/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm4Mcrypt.java
+++ b/buession-security-mcrypt/src/main/java/com/buession/security/mcrypt/Sm4Mcrypt.java
@@ -24,14 +24,12 @@
*/
package com.buession.security.mcrypt;
-import com.buession.core.utils.Assert;
import com.buession.security.crypto.Mode;
import com.buession.security.crypto.Padding;
-import com.buession.security.crypto.internal.SymmetricalCrypto;
+import com.buession.security.crypto.Sm4Crypto;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.nio.charset.Charset;
-import java.security.GeneralSecurityException;
/**
* SM4 加密对象
@@ -295,30 +293,14 @@ public Sm4Mcrypt(final Charset charset, final String salt, final Mode mode, fina
@Override
public String encrypt(final Object object) {
- Assert.isNull(object, "Mcrypt encrypt object could not be null");
-
- try{
- SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding, getProvider(),
- getSalt());
- return crypto.encrypt(object);
- }catch(GeneralSecurityException e){
- logger.error(e.getMessage());
- throw new SecurityException(e);
- }
+ final Sm4Crypto crypto = new Sm4Crypto(getCharset(), getSalt(), mode, padding);
+ return crypto.encrypt(object);
}
@Override
public String decrypt(final CharSequence cs) {
- Assert.isNull(cs, "Mcrypt decrypt object could not be null");
-
- try{
- SymmetricalCrypto crypto = new SymmetricalCrypto(getAlgorithm(), getCharset(), mode, padding, getProvider(),
- getSalt());
- return crypto.decrypt(cs);
- }catch(GeneralSecurityException e){
- logger.error(e.getMessage());
- throw new SecurityException(e);
- }
+ final Sm4Crypto crypto = new Sm4Crypto(getCharset(), getSalt(), mode, padding);
+ return crypto.decrypt(cs);
}
}
diff --git a/buession-security-pac4j/pom.xml b/buession-security-pac4j/pom.xml
index 06e0ef7..7ce11c5 100644
--- a/buession-security-pac4j/pom.xml
+++ b/buession-security-pac4j/pom.xml
@@ -7,7 +7,7 @@
com.buession.security
buession-security-parent
../buession-security-parent
- 2.3.1
+ 2.3.2
buession-security-pac4j
https://security.buession.com/
@@ -160,6 +160,12 @@
org.pac4j
pac4j-cas
+
+
+ org.bouncycastle
+ *
+
+
org.pac4j
diff --git a/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/PrincipalAnnotationUtils.java b/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/PrincipalAnnotationUtils.java
index 0d0f7d6..18a5ffa 100644
--- a/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/PrincipalAnnotationUtils.java
+++ b/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/PrincipalAnnotationUtils.java
@@ -38,6 +38,28 @@ public class PrincipalAnnotationUtils {
private final static Logger logger = LoggerFactory.getLogger(PrincipalAnnotationUtils.class);
+ /**
+ * 判断是否支持
+ *
+ * @param parameter
+ * {@link MethodParameter}
+ *
+ * @return true / false
+ *
+ * @since 2.3.2
+ */
+ public static boolean supportsParameter(MethodParameter parameter) {
+ if(parameter.hasParameterAnnotation(Principal.class) == true){
+ final Class> parameterType = parameter.getParameterType();
+
+ return parameterType.isPrimitive() == false && parameterType.isArray() == false &&
+ parameterType.isAnnotation() == false && parameterType.isEnum() == false &&
+ parameterType.isInterface() == false;
+ }
+
+ return false;
+ }
+
public static T toObject(final Pac4jPrincipal principal, final Principal annotation, final Class paramType) {
if(principal == null){
return null;
diff --git a/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/reactive/PrincipalMethodArgumentResolver.java b/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/reactive/PrincipalMethodArgumentResolver.java
index fc44a16..64c1465 100644
--- a/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/reactive/PrincipalMethodArgumentResolver.java
+++ b/buession-security-pac4j/src/main/java/com/buession/security/pac4j/annotation/reactive/PrincipalMethodArgumentResolver.java
@@ -33,9 +33,8 @@
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
-import org.springframework.web.reactive.result.method.annotation.AbstractNamedValueArgumentResolver;
+import org.springframework.web.reactive.result.method.annotation.AbstractNamedValueSyncArgumentResolver;
import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
/**
* 方法参数注解 {@link Principal} 解析器
@@ -43,7 +42,7 @@
* @author Yong.Teng
* @since 2.1.0
*/
-public class PrincipalMethodArgumentResolver extends AbstractNamedValueArgumentResolver {
+public class PrincipalMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver {
public PrincipalMethodArgumentResolver(ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) {
super(factory, registry);
@@ -51,18 +50,18 @@ public PrincipalMethodArgumentResolver(ConfigurableBeanFactory factory, Reactive
@Override
public boolean supportsParameter(MethodParameter parameter) {
- return parameter.hasParameterAnnotation(Principal.class);
+ return PrincipalAnnotationUtils.supportsParameter(parameter);
}
@Override
- protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
- Principal principal = parameter.getParameterAnnotation(Principal.class);
+ protected NamedValueInfo createNamedValueInfo(MethodParameter methodParameter) {
+ Principal principal = methodParameter.getParameterAnnotation(Principal.class);
Assert.isNull(principal, "No Principal annotation");
- return new PrincipalNamedValueInfo(principal, parameter.getNestedParameterType());
+ return new PrincipalNamedValueInfo(principal, methodParameter.getNestedParameterType());
}
@Override
- protected Mono
- javax.servlet.jsp
- javax.servlet.jsp-api
- 2.3.3
+ jakarta.servlet.jsp
+ jakarta.servlet.jsp-api
provided
true
diff --git a/buession-security-shiro/src/main/java/com/buession/security/shiro/cache/RedisCache.java b/buession-security-shiro/src/main/java/com/buession/security/shiro/cache/RedisCache.java
index 1b166c1..218bfb3 100644
--- a/buession-security-shiro/src/main/java/com/buession/security/shiro/cache/RedisCache.java
+++ b/buession-security-shiro/src/main/java/com/buession/security/shiro/cache/RedisCache.java
@@ -146,7 +146,7 @@ public RedisCache(RedisManager redisManager, String keyPrefix, int expire, Strin
*
* @since 1.2.2
*/
- public RedisCache(RedisSerializer keySerializer, RedisSerializer