mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
add @Serial
This commit is contained in:
@@ -18,12 +18,15 @@ package cn.hutool.v7.crypto;
|
||||
|
||||
import cn.hutool.v7.core.exception.HutoolException;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 加密异常
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class CryptoException extends HutoolException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8068509879445395353L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package cn.hutool.v7.crypto.asymmetric;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.security.KeyPair;
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,7 @@ import java.security.KeyPair;
|
||||
public abstract class AbstractAsymmetricCrypto<T extends AbstractAsymmetricCrypto<T>>
|
||||
extends BaseAsymmetric<T>
|
||||
implements AsymmetricEncryptor, AsymmetricDecryptor{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// ------------------------------------------------------------------ Constructor start
|
||||
|
||||
@@ -22,6 +22,7 @@ import cn.hutool.v7.crypto.*;
|
||||
import cn.hutool.v7.crypto.symmetric.SymmetricAlgorithm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serial;
|
||||
import java.security.*;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
|
||||
@@ -39,6 +40,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
||||
* @author Looly
|
||||
*/
|
||||
public class AsymmetricCrypto extends AbstractAsymmetricCrypto<AsymmetricCrypto> {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ import cn.hutool.v7.core.util.ObjUtil;
|
||||
import cn.hutool.v7.crypto.CryptoException;
|
||||
import cn.hutool.v7.crypto.KeyUtil;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.security.Key;
|
||||
import java.security.KeyPair;
|
||||
@@ -39,6 +40,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public class BaseAsymmetric<T extends BaseAsymmetric<T>> implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
@@ -217,19 +219,21 @@ public class BaseAsymmetric<T extends BaseAsymmetric<T>> implements Serializable
|
||||
* @return {@link Key}
|
||||
*/
|
||||
protected Key getKeyByType(final KeyType type) {
|
||||
switch (type) {
|
||||
case PrivateKey:
|
||||
return switch (type) {
|
||||
case PrivateKey -> {
|
||||
if (null == this.privateKey) {
|
||||
throw new NullPointerException("Private key must not null when use it !");
|
||||
}
|
||||
return this.privateKey;
|
||||
case PublicKey:
|
||||
yield this.privateKey;
|
||||
}
|
||||
case PublicKey -> {
|
||||
if (null == this.publicKey) {
|
||||
throw new NullPointerException("Public key must not null when use it !");
|
||||
}
|
||||
return this.publicKey;
|
||||
}
|
||||
throw new CryptoException("Unsupported key type: " + type);
|
||||
yield this.publicKey;
|
||||
}
|
||||
default -> throw new CryptoException("Unsupported key type: " + type);
|
||||
};
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package cn.hutool.v7.crypto.asymmetric;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.security.KeyPair;
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,7 @@ import java.security.KeyPair;
|
||||
* @since 5.3.10
|
||||
*/
|
||||
public class ECIES extends AsymmetricCrypto{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 默认的ECIES算法 */
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.hutool.v7.crypto.CryptoException;
|
||||
import cn.hutool.v7.crypto.provider.GlobalProviderFactory;
|
||||
import cn.hutool.v7.crypto.KeyUtil;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyPair;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -45,6 +46,7 @@ import java.security.spec.RSAPublicKeySpec;
|
||||
*
|
||||
*/
|
||||
public class RSA extends AsymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 默认的RSA算法 */
|
||||
|
||||
@@ -41,6 +41,7 @@ import cn.hutool.v7.crypto.bc.ECKeyUtil;
|
||||
import cn.hutool.v7.crypto.bc.SmUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serial;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.KeyPair;
|
||||
@@ -65,6 +66,7 @@ import java.security.SecureRandom;
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ import cn.hutool.v7.crypto.SignUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serial;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.Signature;
|
||||
@@ -42,6 +43,7 @@ import java.util.Set;
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public class Sign extends BaseAsymmetric<Sign> {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import cn.hutool.v7.crypto.asymmetric.AbstractAsymmetricCrypto;
|
||||
import cn.hutool.v7.crypto.asymmetric.KeyType;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.Serial;
|
||||
import java.security.Key;
|
||||
import java.security.KeyPair;
|
||||
import java.security.SecureRandom;
|
||||
@@ -46,6 +47,7 @@ import java.security.SecureRandom;
|
||||
* @author Revers, peterstefanov
|
||||
**/
|
||||
public class PaillierCrypto extends AbstractAsymmetricCrypto<PaillierCrypto> {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final PaillierCipher cipher;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package cn.hutool.v7.crypto.asymmetric.paillier;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.math.BigInteger;
|
||||
import java.security.Key;
|
||||
import java.security.SecureRandom;
|
||||
@@ -27,6 +28,7 @@ import java.security.SecureRandom;
|
||||
* @author Looly
|
||||
*/
|
||||
public class PaillierKey implements Key {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package cn.hutool.v7.crypto.asymmetric.paillier;
|
||||
|
||||
import cn.hutool.v7.core.lang.Assert;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PrivateKey;
|
||||
|
||||
@@ -27,6 +28,7 @@ import java.security.PrivateKey;
|
||||
* @author peterstefanov, Revers, Looly
|
||||
*/
|
||||
public class PaillierPrivateKey extends PaillierKey implements PrivateKey {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BigInteger u;
|
||||
|
||||
@@ -18,6 +18,7 @@ package cn.hutool.v7.crypto.asymmetric.paillier;
|
||||
|
||||
import cn.hutool.v7.core.lang.Assert;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.math.BigInteger;
|
||||
import java.security.PublicKey;
|
||||
|
||||
@@ -27,6 +28,7 @@ import java.security.PublicKey;
|
||||
* @author peterstefanov, Revers, Looly
|
||||
*/
|
||||
public class PaillierPublicKey extends PaillierKey implements PublicKey {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BigInteger g;
|
||||
|
||||
@@ -28,10 +28,7 @@ import cn.hutool.v7.crypto.CryptoException;
|
||||
import cn.hutool.v7.crypto.SecureUtil;
|
||||
import cn.hutool.v7.crypto.provider.GlobalProviderFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.Provider;
|
||||
@@ -43,6 +40,7 @@ import java.security.Provider;
|
||||
* @author Looly
|
||||
*/
|
||||
public class Digester extends SimpleWrapper<MessageDigest> implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package cn.hutool.v7.crypto.digest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serial;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,7 @@ import java.nio.charset.Charset;
|
||||
* @since 4.4.3
|
||||
*/
|
||||
public class MD5 extends Digester {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// issue#I6ZIQH
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package cn.hutool.v7.crypto.digest;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 国密SM3杂凑(摘要)算法
|
||||
*
|
||||
@@ -31,6 +33,7 @@ package cn.hutool.v7.crypto.digest;
|
||||
* @since 4.6.8
|
||||
*/
|
||||
public class SM3 extends Digester {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package cn.hutool.v7.crypto.digest.mac;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.Serial;
|
||||
import java.security.Key;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
|
||||
@@ -31,6 +32,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
||||
* @author Looly
|
||||
*/
|
||||
public class HMac extends Mac {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// ------------------------------------------------------------------------------------------- Constructor start
|
||||
|
||||
@@ -24,10 +24,7 @@ import cn.hutool.v7.core.util.ByteUtil;
|
||||
import cn.hutool.v7.core.util.CharsetUtil;
|
||||
import cn.hutool.v7.crypto.CryptoException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
@@ -42,6 +39,7 @@ import java.security.MessageDigest;
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public class Mac implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final MacEngine engine;
|
||||
|
||||
@@ -24,6 +24,7 @@ import cn.hutool.v7.crypto.Padding;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.Serial;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public class AES extends SymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//------------------------------------------------------------------------- Constrctor start
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.hutool.v7.core.util.RandomUtil;
|
||||
import cn.hutool.v7.crypto.KeyUtil;
|
||||
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* ChaCha20算法实现<br>
|
||||
@@ -29,6 +30,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public class ChaCha20 extends SymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ import cn.hutool.v7.crypto.Padding;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* DES加密算法实现<br>
|
||||
@@ -33,6 +34,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public class DES extends SymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// region ----- Constructor
|
||||
|
||||
@@ -23,6 +23,7 @@ import cn.hutool.v7.crypto.Padding;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* DESede是由DES对称加密算法改进后的一种对称加密算法,又名3DES、TripleDES。<br>
|
||||
@@ -34,6 +35,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public class DESede extends SymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// ------------------------------------------------------------------------- Constructor start
|
||||
|
||||
@@ -21,6 +21,7 @@ import cn.hutool.v7.crypto.Padding;
|
||||
import org.bouncycastle.crypto.AlphabetMapper;
|
||||
import org.bouncycastle.jcajce.spec.FPEParameterSpec;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,7 @@ import java.io.Serializable;
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public class FPE implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// 映射字符表,规定了明文和密文的字符范围
|
||||
|
||||
@@ -24,6 +24,7 @@ import cn.hutool.v7.crypto.Padding;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 国密对称堆成加密算法SM4实现
|
||||
@@ -40,6 +41,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
* @since 4.6.8
|
||||
*/
|
||||
public class SM4 extends SymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,10 +34,7 @@ import javax.crypto.CipherOutputStream;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEParameterSpec;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.*;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -52,6 +49,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
* @author Looly
|
||||
*/
|
||||
public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor, Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JceCipher cipher;
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.hutool.v7.core.io.IoUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,7 @@ import java.io.Serializable;
|
||||
* @author Ma Bingyao
|
||||
*/
|
||||
public class XXTEA implements SymmetricEncryptor, SymmetricDecryptor, Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final int DELTA = 0x9E3779B9;
|
||||
|
||||
@@ -20,6 +20,7 @@ import cn.hutool.v7.core.util.RandomUtil;
|
||||
import cn.hutool.v7.crypto.KeyUtil;
|
||||
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 祖冲之算法集(ZUC算法)实现,基于BouncyCastle实现。
|
||||
@@ -28,6 +29,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public class ZUC extends SymmetricCrypto {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user