From 0f94db7a6fbbbe38a82aed33047f13d01edf43dc Mon Sep 17 00:00:00 2001 From: sunyongjie Date: Fri, 8 Mar 2024 08:37:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=95=8F=E6=84=9F=E4=BF=A1=E6=81=AF=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/api/bean/ExecuteResultBean.java | 14 ++++ .../base/api/bean/device/DevicePowerEnum.java | 5 ++ .../base/api/util/RSAEncryptDecrypt.java | 74 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/ExecuteResultBean.java create mode 100644 InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/device/DevicePowerEnum.java create mode 100644 InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/util/RSAEncryptDecrypt.java diff --git a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/ExecuteResultBean.java b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/ExecuteResultBean.java new file mode 100644 index 0000000..3101f93 --- /dev/null +++ b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/ExecuteResultBean.java @@ -0,0 +1,14 @@ +package com.inspur.ispim.cosmos.iboot.base.api.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +@Data +@AllArgsConstructor +public class ExecuteResultBean { + private int code; + + private List output; +} diff --git a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/device/DevicePowerEnum.java b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/device/DevicePowerEnum.java new file mode 100644 index 0000000..e682672 --- /dev/null +++ b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/device/DevicePowerEnum.java @@ -0,0 +1,5 @@ +package com.inspur.ispim.cosmos.iboot.base.api.bean.device; + +public enum DevicePowerEnum { + on, off, reset, pxereset +} diff --git a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/util/RSAEncryptDecrypt.java b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/util/RSAEncryptDecrypt.java new file mode 100644 index 0000000..1ac38ed --- /dev/null +++ b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/util/RSAEncryptDecrypt.java @@ -0,0 +1,74 @@ +package com.inspur.ispim.cosmos.iboot.base.api.util; + +import org.apache.commons.lang3.StringUtils; + +import javax.crypto.Cipher; +import java.security.KeyFactory; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.Arrays; +import java.util.Base64; + + +public class RSAEncryptDecrypt { + // X509 公钥 + private static String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkrzXbuuI+EeZVv/4/KkeifZOWG6cBqRC3MBHvT1jHajUjba71NO29X0k6JFJbU8A8XVG3lxwSw5uticcWdfMwu5tMKPPfK0CTvec9SpeX3Ram4M5t/HXmIw8XiL7+ZsPmm5KA2sd3sDPpOKTCm/9xfMzFhIvUXzsSkv5wbuTrnht6opQCkkBWuzsqYTRtB+wjMXkKoz5wZfnf8gQ/Jlfn0HlEQRXIMIa8cZZ+KCD6EMb9fGmoUHxvWI/NjLEDIceCX6Ksw6lQUj1dQOfLJdMkoZnpdNyC7xsnBAOf79zV6mdDqDJZHdCuqNreQ9xGKdCUB69o1++nq9lpO9W2pV8fQIDAQAB"; + + // PKCS8 私钥 + private static String privateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCSvNdu64j4R5lW//j8qR6J9k5YbpwGpELcwEe9PWMdqNSNtrvU07b1fSTokUltTwDxdUbeXHBLDm62JxxZ18zC7m0wo898rQJO95z1Kl5fdFqbgzm38deYjDxeIvv5mw+abkoDax3ewM+k4pMKb/3F8zMWEi9RfOxKS/nBu5OueG3qilAKSQFa7OyphNG0H7CMxeQqjPnBl+d/yBD8mV+fQeURBFcgwhrxxln4oIPoQxv18aahQfG9Yj82MsQMhx4JfoqzDqVBSPV1A58sl0yShmel03ILvGycEA5/v3NXqZ0OoMlkd0K6o2t5D3EYp0JQHr2jX76er2Wk71balXx9AgMBAAECggEAOSlrWwBSGTX7HBMXMYXIKcJTfsuH6GZwzYHx8FxLkjBErPf0b9IRwcwAZsDCM9zE50riUpj7/aEfq8HMn4sbbwxma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voFdbuTYw0mbFA6HgquaF76BU9E8bLe+sXziRhZb+sTxxx53ywn9UUJZQ=="; + + public static String encrypt(String str) throws Exception { + if (StringUtils.isBlank(str)) { + return null; + } + final byte[] bytes = str.getBytes(); + // base64编码的私钥 + byte[] decoded = Base64.getDecoder().decode(publicKey); + RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); + // RSA加密 + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, pubKey); + return Base64.getEncoder().encodeToString(cipher.doFinal(bytes)); + } + + /** + * 解密算法 + * + * @param cryptoGraph 密文 + */ + public static String maxResultDecrypt(String cryptoGraph) throws Exception { + byte[] decoded = Base64.getDecoder().decode(privateKey); + RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); + // 得到Cipher对象对已用公钥加密的数据进行RSA解密 + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE, priKey); + // 执行解密操作 + return new String(getMaxResultDecrypt(cryptoGraph, cipher)); + } + + //长度过长分割解密 + private static byte[] getMaxResultDecrypt(String str, Cipher cipher) throws Exception { + byte[] inputArray = Base64.getDecoder().decode(str.getBytes()); + int inputLength = inputArray.length; + // 最大解密字节数,超出最大字节数需要分组加密 + int MAX_ENCRYPT_BLOCK = 256; + // 标识 + int offSet = 0; + byte[] resultBytes = {}; + byte[] cache = {}; + while (inputLength - offSet > 0) { + if (inputLength - offSet > MAX_ENCRYPT_BLOCK) { + cache = cipher.doFinal(inputArray, offSet, MAX_ENCRYPT_BLOCK); + offSet += MAX_ENCRYPT_BLOCK; + } else { + cache = cipher.doFinal(inputArray, offSet, inputLength - offSet); + offSet = inputLength; + } + resultBytes = Arrays.copyOf(resultBytes, resultBytes.length + cache.length); + System.arraycopy(cache, 0, resultBytes, resultBytes.length - cache.length, cache.length); + } + return resultBytes; + } +} -- Gitee From 343d58c2566aa7b4109304c7b4fc76ad95198615 Mon Sep 17 00:00:00 2001 From: sunyongjie Date: Thu, 14 Mar 2024 08:57:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0KOS5.8=205.9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=85=BC=E5=AE=B9=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cosmos/iboot/base/api/bean/template/IBootOsInstallBean.java | 2 ++ .../cosmos/iboot/base/api/service/IBootOsInstallService.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/template/IBootOsInstallBean.java b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/template/IBootOsInstallBean.java index a5a92f8..0e63216 100644 --- a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/template/IBootOsInstallBean.java +++ b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/bean/template/IBootOsInstallBean.java @@ -106,4 +106,6 @@ public class IBootOsInstallBean { private String userName; private String userPsw; + private String kernelVersion; + } diff --git a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/service/IBootOsInstallService.java b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/service/IBootOsInstallService.java index eb9812d..9389b25 100644 --- a/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/service/IBootOsInstallService.java +++ b/InManageBoot-iboot/cosmos-biz/cosmos-biz-iboot/cosmos-biz-iboot-base/cosmos-biz-iboot-base-api/src/main/java/com/inspur/ispim/cosmos/iboot/base/api/service/IBootOsInstallService.java @@ -54,7 +54,7 @@ public interface IBootOsInstallService { /** * 写入MAC.INI文件 */ - void insertMacIni(String imageFileId, String ksPath, String mac, String sn, String boodMode); + void insertMacIni(String imageFileId, String ksPath, String mac, String sn, String boodMode) throws IOException; String queryKsFileName(); -- Gitee