parent
c13c6a3c1e
commit
20424c9fc9
|
@ -46,4 +46,6 @@ public class DisposeConfigValue {
|
||||||
* The constant MIN_SPLIT_PAGE_SIZE.
|
* The constant MIN_SPLIT_PAGE_SIZE.
|
||||||
*/
|
*/
|
||||||
public static volatile int MIN_SPLIT_PAGE_SIZE = 10;
|
public static volatile int MIN_SPLIT_PAGE_SIZE = 10;
|
||||||
|
|
||||||
|
public static volatile boolean ENABLE_UTEST_MOCK = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dispose.interceptor;
|
package com.dispose.interceptor;
|
||||||
|
|
||||||
|
import com.dispose.common.DisposeConfigValue;
|
||||||
import com.dispose.common.ProtoCryptoType;
|
import com.dispose.common.ProtoCryptoType;
|
||||||
import com.dispose.common.SecurityConfigValue;
|
import com.dispose.common.SecurityConfigValue;
|
||||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||||
|
@ -42,6 +43,11 @@ public class ResponseProtocolSecurity implements ResponseBodyAdvice<Object> {
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(@NotNull MethodParameter methodParameter,
|
public boolean supports(@NotNull MethodParameter methodParameter,
|
||||||
@NotNull Class<? extends HttpMessageConverter<?>> aClass) {
|
@NotNull Class<? extends HttpMessageConverter<?>> aClass) {
|
||||||
|
// 单元测试Mock模式
|
||||||
|
if (DisposeConfigValue.ENABLE_UTEST_MOCK) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return methodParameter.getContainingClass().isAnnotationPresent(Encryption.class)
|
return methodParameter.getContainingClass().isAnnotationPresent(Encryption.class)
|
||||||
|| methodParameter.hasMethodAnnotation(Encryption.class);
|
|| methodParameter.hasMethodAnnotation(Encryption.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Response status.
|
* The type Response status.
|
||||||
*
|
*
|
||||||
|
@ -24,14 +22,4 @@ public class BaseRespStatus {
|
||||||
* 登录消息: status状态码对应的提示信息
|
* 登录消息: status状态码对应的提示信息
|
||||||
*/
|
*/
|
||||||
private String[] message;
|
private String[] message;
|
||||||
|
|
||||||
/**
|
|
||||||
* To string string.
|
|
||||||
*
|
|
||||||
* @return the string
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "{\"status\":" + status + ", \"message\":\"" + Arrays.toString(message) + "\"}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,12 @@ import javax.crypto.Cipher;
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
import javax.crypto.KeyGenerator;
|
import javax.crypto.KeyGenerator;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.NoSuchPaddingException;
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import javax.crypto.SecretKeyFactory;
|
|
||||||
import javax.crypto.spec.DESKeySpec;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Crypto helper.
|
* The type Crypto helper.
|
||||||
|
@ -71,7 +67,7 @@ public class CryptoHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aes 256 encryption byte [ ].
|
* Aes 128 encryption byte [ ].
|
||||||
*
|
*
|
||||||
* @param plaintext the plaintext
|
* @param plaintext the plaintext
|
||||||
* @param aesKey the aes key
|
* @param aesKey the aes key
|
||||||
|
@ -96,7 +92,7 @@ public class CryptoHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aes 256 decryption byte [ ].
|
* Aes 128 decryption byte [ ].
|
||||||
*
|
*
|
||||||
* @param ciphertext the ciphertext
|
* @param ciphertext the ciphertext
|
||||||
* @param aesKey the aes key
|
* @param aesKey the aes key
|
||||||
|
@ -129,20 +125,21 @@ public class CryptoHelper {
|
||||||
* @return the byte [ ]
|
* @return the byte [ ]
|
||||||
* @throws InvalidKeyException the invalid key exception
|
* @throws InvalidKeyException the invalid key exception
|
||||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||||
* @throws InvalidKeySpecException the invalid key spec exception
|
|
||||||
* @throws NoSuchPaddingException the no such padding exception
|
* @throws NoSuchPaddingException the no such padding exception
|
||||||
* @throws BadPaddingException the bad padding exception
|
* @throws BadPaddingException the bad padding exception
|
||||||
* @throws IllegalBlockSizeException the illegal block size exception
|
* @throws IllegalBlockSizeException the illegal block size exception
|
||||||
*/
|
*/
|
||||||
public static byte[] desDecryption(byte[] ciphertext, String desKey) throws InvalidKeyException,
|
public static byte[] desDecryption(byte[] ciphertext, String desKey) throws InvalidKeyException,
|
||||||
NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException,
|
NoSuchAlgorithmException, NoSuchPaddingException, BadPaddingException,
|
||||||
IllegalBlockSizeException {
|
IllegalBlockSizeException {
|
||||||
SecureRandom sr = new SecureRandom();
|
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
|
||||||
DESKeySpec desKeySpec = new DESKeySpec(desKey.getBytes());
|
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
secureRandom.setSeed(desKey.getBytes());
|
||||||
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
|
|
||||||
|
keyGen.init(56, secureRandom);
|
||||||
Cipher cipher = Cipher.getInstance(DES_ALGORITHM_STR);
|
Cipher cipher = Cipher.getInstance(DES_ALGORITHM_STR);
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey, sr);
|
SecretKeySpec key = new SecretKeySpec(keyGen.generateKey().getEncoded(), "DES");
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||||
return cipher.doFinal(ciphertext);
|
return cipher.doFinal(ciphertext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,20 +151,21 @@ public class CryptoHelper {
|
||||||
* @return the byte [ ]
|
* @return the byte [ ]
|
||||||
* @throws InvalidKeyException the invalid key exception
|
* @throws InvalidKeyException the invalid key exception
|
||||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||||
* @throws InvalidKeySpecException the invalid key spec exception
|
|
||||||
* @throws NoSuchPaddingException the no such padding exception
|
* @throws NoSuchPaddingException the no such padding exception
|
||||||
* @throws BadPaddingException the bad padding exception
|
* @throws BadPaddingException the bad padding exception
|
||||||
* @throws IllegalBlockSizeException the illegal block size exception
|
* @throws IllegalBlockSizeException the illegal block size exception
|
||||||
*/
|
*/
|
||||||
public static byte[] desEncryption(byte[] plaintext, String desKey) throws InvalidKeyException,
|
public static byte[] desEncryption(byte[] plaintext, String desKey) throws InvalidKeyException,
|
||||||
NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException,
|
NoSuchAlgorithmException, NoSuchPaddingException, BadPaddingException,
|
||||||
IllegalBlockSizeException {
|
IllegalBlockSizeException {
|
||||||
SecureRandom sr = new SecureRandom();
|
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
|
||||||
DESKeySpec desKeySpec = new DESKeySpec(desKey.getBytes());
|
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
secureRandom.setSeed(desKey.getBytes());
|
||||||
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
|
|
||||||
|
keyGen.init(56, secureRandom);
|
||||||
Cipher cipher = Cipher.getInstance(DES_ALGORITHM_STR);
|
Cipher cipher = Cipher.getInstance(DES_ALGORITHM_STR);
|
||||||
cipher.init(Cipher.DECRYPT_MODE, secretKey, sr);
|
SecretKeySpec key = new SecretKeySpec(keyGen.generateKey().getEncoded(), "DES");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||||
return cipher.doFinal(plaintext);
|
return cipher.doFinal(plaintext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue