mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.lang.func.Wrapper;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
@@ -18,7 +20,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
||||
* @author looly
|
||||
* @since 5.7.17
|
||||
*/
|
||||
public class CipherWrapper {
|
||||
public class CipherWrapper implements Wrapper<Cipher> {
|
||||
|
||||
private final Cipher cipher;
|
||||
/**
|
||||
@@ -85,7 +87,8 @@ public class CipherWrapper {
|
||||
*
|
||||
* @return {@link Cipher}
|
||||
*/
|
||||
public Cipher getCipher() {
|
||||
@Override
|
||||
public Cipher getRaw() {
|
||||
return this.cipher;
|
||||
}
|
||||
|
||||
|
@@ -289,7 +289,7 @@ public class AsymmetricCrypto extends AbstractAsymmetricCrypto<AsymmetricCrypto>
|
||||
* @since 5.4.3
|
||||
*/
|
||||
public Cipher getCipher() {
|
||||
return this.cipherWrapper.getCipher();
|
||||
return this.cipherWrapper.getRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,6 +364,6 @@ public class AsymmetricCrypto extends AbstractAsymmetricCrypto<AsymmetricCrypto>
|
||||
* @throws InvalidKeyException 异常KEY错误
|
||||
*/
|
||||
private Cipher initMode(final int mode, final Key key) throws InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
return this.cipherWrapper.initMode(mode, key).getCipher();
|
||||
return this.cipherWrapper.initMode(mode, key).getRaw();
|
||||
}
|
||||
}
|
||||
|
@@ -166,7 +166,7 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
|
||||
* @return 加密或解密
|
||||
*/
|
||||
public Cipher getCipher() {
|
||||
return cipherWrapper.getCipher();
|
||||
return cipherWrapper.getRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +242,7 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
|
||||
* @since 5.6.8
|
||||
*/
|
||||
public byte[] update(final byte[] data) {
|
||||
final Cipher cipher = cipherWrapper.getCipher();
|
||||
final Cipher cipher = cipherWrapper.getRaw();
|
||||
lock.lock();
|
||||
try {
|
||||
return cipher.update(paddingDataWithZero(data, cipher.getBlockSize()));
|
||||
@@ -383,7 +383,7 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
|
||||
private SymmetricCrypto initParams(final String algorithm, AlgorithmParameterSpec paramsSpec) {
|
||||
if (null == paramsSpec) {
|
||||
byte[] iv = Opt.ofNullable(cipherWrapper)
|
||||
.map(CipherWrapper::getCipher).map(Cipher::getIV).get();
|
||||
.map(CipherWrapper::getRaw).map(Cipher::getIV).get();
|
||||
|
||||
// 随机IV
|
||||
if (StrUtil.startWithIgnoreCase(algorithm, "PBE")) {
|
||||
@@ -412,7 +412,7 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
|
||||
* @throws InvalidAlgorithmParameterException 无效算法
|
||||
*/
|
||||
private Cipher initMode(final int mode) throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||
return this.cipherWrapper.initMode(mode, this.secretKey).getCipher();
|
||||
return this.cipherWrapper.initMode(mode, this.secretKey).getRaw();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user