feat: 升级jdk17

This commit is contained in:
zlt2000
2023-08-01 17:08:46 +08:00
parent adc037d213
commit c7dfbc9e39
5 changed files with 38 additions and 17 deletions
+25 -3
View File
@@ -9,10 +9,10 @@
<packaging>pom</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>8</java.version>
<java.version>17</java.version>
<spring-cloud-alibaba-dependencies.version>2021.1</spring-cloud-alibaba-dependencies.version>
<spring-boot-dependencies.version>2.5.14</spring-boot-dependencies.version>
<spring-cloud-dependencies.version>2020.0.6</spring-cloud-dependencies.version>
@@ -63,6 +63,8 @@
<docker.java.security.egd>-Djava.security.egd=file:/dev/./urandom</docker.java.security.egd>
<docker.java.opts>-Xms128m -Xmx128m</docker.java.opts>
<guava.version>20.0</guava.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
</properties>
<dependencies>
@@ -452,6 +454,26 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-dependencies.version}</version>
</plugin>
<!-- 指定jdk版本,和指定编码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- maven 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
@@ -1,7 +1,6 @@
package com.central.common.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import java.security.KeyFactory;
@@ -33,8 +32,7 @@ public class RsaUtils {
Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] output = cipher.doFinal(content.getBytes());
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(output);
return Base64.encodeBase64String(output);
}catch (Exception e){
e.printStackTrace();
}
@@ -83,8 +81,7 @@ public class RsaUtils {
Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE);
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte [] b = cipher.doFinal(content.getBytes());
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(b);
return Base64.encodeBase64String(b);
} catch (Exception e){
e.printStackTrace();
}
@@ -97,7 +94,7 @@ public class RsaUtils {
*/
public static RSAPublicKey getPublicKey(String key) throws Exception {
byte[] keyBytes;
keyBytes = (new BASE64Decoder()).decodeBuffer(key);
keyBytes = Base64.decodeBase64(key);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return (RSAPublicKey)keyFactory.generatePublic(keySpec);
@@ -109,7 +106,7 @@ public class RsaUtils {
*/
public static PrivateKey getPrivateKey(String key) throws Exception {
byte[] keyBytes;
keyBytes = (new BASE64Decoder()).decodeBuffer(key);
keyBytes = Base64.decodeBase64(key);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePrivate(keySpec);
@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Encoder;
import org.apache.commons.codec.binary.Base64;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
@@ -217,8 +217,7 @@ public class ApiController {
*/
private String getBase64ClientParam() {
byte[] authorization = (clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8);
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(authorization);
return Base64.encodeBase64String(authorization);
}
@Data
+4
View File
@@ -22,6 +22,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
</dependencies>
<build>
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Encoder;
import org.apache.commons.codec.binary.Base64;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
@@ -73,8 +73,7 @@ public class ApiController {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
byte[] authorization = (clientId + ":" + clientSecret).getBytes("UTF-8");
BASE64Encoder encoder = new BASE64Encoder();
String base64Auth = encoder.encode(authorization);
String base64Auth = Base64.encodeBase64String(authorization);
headers.add("Authorization", "Basic " + base64Auth);
MultiValueMap<String, String> param = new LinkedMultiValueMap<>();