forked from github/dataease
Merge pull request #6847 from dataease/pr@dev-v2@feat_aksk_auth
feat: ak/sk认证校验
This commit is contained in:
commit
3a0c1b1e1d
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
||||
Subproject commit f28041745618304f6421a42d3ceaac68b96960a0
|
||||
Subproject commit b6df806cadde3be0a5cb55033a56f763ecd2a53b
|
@ -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";
|
||||
|
||||
|
36
sdk/common/src/main/java/io/dataease/utils/AesUtils.java
Normal file
36
sdk/common/src/main/java/io/dataease/utils/AesUtils.java
Normal 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 error,please check parameters", e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user