Merge pull request #6847 from dataease/pr@dev-v2@feat_aksk_auth

feat: ak/sk认证校验
This commit is contained in:
fit2cloud-chenyw 2023-11-25 16:16:58 +08:00 committed by GitHub
commit 3a0c1b1e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

@ -1 +1 @@
Subproject commit f28041745618304f6421a42d3ceaac68b96960a0
Subproject commit b6df806cadde3be0a5cb55033a56f763ecd2a53b

View File

@ -18,6 +18,7 @@ public class AuthConstant {
public final static String USER_IMPORT_ERROR_KEY = "USER-IMPORT-ERROR-KEY";
public final static String LINK_TOKEN_KEY = "X-DE-LINK-TOKEN";
public final static String ASK_TOKEN_KEY = "X-DE-ASK-TOKEN";
public final static String DE_EXECUTE_VERSION = "X-DE-EXECUTE-VERSION";

View File

@ -0,0 +1,36 @@
package io.dataease.utils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import static java.nio.charset.StandardCharsets.UTF_8;
public class AesUtils {
public static String aesDecrypt(String src, String secretKey, String iv) {
if (StringUtils.isBlank(secretKey)) {
throw new RuntimeException("secretKey is empty");
}
try {
byte[] raw = secretKey.getBytes(UTF_8);
SecretKeySpec secretKeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec iv1 = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, iv1);
byte[] encrypted1 = Base64.decodeBase64(src);
byte[] original = cipher.doFinal(encrypted1);
return new String(original, UTF_8);
} catch (BadPaddingException | IllegalBlockSizeException e) {
// 解密的原字符串为非加密字符串则直接返回原字符串
return src;
} catch (Exception e) {
throw new RuntimeException("decrypt errorplease check parameters", e);
}
}
}