diff --git a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/JceCipher.java b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/JceCipher.java
index d4dbd5c07..689c95695 100644
--- a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/JceCipher.java
+++ b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/JceCipher.java
@@ -13,7 +13,7 @@
package org.dromara.hutool.crypto;
import org.dromara.hutool.core.lang.Assert;
-import org.dromara.hutool.core.lang.wrapper.Wrapper;
+import org.dromara.hutool.core.lang.wrapper.SimpleWrapper;
import javax.crypto.ShortBufferException;
import java.security.InvalidAlgorithmParameterException;
@@ -27,9 +27,7 @@ import java.security.spec.AlgorithmParameterSpec;
*
* @author Looly
*/
-public class JceCipher implements Cipher, Wrapper {
-
- private final javax.crypto.Cipher cipher;
+public class JceCipher extends SimpleWrapper implements Cipher {
/**
* 构造
@@ -43,30 +41,25 @@ public class JceCipher implements Cipher, Wrapper {
/**
* 构造
*
- * @param cipher {@link javax.crypto.Cipher}
+ * @param cipher {@link javax.crypto.Cipher},可以通过{@link javax.crypto.Cipher#getInstance(String)}创建
*/
public JceCipher(final javax.crypto.Cipher cipher) {
- this.cipher = Assert.notNull(cipher);
- }
-
- @Override
- public javax.crypto.Cipher getRaw() {
- return this.cipher;
+ super(Assert.notNull(cipher));
}
@Override
public String getAlgorithmName() {
- return this.cipher.getAlgorithm();
+ return getRaw().getAlgorithm();
}
@Override
public int getBlockSize() {
- return this.cipher.getBlockSize();
+ return getRaw().getBlockSize();
}
@Override
public int getOutputSize(final int len) {
- return this.cipher.getOutputSize(len);
+ return getRaw().getOutputSize(len);
}
@Override
@@ -89,7 +82,7 @@ public class JceCipher implements Cipher, Wrapper {
* @throws InvalidKeyException 无效key
*/
public void init(final int mode, final JceParameters jceParameters) throws InvalidAlgorithmParameterException, InvalidKeyException {
- final javax.crypto.Cipher cipher = this.cipher;
+ final javax.crypto.Cipher cipher = getRaw();
if (null != jceParameters.parameterSpec) {
if (null != jceParameters.random) {
cipher.init(mode, jceParameters.key, jceParameters.parameterSpec, jceParameters.random);
@@ -108,7 +101,7 @@ public class JceCipher implements Cipher, Wrapper {
@Override
public int process(final byte[] in, final int inOff, final int len, final byte[] out, final int outOff) {
try {
- return this.cipher.update(in, inOff, len, out, outOff);
+ return getRaw().update(in, inOff, len, out, outOff);
} catch (final ShortBufferException e) {
throw new CryptoException(e);
}
@@ -117,7 +110,7 @@ public class JceCipher implements Cipher, Wrapper {
@Override
public int doFinal(final byte[] out, final int outOff) {
try {
- return this.cipher.doFinal(out, outOff);
+ return getRaw().doFinal(out, outOff);
} catch (final Exception e) {
throw new CryptoException(e);
}
@@ -126,7 +119,7 @@ public class JceCipher implements Cipher, Wrapper {
@Override
public byte[] processFinal(final byte[] data) {
try {
- return this.cipher.doFinal(data);
+ return getRaw().doFinal(data);
} catch (final Exception e) {
throw new CryptoException(e);
}
diff --git a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/BCCipher.java b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/BCCipher.java
index 44f4eccfd..3281675a1 100644
--- a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/BCCipher.java
+++ b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/bc/BCCipher.java
@@ -12,10 +12,7 @@
package org.dromara.hutool.crypto.bc;
-import org.bouncycastle.crypto.BufferedBlockCipher;
-import org.bouncycastle.crypto.CipherParameters;
-import org.bouncycastle.crypto.InvalidCipherTextException;
-import org.bouncycastle.crypto.StreamCipher;
+import org.bouncycastle.crypto.*;
import org.bouncycastle.crypto.modes.AEADBlockCipher;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.wrapper.Wrapper;
@@ -23,10 +20,13 @@ import org.dromara.hutool.crypto.Cipher;
import org.dromara.hutool.crypto.CipherMode;
import org.dromara.hutool.crypto.CryptoException;
+import java.util.Arrays;
+
/**
* 基于BouncyCastle库封装的加密解密实现,包装包括:
*
* - {@link BufferedBlockCipher}
+ * - {@link BlockCipher}
* - {@link StreamCipher}
* - {@link AEADBlockCipher}
*
@@ -38,7 +38,11 @@ public class BCCipher implements Cipher, Wrapper
*
+ *
+ * MacEngineFactory
+ * ||(创建)
+ * MacEngine----------------(包装)-----------------> Mac
+ * _____|_______________ |
+ * / \ HMac
+ * JCEMacEngine BCMacEngine
+ * / \
+ * BCHMacEngine CBCBlockCipherMacEngine
+ * |
+ * SM4MacEngine
+ *
+ *
+ * 通过MacEngine,封装支持了BouncyCastle和JCE实现的一些MAC算法,通过MacEngineFactory自动根据算法名称创建对应对象。
+ *
* @author Looly
* @since 4.5.13
*/
diff --git a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/digest/otp/package-info.java b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/digest/otp/package-info.java
index 29e540aac..695306155 100644
--- a/hutool-crypto/src/main/java/org/dromara/hutool/crypto/digest/otp/package-info.java
+++ b/hutool-crypto/src/main/java/org/dromara/hutool/crypto/digest/otp/package-info.java
@@ -21,6 +21,12 @@
* Truncate:是一个函数,就是怎么截取加密后的串,并取加密后串的哪些字段组成一个数字。
*
*
+ * 实现包括:
+ *
+ * - HMAC-based one-time passwords (HOTP) 基于HMAC算法一次性密码生成器
+ * - time-based one-time passwords (TOTP) 基于时间戳算法的一次性密码生成器
+ *
+ *
* @author looly
*/
package org.dromara.hutool.crypto.digest.otp;
diff --git a/hutool-db/src/main/java/org/dromara/hutool/db/ds/DSWrapper.java b/hutool-db/src/main/java/org/dromara/hutool/db/ds/DSWrapper.java
index 1109de772..21177f3b3 100644
--- a/hutool-db/src/main/java/org/dromara/hutool/db/ds/DSWrapper.java
+++ b/hutool-db/src/main/java/org/dromara/hutool/db/ds/DSWrapper.java
@@ -14,7 +14,7 @@ package org.dromara.hutool.db.ds;
import org.dromara.hutool.core.exception.CloneException;
import org.dromara.hutool.core.io.IoUtil;
-import org.dromara.hutool.core.lang.wrapper.Wrapper;
+import org.dromara.hutool.core.lang.wrapper.SimpleWrapper;
import javax.sql.DataSource;
import java.io.Closeable;
@@ -34,9 +34,8 @@ import java.util.logging.Logger;
* @author looly
* @since 4.3.2
*/
-public class DSWrapper implements Wrapper, DataSource, Closeable, Cloneable {
+public class DSWrapper extends SimpleWrapper implements DataSource, Closeable, Cloneable {
- private final DataSource ds;
private final String driver;
/**
@@ -57,7 +56,7 @@ public class DSWrapper implements Wrapper, DataSource, Closeable, Cl
* @param driver 数据库驱动类名
*/
public DSWrapper(final DataSource ds, final String driver) {
- this.ds = ds;
+ super(ds);
this.driver = driver;
}
@@ -70,65 +69,56 @@ public class DSWrapper implements Wrapper, DataSource, Closeable, Cl
return this.driver;
}
- /**
- * 获取原始的数据源
- *
- * @return 原始数据源
- */
- @Override
- public DataSource getRaw() {
- return this.ds;
- }
-
@Override
public PrintWriter getLogWriter() throws SQLException {
- return ds.getLogWriter();
+ return getRaw().getLogWriter();
}
@Override
public void setLogWriter(final PrintWriter out) throws SQLException {
- ds.setLogWriter(out);
+ getRaw().setLogWriter(out);
}
@Override
public void setLoginTimeout(final int seconds) throws SQLException {
- ds.setLoginTimeout(seconds);
+ getRaw().setLoginTimeout(seconds);
}
@Override
public int getLoginTimeout() throws SQLException {
- return ds.getLoginTimeout();
+ return getRaw().getLoginTimeout();
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
- return ds.getParentLogger();
+ return getRaw().getParentLogger();
}
@Override
public T unwrap(final Class iface) throws SQLException {
- return ds.unwrap(iface);
+ return getRaw().unwrap(iface);
}
@Override
public boolean isWrapperFor(final Class> iface) throws SQLException {
- return ds.isWrapperFor(iface);
+ return getRaw().isWrapperFor(iface);
}
@Override
public Connection getConnection() throws SQLException {
- return ds.getConnection();
+ return getRaw().getConnection();
}
@Override
public Connection getConnection(final String username, final String password) throws SQLException {
- return ds.getConnection(username, password);
+ return getRaw().getConnection(username, password);
}
@Override
public void close() {
- if (this.ds instanceof AutoCloseable) {
- IoUtil.closeQuietly((AutoCloseable) this.ds);
+ final DataSource ds = getRaw();
+ if (ds instanceof AutoCloseable) {
+ IoUtil.closeQuietly((AutoCloseable) ds);
}
}