From f4e076d82c97e2c1b8f3e0c8e35596b7dc25315c Mon Sep 17 00:00:00 2001 From: "Crystal.Sea" Date: Sat, 2 Oct 2021 11:25:09 +0800 Subject: [PATCH] ReciprocalUtils compatible jdk 17 --- .../main/java/org/maxkey/crypto/ReciprocalUtils.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/maxkey-common/src/main/java/org/maxkey/crypto/ReciprocalUtils.java b/maxkey-common/src/main/java/org/maxkey/crypto/ReciprocalUtils.java index c7dbf5fc..847cc7af 100644 --- a/maxkey-common/src/main/java/org/maxkey/crypto/ReciprocalUtils.java +++ b/maxkey-common/src/main/java/org/maxkey/crypto/ReciprocalUtils.java @@ -53,6 +53,16 @@ public final class ReciprocalUtils { public static final String AES = "AES"; } + static { + if(System.getProperty("java.version").startsWith("1.8")) { + try { + Security.addProvider(new com.sun.crypto.provider.SunJCE()); + }catch (Exception e) { + e.printStackTrace(); + } + } + } + public static byte[] encode(byte[] simpleBytes, SecretKey secretKey, String algorithm) { // Create the ciphers Cipher ecipher; @@ -155,7 +165,6 @@ public final class ReciprocalUtils { public static SecretKey generatorDefaultKey(String algorithm) { try { - Security.addProvider(new com.sun.crypto.provider.SunJCE()); String secretKey = defaultKey; if (algorithm.equals(Algorithm.DES)) { secretKey = defaultKey.substring(0, 8);