v1.4.0RC1

This commit is contained in:
shimingxy
2020-04-25 11:21:22 +08:00
parent 5fa24afc83
commit 08be0df891
37 changed files with 737 additions and 737 deletions

View File

@@ -10,6 +10,7 @@
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">

View File

@@ -8,9 +8,122 @@ org.eclipse.jdt.core.circularClasspath=warning
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error

View File

@@ -27,248 +27,242 @@ import org.maxkey.util.StringGenerator;
*/
public final class ReciprocalUtils {
private static final String defaultKey = "l0JqT7NvIzP9oRaG4kFc1QmD_bWu3x8E5yS2h6"; //
private static final String defaultKey = "l0JqT7NvIzP9oRaG4kFc1QmD_bWu3x8E5yS2h6"; //
public final class Algorithm {
public static final String DES = "DES";
public static final String DESede = "DESede";
public static final String Blowfish = "Blowfish";
public static final String AES = "AES";
}
public final class Algorithm {
public static final String DES = "DES";
public static final String DESede = "DESede";
public static final String Blowfish = "Blowfish";
public static final String AES = "AES";
}
public static byte[] encode(byte[] simpleBytes, SecretKey secretKey,String algorithm) {
// Create the ciphers
Cipher ecipher;
byte[] byteFinal = null;
try {
ecipher = Cipher.getInstance(secretKey.getAlgorithm());
// Encode the string into bytes using utf-8
ecipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Encrypt
byteFinal = ecipher.doFinal(simpleBytes);
return byteFinal;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static byte[] encode(byte[] simpleBytes, SecretKey secretKey, String algorithm) {
// Create the ciphers
Cipher ecipher;
byte[] byteFinal = null;
try {
ecipher = Cipher.getInstance(secretKey.getAlgorithm());
// Encode the string into bytes using utf-8
ecipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Encrypt
byteFinal = ecipher.doFinal(simpleBytes);
return byteFinal;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* @param simple
* @param secretKey
* must length
* @return
* @throws Exception
*/
public static byte[] encode(String simple, String secretKey,String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
SecretKey key = generatorKey(secretKey, algorithm);
try {
return encode(simple.getBytes("UTF-8"), key, algorithm);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
/**
* @param simple
* @param secretKey must length
* @return
* @throws Exception
*/
public static byte[] encode(String simple, String secretKey, String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
SecretKey key = generatorKey(secretKey, algorithm);
try {
return encode(simple.getBytes("UTF-8"), key, algorithm);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
public static byte[] decoder(byte[] ciphersBytes, SecretKey secretKey,String algorithm) {
Cipher cipher;
byte[] byteFinal = null;
try {
cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byteFinal = cipher.doFinal(ciphersBytes);
// String simple=new String(byteFinal, "UTF8" );
// return simple;
return byteFinal;
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return null;
}
public static byte[] decoder(byte[] ciphersBytes, SecretKey secretKey, String algorithm) {
Cipher cipher;
byte[] byteFinal = null;
try {
cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byteFinal = cipher.doFinal(ciphersBytes);
// String simple=new String(byteFinal, "UTF8" );
// return simple;
return byteFinal;
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return null;
}
public static String decoder(byte[] ciphersBytes, String secretKey,String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
SecretKey key = generatorKey(secretKey, algorithm);
try {
return new String(decoder(ciphersBytes, key, algorithm), "UTF8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
public static String decoder(byte[] ciphersBytes, String secretKey, String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
SecretKey key = generatorKey(secretKey, algorithm);
try {
return new String(decoder(ciphersBytes, key, algorithm), "UTF8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return null;
}
public static byte[] encodeByDefaultKey(String simple, String algorithm) {
SecretKey key = generatorDefaultKey(algorithm);
return encode(simple.getBytes(), key, algorithm);
public static byte[] encodeByDefaultKey(String simple, String algorithm) {
SecretKey key = generatorDefaultKey(algorithm);
return encode(simple.getBytes(), key, algorithm);
}
}
public static String encode2HexByDefaultKey(String simple, String algorithm) {
byte[] byteFinal = encodeByDefaultKey(simple, algorithm);
public static String encode2HexByDefaultKey(String simple, String algorithm) {
byte[] byteFinal = encodeByDefaultKey(simple, algorithm);
String cipherHex = HexUtils.bytes2HexString(byteFinal);
return cipherHex;
}
String cipherHex = HexUtils.bytes2HexString(byteFinal);
return cipherHex;
}
public static byte[] decoderByDefaultKey(byte[] byteCiphers,String algorithm) {
SecretKey key = generatorDefaultKey(algorithm);
return decoder(byteCiphers, key, algorithm);
public static byte[] decoderByDefaultKey(byte[] byteCiphers, String algorithm) {
SecretKey key = generatorDefaultKey(algorithm);
return decoder(byteCiphers, key, algorithm);
}
}
public static String decoderHexByDefaultKey(String ciphers, String algorithm) {
byte[] byteSimple = HexUtils.hex2Bytes(ciphers);
byte[] byteFinal = decoderByDefaultKey(byteSimple, algorithm);
public static String decoderHexByDefaultKey(String ciphers, String algorithm) {
byte[] byteSimple = HexUtils.hex2Bytes(ciphers);
String simple = null;
try {
simple = new String(byteFinal, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return simple;
byte[] byteFinal = decoderByDefaultKey(byteSimple, algorithm);
}
String simple = null;
try {
simple = new String(byteFinal, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return simple;
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);
}else if(algorithm.equals(Algorithm.AES)||algorithm.equals(Algorithm.Blowfish)){
secretKey=defaultKey.substring(0, 16);
}else if(algorithm.equals(Algorithm.DESede)){
secretKey=defaultKey.substring(0, 24);
}
//System.out.println("defaultKey : "+secretKey);
SecretKey key = new SecretKeySpec(secretKey.getBytes(), algorithm);
return key;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
private static SecretKey generatorKey(String secretKey, String algorithm) {
try {
SecretKey key = new SecretKeySpec(secretKey.getBytes(), algorithm);
return key;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
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);
} else if (algorithm.equals(Algorithm.AES) || algorithm.equals(Algorithm.Blowfish)) {
secretKey = defaultKey.substring(0, 16);
} else if (algorithm.equals(Algorithm.DESede)) {
secretKey = defaultKey.substring(0, 24);
}
// System.out.println("defaultKey : "+secretKey);
SecretKey key = new SecretKeySpec(secretKey.getBytes(), algorithm);
return key;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String encode2Hex(String simple, String secretKey,String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
byte[] cipher = encode(simple, secretKey, algorithm);
// Encode bytes to HEX to get a string
return HexUtils.bytes2HexString(cipher);
}
return null;
}
private static SecretKey generatorKey(String secretKey, String algorithm) {
try {
SecretKey key = new SecretKeySpec(secretKey.getBytes(), algorithm);
return key;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String decoderHex(String ciphers, String secretKey,String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
byte[] byteSimple = HexUtils.hex2Bytes(ciphers);
public static String encode2Hex(String simple, String secretKey, String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
byte[] cipher = encode(simple, secretKey, algorithm);
// Encode bytes to HEX to get a string
return HexUtils.bytes2HexString(cipher);
}
return null;
}
return decoder(byteSimple, secretKey, algorithm);
}
return null;
}
public static String decoderHex(String ciphers, String secretKey, String algorithm) {
if (keyLengthCheck(secretKey, algorithm)) {
byte[] byteSimple = HexUtils.hex2Bytes(ciphers);
private static boolean keyLengthCheck(String secretKey, String algorithm) {
boolean lengthCheck = false;
if (algorithm.equals(Algorithm.DES)) {
if (secretKey.length() == 8) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class).debug(
"key length is " + secretKey.getBytes().length
+ " ,must lequal 8");
}
} else if (algorithm.equals(Algorithm.DESede)) {
if (secretKey.length() == 24) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class).debug(
"key length is " + secretKey.getBytes().length
+ " ,must equal 24");
}
} else if (algorithm.equals(Algorithm.AES)) {
if (secretKey.length() == 16) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class).debug(
"key length is " + secretKey.getBytes().length
+ " ,must equal 16");
}
} else if (algorithm.equals(Algorithm.Blowfish)) {
if (secretKey.length() <= 16) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class).debug(
"key length is " + secretKey.getBytes().length
+ " ,must be less then 16");
}
}
return lengthCheck;
}
return decoder(byteSimple, secretKey, algorithm);
}
return null;
}
/**
* @param simple
* @param secretKey
* must length is 16
* @return
*/
public static String aesEncode(String simple, String secretKey) {
return encode2Hex(simple, secretKey, Algorithm.AES);
}
private static boolean keyLengthCheck(String secretKey, String algorithm) {
boolean lengthCheck = false;
if (algorithm.equals(Algorithm.DES)) {
if (secretKey.length() == 8) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class)
.debug("key length is " + secretKey.getBytes().length + " ,must lequal 8");
}
} else if (algorithm.equals(Algorithm.DESede)) {
if (secretKey.length() == 24) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class)
.debug("key length is " + secretKey.getBytes().length + " ,must equal 24");
}
} else if (algorithm.equals(Algorithm.AES)) {
if (secretKey.length() == 16) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class)
.debug("key length is " + secretKey.getBytes().length + " ,must equal 16");
}
} else if (algorithm.equals(Algorithm.Blowfish)) {
if (secretKey.length() <= 16) {
lengthCheck = true;
} else {
LogFactory.getLog(ReciprocalUtils.class)
.debug("key length is " + secretKey.getBytes().length + " ,must be less then 16");
}
}
return lengthCheck;
}
public static String aesDecoder(String ciphers, String secretKey) {
return decoderHex(ciphers, secretKey, Algorithm.AES);
}
/**
* @param simple
* @param secretKey must length is 16
* @return
*/
public static String aesEncode(String simple, String secretKey) {
return encode2Hex(simple, secretKey, Algorithm.AES);
}
/**
* encode by defaultKey with Algorithm.AES
*
* @param simple
* @return Hex
*/
public static String encode(String simple) {
return encode2HexByDefaultKey(simple, Algorithm.AES);
}
public static String aesDecoder(String ciphers, String secretKey) {
return decoderHex(ciphers, secretKey, Algorithm.AES);
}
/**
* decoder by defaultKey with Algorithm.AES
*
* @param ciphers is HEX
*
* @return
*/
public static String decoder(String ciphers) {
return decoderHexByDefaultKey(ciphers, Algorithm.AES);
}
/**
* encode by defaultKey with Algorithm.AES
*
* @param simple
* @return Hex
*/
public static String encode(String simple) {
return encode2HexByDefaultKey(simple, 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();
}
}
/**
* decoder by defaultKey with Algorithm.AES
*
* @param ciphers is HEX
*
* @return
*/
public static String decoder(String ciphers) {
return decoderHexByDefaultKey(ciphers, 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();
}
}
}

View File

@@ -14,401 +14,295 @@ import org.springframework.web.multipart.MultipartFile;
* @author Crystal.Sea
*
*/
@Table(name = "APPS_SAML_V20_DETAILS")
public class AppsSAML20Details extends Apps {
/**
*
*/
private static final long serialVersionUID = -291159876339333345L;
@Id
@Column
@GeneratedValue(strategy=GenerationType.AUTO,generator="uuid")
protected String id;
@Column
private String certIssuer;
@Column
private String certSubject;
@Column
private String certExpiration;
@Column
private byte[] keyStore;
private String entityId;
@Column
private String spAcsUrl;
@Column
private String issuer;
@Column
private String audience;
@Column
private String nameidFormat;
@Column
private String validityInterval;
/**
* Redirect-Post
* Post-Post
* IdpInit-Post
* Redirect-PostSimpleSign
* Post-PostSimpleSign
* IdpInit-PostSimpleSign
*/
@Column
private String binding;
/**
* 0 false
* 1 true
*/
@Column
private int encrypted;
/**
* for upload
*/
private MultipartFile certMetaFile;
/**
* metadata or certificate
*/
private String fileType;
/**
* 0 original
* 1 uppercase
* 2 lowercase
*/
@Column
private int nameIdConvert;
public static class BINDINGTYPE{
public String Redirect_Post="Redirect-Post";
public String Post_Post="Post-Post";
public String IdpInit_Post="IdpInit-Post";
public String Redirect_PostSimpleSign="Redirect-PostSimpleSign";
public String Post_PostSimpleSign="Post-PostSimpleSign";
public String IdpInit_PostSimpleSign="IdpInit-PostSimpleSign";
}
/**
*
*/
public AppsSAML20Details() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/**
* @return the certIssuer
*/
public String getCertIssuer() {
return certIssuer;
}
/**
* @param certIssuer the certIssuer to set
*/
public void setCertIssuer(String certIssuer) {
this.certIssuer = certIssuer;
}
/**
* @return the certSubject
*/
public String getCertSubject() {
return certSubject;
}
/**
* @param certSubject the certSubject to set
*/
public void setCertSubject(String certSubject) {
this.certSubject = certSubject;
}
/**
* @return the certExpiration
*/
public String getCertExpiration() {
return certExpiration;
}
/**
* @param certExpiration the certExpiration to set
*/
public void setCertExpiration(String certExpiration) {
this.certExpiration = certExpiration;
}
/**
* @return the keyStore
*/
public byte[] getKeyStore() {
return keyStore;
}
/**
* @param keyStore the keyStore to set
*/
public void setKeyStore(byte[] keyStore) {
this.keyStore = keyStore;
}
/**
* @return the entityId
*/
public String getEntityId() {
return entityId;
}
/**
* @param entityId the entityId to set
*/
public void setEntityId(String entityId) {
this.entityId = entityId;
}
/**
* @return the spAcsUrl
*/
public String getSpAcsUrl() {
return spAcsUrl;
}
/**
* @param spAcsUrl the spAcsUrl to set
*/
public void setSpAcsUrl(String spAcsUrl) {
this.spAcsUrl = spAcsUrl;
}
/**
* @return the issuer
*/
public String getIssuer() {
return issuer;
}
/**
* @param issuer the issuer to set
*/
public void setIssuer(String issuer) {
this.issuer = issuer;
}
/**
* @return the audience
*/
public String getAudience() {
return audience;
}
/**
* @param audience the audience to set
*/
public void setAudience(String audience) {
this.audience = audience;
}
/**
* @return the nameidFormat
*/
public String getNameidFormat() {
return nameidFormat;
}
/**
* @param nameidFormat the nameidFormat to set
*/
public void setNameidFormat(String nameidFormat) {
this.nameidFormat = nameidFormat;
}
/**
* @return the validityInterval
*/
public String getValidityInterval() {
return validityInterval;
}
/**
* @param validityInterval the validityInterval to set
*/
public void setValidityInterval(String validityInterval) {
this.validityInterval = validityInterval;
}
/**
* @return the certMetaFile
*/
public MultipartFile getCertMetaFile() {
return certMetaFile;
}
/**
* @param certMetaFile the certMetaFile to set
*/
public void setCertMetaFile(MultipartFile certMetaFile) {
this.certMetaFile = certMetaFile;
}
/**
* @return the fileType
*/
public String getFileType() {
return fileType;
}
/**
* @param fileType the fileType to set
*/
public void setFileType(String fileType) {
this.fileType = fileType;
}
public String getBinding() {
return binding;
}
public void setBinding(String binding) {
this.binding = binding;
}
public int getEncrypted() {
return encrypted;
}
public void setEncrypted(int encrypted) {
this.encrypted = encrypted;
}
public int getNameIdConvert() {
return nameIdConvert;
}
public void setNameIdConvert(int nameIdConvert) {
this.nameIdConvert = nameIdConvert;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "SAMLBaseDetails [certIssuer=" + certIssuer + ", certSubject="
+ certSubject + ", certExpiration=" + certExpiration
+ ", keyStore=" + Arrays.toString(keyStore) + ", entityId="
+ entityId + ", spAcsUrl=" + spAcsUrl + ", issuer=" + issuer
+ ", audience=" + audience + ", nameidFormat=" + nameidFormat
+ ", validityInterval=" + validityInterval + ", binding="
+ binding + ", encrypted=" + encrypted + ", certMetaFile="
+ certMetaFile + ", fileType=" + fileType + ", nameIdConvert="
+ nameIdConvert + "]";
}
@Table(name = "APPS_SAML_V20_DETAILS")
public class AppsSAML20Details extends Apps {
/**
*
*/
private static final long serialVersionUID = -291159876339333345L;
@Id
@Column
@GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
protected String id;
@Column
private String certIssuer;
@Column
private String certSubject;
@Column
private String certExpiration;
@Column
private byte[] keyStore;
@Column
private String entityId;
@Column
private String spAcsUrl;
@Column
private String issuer;
@Column
private String audience;
@Column
private String nameidFormat;
@Column
private String validityInterval;
/**
* Redirect-Post Post-Post IdpInit-Post Redirect-PostSimpleSign
* Post-PostSimpleSign IdpInit-PostSimpleSign
*/
@Column
private String binding;
/**
* 0 false 1 true
*/
@Column
private int encrypted;
/**
* for upload
*/
private MultipartFile certMetaFile;
/**
* metadata or certificate
*/
private String fileType;
/**
* 0 original 1 uppercase 2 lowercase
*/
@Column
private int nameIdConvert;
public static class BINDINGTYPE {
public String Redirect_Post = "Redirect-Post";
public String Post_Post = "Post-Post";
public String IdpInit_Post = "IdpInit-Post";
public String Redirect_PostSimpleSign = "Redirect-PostSimpleSign";
public String Post_PostSimpleSign = "Post-PostSimpleSign";
public String IdpInit_PostSimpleSign = "IdpInit-PostSimpleSign";
}
/**
*
*/
public AppsSAML20Details() {
super();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/**
* @return the certIssuer
*/
public String getCertIssuer() {
return certIssuer;
}
/**
* @param certIssuer the certIssuer to set
*/
public void setCertIssuer(String certIssuer) {
this.certIssuer = certIssuer;
}
/**
* @return the certSubject
*/
public String getCertSubject() {
return certSubject;
}
/**
* @param certSubject the certSubject to set
*/
public void setCertSubject(String certSubject) {
this.certSubject = certSubject;
}
/**
* @return the certExpiration
*/
public String getCertExpiration() {
return certExpiration;
}
/**
* @param certExpiration the certExpiration to set
*/
public void setCertExpiration(String certExpiration) {
this.certExpiration = certExpiration;
}
/**
* @return the keyStore
*/
public byte[] getKeyStore() {
return keyStore;
}
/**
* @param keyStore the keyStore to set
*/
public void setKeyStore(byte[] keyStore) {
this.keyStore = keyStore;
}
/**
* @return the entityId
*/
public String getEntityId() {
return entityId;
}
/**
* @param entityId the entityId to set
*/
public void setEntityId(String entityId) {
this.entityId = entityId;
}
/**
* @return the spAcsUrl
*/
public String getSpAcsUrl() {
return spAcsUrl;
}
/**
* @param spAcsUrl the spAcsUrl to set
*/
public void setSpAcsUrl(String spAcsUrl) {
this.spAcsUrl = spAcsUrl;
}
/**
* @return the issuer
*/
public String getIssuer() {
return issuer;
}
/**
* @param issuer the issuer to set
*/
public void setIssuer(String issuer) {
this.issuer = issuer;
}
/**
* @return the audience
*/
public String getAudience() {
return audience;
}
/**
* @param audience the audience to set
*/
public void setAudience(String audience) {
this.audience = audience;
}
/**
* @return the nameidFormat
*/
public String getNameidFormat() {
return nameidFormat;
}
/**
* @param nameidFormat the nameidFormat to set
*/
public void setNameidFormat(String nameidFormat) {
this.nameidFormat = nameidFormat;
}
/**
* @return the validityInterval
*/
public String getValidityInterval() {
return validityInterval;
}
/**
* @param validityInterval the validityInterval to set
*/
public void setValidityInterval(String validityInterval) {
this.validityInterval = validityInterval;
}
/**
* @return the certMetaFile
*/
public MultipartFile getCertMetaFile() {
return certMetaFile;
}
/**
* @param certMetaFile the certMetaFile to set
*/
public void setCertMetaFile(MultipartFile certMetaFile) {
this.certMetaFile = certMetaFile;
}
/**
* @return the fileType
*/
public String getFileType() {
return fileType;
}
/**
* @param fileType the fileType to set
*/
public void setFileType(String fileType) {
this.fileType = fileType;
}
public String getBinding() {
return binding;
}
public void setBinding(String binding) {
this.binding = binding;
}
public int getEncrypted() {
return encrypted;
}
public void setEncrypted(int encrypted) {
this.encrypted = encrypted;
}
public int getNameIdConvert() {
return nameIdConvert;
}
public void setNameIdConvert(int nameIdConvert) {
this.nameIdConvert = nameIdConvert;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "SAMLBaseDetails [certIssuer=" + certIssuer + ", certSubject=" + certSubject + ", certExpiration="
+ certExpiration + ", keyStore=" + Arrays.toString(keyStore) + ", entityId=" + entityId + ", spAcsUrl="
+ spAcsUrl + ", issuer=" + issuer + ", audience=" + audience + ", nameidFormat=" + nameidFormat
+ ", validityInterval=" + validityInterval + ", binding=" + binding + ", encrypted=" + encrypted
+ ", certMetaFile=" + certMetaFile + ", fileType=" + fileType + ", nameIdConvert=" + nameIdConvert
+ "]";
}
}