Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.7.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	mica-core/src/main/java/net/dreamlu/mica/core/validation/constraintvalidators/RangeInValidator.java
  • Loading branch information
ChunMengLu committed Apr 24, 2024
2 parents 95b3994 + c963d06 commit 0c788ee
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package net.dreamlu.mica.core.beans;

import net.dreamlu.mica.core.utils.*;
import net.dreamlu.mica.core.utils.BeanUtil;
import net.dreamlu.mica.core.utils.CollectionUtil;
import net.dreamlu.mica.core.utils.ReflectUtil;
import net.dreamlu.mica.core.utils.StringUtil;
import org.springframework.asm.ClassVisitor;
import org.springframework.asm.Label;
import org.springframework.asm.Opcodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.function.CheckedFunction;
import net.dreamlu.mica.core.utils.*;
import net.dreamlu.mica.core.utils.CollectionUtil;
import net.dreamlu.mica.core.utils.ConvertUtil;
import net.dreamlu.mica.core.utils.ReflectUtil;
import net.dreamlu.mica.core.utils.Unchecked;
import org.springframework.cglib.core.Converter;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
Expand Down
7 changes: 4 additions & 3 deletions mica-core/src/main/java/net/dreamlu/mica/core/utils/$.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.time.Duration;
import java.time.LocalDate;
Expand Down Expand Up @@ -1010,7 +1011,7 @@ public static byte[] sha224(final byte[] bytes) {
* @return digest as a hex string
*/
public static String sha224Hex(String data) {
return DigestUtil.sha224Hex(data.getBytes(Charsets.UTF_8));
return DigestUtil.sha224Hex(data.getBytes(StandardCharsets.UTF_8));
}

/**
Expand Down Expand Up @@ -1855,7 +1856,7 @@ public static <K, V> Map<K, V> readJsonAsMap(@Nullable String content, Class<?>
* @return the encoded String
*/
public static String urlEncode(String source) {
return UriUtils.encode(source, Charsets.UTF_8);
return UriUtils.encode(source, StandardCharsets.UTF_8);
}

/**
Expand All @@ -1879,7 +1880,7 @@ public static String urlEncode(String source, Charset charset) {
* @see java.net.URLDecoder#decode(String, String)
*/
public static String urlDecode(String source) {
return StringUtils.uriDecode(source, Charsets.UTF_8);
return StringUtils.uriDecode(source, StandardCharsets.UTF_8);
}

/**
Expand Down
25 changes: 12 additions & 13 deletions mica-core/src/main/java/net/dreamlu/mica/core/utils/AesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @author L.cm
*/
public class AesUtil {
public static final Charset DEFAULT_CHARSET = Charsets.UTF_8;

public static String genAesKey() {
return StringUtil.random(32);
Expand Down Expand Up @@ -49,7 +48,7 @@ public static SecretKeySpec genMySqlAesKey(final byte[] key) {
* @return SecretKeySpec
*/
public static SecretKeySpec genMySqlAesKey(final String key) {
return genMySqlAesKey(key.getBytes(DEFAULT_CHARSET));
return genMySqlAesKey(key.getBytes(StandardCharsets.UTF_8));
}

public static String encryptToHex(String content, String aesTextKey) {
Expand All @@ -69,15 +68,15 @@ public static String encryptToBase64(byte[] content, String aesTextKey) {
}

public static byte[] encrypt(String content, String aesTextKey) {
return encrypt(content.getBytes(DEFAULT_CHARSET), aesTextKey);
return encrypt(content.getBytes(StandardCharsets.UTF_8), aesTextKey);
}

public static byte[] encrypt(String content, Charset charset, String aesTextKey) {
return encrypt(content.getBytes(charset), aesTextKey);
}

public static byte[] encrypt(byte[] content, String aesTextKey) {
return encrypt(content, Objects.requireNonNull(aesTextKey).getBytes(DEFAULT_CHARSET));
return encrypt(content, Objects.requireNonNull(aesTextKey).getBytes(StandardCharsets.UTF_8));
}

@Nullable
Expand All @@ -86,15 +85,15 @@ public static String decryptFormHexToString(@Nullable String content, String aes
if (hexBytes == null) {
return null;
}
return new String(hexBytes, DEFAULT_CHARSET);
return new String(hexBytes, StandardCharsets.UTF_8);
}

@Nullable
public static byte[] decryptFormHex(@Nullable String content, String aesTextKey) {
if (StringUtil.isBlank(content)) {
return null;
}
return decryptFormHex(content.getBytes(DEFAULT_CHARSET), aesTextKey);
return decryptFormHex(content.getBytes(StandardCharsets.UTF_8), aesTextKey);
}

public static byte[] decryptFormHex(byte[] content, String aesTextKey) {
Expand All @@ -107,27 +106,27 @@ public static String decryptFormBase64ToString(@Nullable String content, String
if (hexBytes == null) {
return null;
}
return new String(hexBytes, DEFAULT_CHARSET);
return new String(hexBytes, StandardCharsets.UTF_8);
}

@Nullable
public static byte[] decryptFormBase64(@Nullable String content, String aesTextKey) {
if (StringUtil.isBlank(content)) {
return null;
}
return decryptFormBase64(content.getBytes(DEFAULT_CHARSET), aesTextKey);
return decryptFormBase64(content.getBytes(StandardCharsets.UTF_8), aesTextKey);
}

public static byte[] decryptFormBase64(byte[] content, String aesTextKey) {
return decrypt(Base64Util.decode(content), aesTextKey);
}

public static String decryptToString(byte[] content, String aesTextKey) {
return new String(decrypt(content, aesTextKey), DEFAULT_CHARSET);
return new String(decrypt(content, aesTextKey), StandardCharsets.UTF_8);
}

public static byte[] decrypt(byte[] content, String aesTextKey) {
return decrypt(content, Objects.requireNonNull(aesTextKey).getBytes(DEFAULT_CHARSET));
return decrypt(content, Objects.requireNonNull(aesTextKey).getBytes(StandardCharsets.UTF_8));
}

public static byte[] encrypt(byte[] content, byte[] aesKey) {
Expand Down Expand Up @@ -190,7 +189,7 @@ public static <T> T encryptMysql(String input, String aesKey, Function<byte[], T
* @return byte 数组
*/
public static byte[] decryptMysql(String input, String aesKey) {
return decryptMysql(input, txt -> txt.getBytes(DEFAULT_CHARSET), aesKey);
return decryptMysql(input, txt -> txt.getBytes(StandardCharsets.UTF_8), aesKey);
}

/**
Expand Down Expand Up @@ -219,7 +218,7 @@ public static byte[] decryptMysql(String input, Function<String, byte[]> inputMa
* @return 字符串
*/
public static String decryptMysqlToString(String input, Function<String, byte[]> inputMapper, String aesKey) {
return new String(decryptMysql(input, inputMapper, aesKey), DEFAULT_CHARSET);
return new String(decryptMysql(input, inputMapper, aesKey), StandardCharsets.UTF_8);
}

/**
Expand All @@ -230,7 +229,7 @@ public static String decryptMysqlToString(String input, Function<String, byte[]>
* @return 字符串
*/
public static String decryptMysqlToString(String input, String aesKey) {
return decryptMysqlToString(input, txt -> txt.getBytes(DEFAULT_CHARSET), aesKey);
return decryptMysqlToString(input, txt -> txt.getBytes(StandardCharsets.UTF_8), aesKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.dreamlu.mica.core.utils;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
Expand All @@ -37,7 +38,7 @@ public class Base64Util {
* @return {String}
*/
public static String encode(String value) {
return encode(value, Charsets.UTF_8);
return encode(value, StandardCharsets.UTF_8);
}

/**
Expand All @@ -59,7 +60,7 @@ public static String encode(String value, Charset charset) {
* @return {String}
*/
public static String encodeUrlSafe(String value) {
return encodeUrlSafe(value, Charsets.UTF_8);
return encodeUrlSafe(value, StandardCharsets.UTF_8);
}

/**
Expand All @@ -81,7 +82,7 @@ public static String encodeUrlSafe(String value, Charset charset) {
* @return {String}
*/
public static String decode(String value) {
return decode(value, Charsets.UTF_8);
return decode(value, StandardCharsets.UTF_8);
}

/**
Expand All @@ -104,7 +105,7 @@ public static String decode(String value, Charset charset) {
* @return {String}
*/
public static String decodeUrlSafe(String value) {
return decodeUrlSafe(value, Charsets.UTF_8);
return decodeUrlSafe(value, StandardCharsets.UTF_8);
}

/**
Expand Down Expand Up @@ -185,7 +186,7 @@ public static String encodeToString(byte[] src) {
if (src.length == 0) {
return "";
}
return new String(encode(src), Charsets.UTF_8);
return new String(encode(src), StandardCharsets.UTF_8);
}

/**
Expand All @@ -198,7 +199,7 @@ public static byte[] decodeFromString(String src) {
if (src.isEmpty()) {
return new byte[0];
}
return decode(src.getBytes(Charsets.UTF_8));
return decode(src.getBytes(StandardCharsets.UTF_8));
}

/**
Expand All @@ -209,7 +210,7 @@ public static byte[] decodeFromString(String src) {
* @return the encoded byte array as a UTF-8 String
*/
public static String encodeToUrlSafeString(byte[] src) {
return new String(encodeUrlSafe(src), Charsets.UTF_8);
return new String(encodeUrlSafe(src), StandardCharsets.UTF_8);
}

/**
Expand All @@ -220,7 +221,7 @@ public static String encodeToUrlSafeString(byte[] src) {
* @return the original byte array
*/
public static byte[] decodeFromUrlSafeString(String src) {
return decodeUrlSafe(src.getBytes(Charsets.UTF_8));
return decodeUrlSafe(src.getBytes(StandardCharsets.UTF_8));
}

}
13 changes: 7 additions & 6 deletions mica-core/src/main/java/net/dreamlu/mica/core/utils/DesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

/**
Expand Down Expand Up @@ -66,7 +67,7 @@ public static String encryptToHex(@Nullable String data, String password) {
if (StringUtil.isBlank(data)) {
return null;
}
byte[] dataBytes = data.getBytes(Charsets.UTF_8);
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
return encryptToHex(dataBytes, password);
}

Expand All @@ -83,7 +84,7 @@ public static String decryptFormHex(@Nullable String data, String password) {
return null;
}
byte[] hexBytes = HexUtil.decode(data);
return new String(decrypt(hexBytes, password), Charsets.UTF_8);
return new String(decrypt(hexBytes, password), StandardCharsets.UTF_8);
}

/**
Expand All @@ -109,7 +110,7 @@ public static String encryptToBase64(@Nullable String data, String password) {
if (StringUtil.isBlank(data)) {
return null;
}
byte[] dataBytes = data.getBytes(Charsets.UTF_8);
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
return encryptToBase64(dataBytes, password);
}

Expand Down Expand Up @@ -138,7 +139,7 @@ public static String decryptFormBase64(@Nullable String data, String password) {
return null;
}
byte[] dataBytes = Base64Util.decodeFromString(data);
return new String(decrypt(dataBytes, password), Charsets.UTF_8);
return new String(decrypt(dataBytes, password), StandardCharsets.UTF_8);
}

/**
Expand All @@ -160,7 +161,7 @@ public static byte[] encrypt(byte[] data, byte[] desKey) {
* @return byte array
*/
public static byte[] encrypt(byte[] data, String desKey) {
return encrypt(data, Objects.requireNonNull(desKey).getBytes(Charsets.UTF_8));
return encrypt(data, Objects.requireNonNull(desKey).getBytes(StandardCharsets.UTF_8));
}

/**
Expand All @@ -182,7 +183,7 @@ public static byte[] decrypt(byte[] data, byte[] desKey) {
* @return byte array
*/
public static byte[] decrypt(byte[] data, String desKey) {
return decrypt(data, Objects.requireNonNull(desKey).getBytes(Charsets.UTF_8));
return decrypt(data, Objects.requireNonNull(desKey).getBytes(StandardCharsets.UTF_8));
}

/**
Expand Down
Loading

0 comments on commit 0c788ee

Please sign in to comment.