|
@@ -21,6 +21,7 @@
|
|
|
package org.dromara.maxkey.crypto;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.lang.reflect.Constructor;
|
|
|
import java.security.Provider;
|
|
|
import java.security.Security;
|
|
|
|
|
@@ -30,8 +31,6 @@ import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
-import org.dromara.maxkey.util.Instance;
|
|
|
-import org.dromara.maxkey.util.StringGenerator;
|
|
|
|
|
|
/**
|
|
|
* Reciprocal cipher or Symmetric-key algorithm
|
|
@@ -59,7 +58,7 @@ public final class ReciprocalUtils {
|
|
|
static {
|
|
|
if(System.getProperty("java.version").startsWith("1.8")) {
|
|
|
try {
|
|
|
- Security.addProvider((Provider)Instance.newInstance("com.sun.crypto.provider.SunJCE"));
|
|
|
+ Security.addProvider((Provider)newInstance("com.sun.crypto.provider.SunJCE"));
|
|
|
}catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -234,18 +233,17 @@ public final class ReciprocalUtils {
|
|
|
public static String aesDecoder(String ciphers, String secretKey) {
|
|
|
return decoderHex(ciphers, secretKey, Algorithm.AES);
|
|
|
}
|
|
|
-
|
|
|
- public static String generateKey(String algorithm) {
|
|
|
- if (algorithm.equals(Algorithm.DES)) {
|
|
|
- return (new StringGenerator(8)).randomGenerate();
|
|
|
- } else if (algorithm.equals(Algorithm.AES)) {
|
|
|
- return (new StringGenerator(16)).randomGenerate();
|
|
|
- } else if (algorithm.equals(Algorithm.Blowfish)) {
|
|
|
- return (new StringGenerator(16)).randomGenerate();
|
|
|
- } else if (algorithm.equals(Algorithm.DESede)) {
|
|
|
- return (new StringGenerator(24)).randomGenerate();
|
|
|
- } else {
|
|
|
- return (new StringGenerator()).uniqueGenerate();
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ public static Object newInstance(String className) {
|
|
|
+ Class<?> cls;
|
|
|
+ try {
|
|
|
+ cls = Class.forName(className);
|
|
|
+ Constructor<?> constructor = cls.getConstructor();
|
|
|
+ return constructor.newInstance();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
}
|