feat(X-Pack): 新增插件管理菜单

This commit is contained in:
fit2cloud-chenyw
2024-06-12 13:24:06 +08:00
parent 771a58a06b
commit f3d14cd7ba
7 changed files with 21 additions and 24 deletions

View File

@@ -6,11 +6,9 @@ import io.dataease.model.RSAModel;
import io.dataease.rsa.dao.entity.CoreRsa;
import io.dataease.rsa.manage.RsaManage;
import jakarta.annotation.Resource;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
@@ -21,6 +19,7 @@ import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
@Component
public class RsaUtils {
@@ -62,7 +61,7 @@ public class RsaUtils {
KeyFactory keyFactory = null;
try {
keyFactory = KeyFactory.getInstance("RSA");
byte[] decodedKey = Base64.decodeBase64(privateKey.getBytes());
byte[] decodedKey = Base64.getDecoder().decode(privateKey.getBytes());
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedKey);
return keyFactory.generatePrivate(keySpec);
} catch (Exception e) {
@@ -75,7 +74,7 @@ public class RsaUtils {
KeyFactory keyFactory = null;
try {
keyFactory = KeyFactory.getInstance("RSA");
byte[] decodedKey = Base64.decodeBase64(publicKey.getBytes());
byte[] decodedKey = Base64.getDecoder().decode(publicKey.getBytes());
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decodedKey);
return keyFactory.generatePublic(keySpec);
} catch (Exception e) {
@@ -104,13 +103,13 @@ public class RsaUtils {
}
byte[] encryptedData = out.toByteArray();
out.close();
return Base64.encodeBase64String(encryptedData);
return Base64.getEncoder().encodeToString(encryptedData);
}
private static String decrypt(String data, PrivateKey privateKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] dataBytes = Base64.decodeBase64(data);
byte[] dataBytes = Base64.getDecoder().decode(data);
int inputLen = dataBytes.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offset = 0;
@@ -132,8 +131,8 @@ public class RsaUtils {
public static RSAModel generate() {
KeyPair keyPair = getKeyPair();
String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));
String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));
String privateKey = new String(Base64.getEncoder().encode(keyPair.getPrivate().getEncoded()));
String publicKey = new String(Base64.getEncoder().encode(keyPair.getPublic().getEncoded()));
RSAModel rsaModel = new RSAModel();
rsaModel.setPrivateKey(privateKey);
rsaModel.setPublicKey(publicKey);
@@ -173,7 +172,7 @@ public class RsaUtils {
String publicKey = coreRsa.getPublicKey();
String aesKey = coreRsa.getAesKey();
String pk = ascEncrypt(publicKey, aesKey).replaceAll("[\\s*\t\n\r]", "");
String separator = Base64Utils.encodeToUrlSafeString(PK_SEPARATOR.getBytes(StandardCharsets.UTF_8));
String separator = Base64.getUrlEncoder().encodeToString(PK_SEPARATOR.getBytes(StandardCharsets.UTF_8));
return pk + separator + aesKey;
}
@@ -184,24 +183,17 @@ public class RsaUtils {
}
private static String ascEncrypt(String message, String key) {
/*byte[] baseKey = key.getBytes(StandardCharsets.UTF_8);
byte[] ivBytes = IV_KEY.getBytes(StandardCharsets.UTF_8);
AES aes = new AES("CBC", "PKCS7Padding", baseKey, ivBytes);
byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
return Base64Utils.encodeToString(aes.encrypt(messageBytes));*/
Cipher cipher = null;
try {
byte[] baseKey = key.getBytes(StandardCharsets.UTF_8);
byte[] ivBytes = IV_KEY.getBytes(StandardCharsets.UTF_8);
byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
// 根据secretKey(密钥)的字节内容,"恢复"秘钥对象
SecretKey keySpec = new SecretKeySpec(baseKey, "AES");
IvParameterSpec ivps = new IvParameterSpec(ivBytes);
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivps);
byte[] data = cipher.doFinal(messageBytes);
return Base64.encodeBase64String(data);
return Base64.getEncoder().encodeToString(data);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
throw new RuntimeException(e);

View File

@@ -3,11 +3,11 @@ package io.dataease.utils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import static io.dataease.constant.StaticResourceConstants.*;
@@ -86,7 +86,7 @@ public class StaticResourceUtils {
}
// Encode byte array as Base64
if (buffer != null) {
return Base64Utils.encodeToString(buffer);
return Base64.getEncoder().encodeToString(buffer);
} else {
return null;
}