Skip to content

Commit

Permalink
update EncryptDencrypt by tylerchen
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerchen committed Nov 20, 2017
1 parent 4ffa42f commit 9e5341f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
Binary file not shown.
Binary file modified builds/org/iff/tc-util-project/1.0.19/tc-util-project-1.0.19.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion builds/org/iff/tc-util-project/maven-metadata-local.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<version>1.0.18</version>
<version>1.0.19</version>
</versions>
<lastUpdated>20171109161024</lastUpdated>
<lastUpdated>20171120084252</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
*/
public interface EncryptDencrypt {

public static final String METHOD_MD5 = "MD5";
public static final String METHOD_MD5_2 = "MD5-2";
public static final String METHOD_MD5_FIRST = "MD5-first";
public static final String METHOD_MD5_SECOND = "MD5-second";
public static final String METHOD_MD5_BOTH = "MD5-both";
public static final String METHOD_RSA = "RSA";

String encrypt(String method, String salt, String value);

String dencrypt(String method, String salt, String value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ public String encrypt(String method, String saltOrKey, String value) {
if (StringUtils.isEmpty(value)) {
return value;
}
if ("MD5".equalsIgnoreCase(method)) {
if (EncryptDencrypt.METHOD_MD5.equalsIgnoreCase(method)) {
return MD5Helper.string2MD5(value);
} else if ("MD5-2".equalsIgnoreCase(method)) {
} else if (EncryptDencrypt.METHOD_MD5_2.equalsIgnoreCase(method)) {
if (StringUtils.isNotEmpty(saltOrKey)) {
return MD5Helper.string2MD5(saltOrKey + "-" + MD5Helper.string2MD5(value));
}
return MD5Helper.string2MD5(MD5Helper.string2MD5(value));
} else if ("RSA".equalsIgnoreCase(method)) {
} else if (EncryptDencrypt.METHOD_MD5_FIRST.equalsIgnoreCase(method)) {
return MD5Helper.firstSalt(value);
} else if (EncryptDencrypt.METHOD_MD5_SECOND.equalsIgnoreCase(method)) {
return MD5Helper.secondSalt(value);
} else if (EncryptDencrypt.METHOD_MD5_BOTH.equalsIgnoreCase(method)) {
return MD5Helper.firstSalt(MD5Helper.secondSalt(value));
} else if (EncryptDencrypt.METHOD_RSA.equalsIgnoreCase(method)) {
if (StringUtils.isNotEmpty(saltOrKey)) {
return RSAHelper.encrypt(value, RSAHelper.getPublicKeyFromBase64(saltOrKey));
} else {
Expand All @@ -45,11 +51,17 @@ public String dencrypt(String method, String saltOrKey, String value) {
if (StringUtils.isEmpty(value)) {
return value;
}
if ("MD5".equalsIgnoreCase(method)) {
if (EncryptDencrypt.METHOD_MD5.equalsIgnoreCase(method)) {
Assert.error(FCS.get("Encrypt method {0} is not supported for dencrypt!", method));
} else if ("MD5-2".equalsIgnoreCase(method)) {
} else if (EncryptDencrypt.METHOD_MD5_2.equalsIgnoreCase(method)) {
Assert.error(FCS.get("Encrypt method {0} is not supported for dencrypt!", method));
} else if ("RSA".equalsIgnoreCase(method)) {
} else if (EncryptDencrypt.METHOD_MD5_FIRST.equalsIgnoreCase(method)) {
Assert.error(FCS.get("Encrypt method {0} is not supported for dencrypt!", method));
} else if (EncryptDencrypt.METHOD_MD5_SECOND.equalsIgnoreCase(method)) {
Assert.error(FCS.get("Encrypt method {0} is not supported for dencrypt!", method));
} else if (EncryptDencrypt.METHOD_MD5_BOTH.equalsIgnoreCase(method)) {
Assert.error(FCS.get("Encrypt method {0} is not supported for dencrypt!", method));
} else if (EncryptDencrypt.METHOD_RSA.equalsIgnoreCase(method)) {
if (StringUtils.isNotEmpty(saltOrKey)) {
return RSAHelper.decrypt(value, RSAHelper.getPrivateKeyFromBase64(saltOrKey));
} else {
Expand Down

0 comments on commit 9e5341f

Please sign in to comment.