|
|
@@ -37,7 +37,7 @@ public class Crypto {
|
|
|
|
|
|
private static final String RSA = "RSA";
|
|
|
|
|
|
- private static final String KEY = "HANGZHOU";
|
|
|
+ private static final String NEVERCHANGEKEY = "NEVERCHANGEKEY";
|
|
|
|
|
|
public static String encrypt(String data, String key) throws Exception {
|
|
|
byte[] bt = encrypt(data.getBytes(), key.getBytes());
|
|
|
@@ -126,58 +126,6 @@ public class Crypto {
|
|
|
public static final String TEST_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCWcVZIS57VeOUzi8c01WKvwJK9uRe6hrGTUYmF6J/pI6/UvCbdBWCoErbzsBZOElOH8Sqal3vsNMVLjPYClfoDyYDaUlakP3ldfnXJzAFJVVubF53KadG+fwnh9ZMvxdh7VXVqRL3IQBDwGgzX4rmSK+qkUJjc3OkrNJPB7LLD8QIDAQAB";
|
|
|
public static final String TEST_PRIVATE_KEY = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJZxVkhLntV45TOLxzTVYq/Akr25F7qGsZNRiYXon+kjr9S8Jt0FYKgStvOwFk4SU4fxKpqXe+w0xUuM9gKV+gPJgNpSVqQ/eV1+dcnMAUlVW5sXncpp0b5/CeH1ky/F2HtVdWpEvchAEPAaDNfiuZIr6qRQmNzc6Ss0k8HsssPxAgMBAAECgYAWtRy05NUgm5Lc6Og0jVDL/mEnydxPBy2ectwzHh2k7wIHNi8XhUxFki2TMqzrM9Dv3/LySpMl4AE3mhs34LNPy6F+MwyF5X7j+2Y6MflJyeb9HNyT++viysQneoOEiOk3ghxF2/GPjpiEF79wSp+1YKTxRAyq7ypV3t35fGOOEQJBANLDPWl8b5c3lrcz/dTamMjHbVamEyX43yzQOphzkhYsz4pruATzTxU+z8/zPdEqHcWWV39CP3xu3EYNcAhxJW8CQQC2u7PF5Xb1xYRCsmIPssFxil64vvdUadSxl7GLAgjQ9ULyYWB24KObCEzLnPcT8Pf2Q0YQOixxa/78FuzmgbyfAkA7ZFFV/H7lugB6t+f7p24OhkRFep9CwBMD6dnZRBgSr6X8d8ZvfrD2Z7DgBMeSva+OEoOtlNmXExZ3lynO9zN5AkAVczEmIMp3DSl6XtAuAZC9kD2QODJ2QToLYsAfjiyUwsWKCC43piTuVOoW2KUUPSwOR1VZIEsJQWEcHGDQqhgHAkAeZ7a6dVRZFdBwKA0ADjYCufAW2cIYiVDQBJpgB+kiLQflusNOCBK0FT3lg8BdUSy2D253Ih6l3lbaM/4M7DFQ";
|
|
|
|
|
|
-// private static final String KEY_AES = "AES";
|
|
|
-//
|
|
|
-// public static String aesEncrypt(String src) throws NoSuchAlgorithmException, NoSuchPaddingException,
|
|
|
-// InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
|
|
-// byte[] raw = "hangzhouzhejiang".getBytes();
|
|
|
-// SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_AES);
|
|
|
-// Cipher cipher = Cipher.getInstance(KEY_AES);
|
|
|
-// cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
|
|
|
-// byte[] encrypted = cipher.doFinal(src.getBytes());
|
|
|
-// return byte2hex(encrypted);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public static String aesDecrypt(String src) throws NoSuchAlgorithmException, NoSuchPaddingException,
|
|
|
-// InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
|
|
-// byte[] raw = "hangzhouzhejiang".getBytes();
|
|
|
-// SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_AES);
|
|
|
-// Cipher cipher = Cipher.getInstance(KEY_AES);
|
|
|
-// cipher.init(Cipher.DECRYPT_MODE, skeySpec);
|
|
|
-// byte[] encrypted1 = hex2byte(src);
|
|
|
-// byte[] original = cipher.doFinal(encrypted1);
|
|
|
-// return new String(original);
|
|
|
-// }
|
|
|
-//
|
|
|
-// public static byte[] hex2byte(String strhex) {
|
|
|
-// if (strhex == null) {
|
|
|
-// return new byte[0];
|
|
|
-// }
|
|
|
-// int l = strhex.length();
|
|
|
-// if (l % 2 == 1) {
|
|
|
-// return new byte[0];
|
|
|
-// }
|
|
|
-// byte[] b = new byte[l / 2];
|
|
|
-// for (int i = 0; i != l / 2; i++) {
|
|
|
-// b[i] = (byte) Integer.parseInt(strhex.substring(i * 2, i * 2 + 2), 16);
|
|
|
-// }
|
|
|
-// return b;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public static String byte2hex(byte[] b) {
|
|
|
-// StringBuilder sb = new StringBuilder();
|
|
|
-// String tmp = "";
|
|
|
-// for (int n = 0; n < b.length; n++) {
|
|
|
-// tmp = (Integer.toHexString(b[n] & 0XFF));
|
|
|
-// if (tmp.length() == 1) {
|
|
|
-// sb.append("0" + tmp);
|
|
|
-// } else {
|
|
|
-// sb.append(tmp);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return sb.toString().toUpperCase();
|
|
|
-// }
|
|
|
-
|
|
|
public static String plainTextPassword(String text) throws Exception {
|
|
|
if (StringUtils.isEmpty(text)) {
|
|
|
return text;
|
|
|
@@ -187,7 +135,7 @@ public class Crypto {
|
|
|
String value = StringEscapeUtils.unescapeJson(matcher.group(1));
|
|
|
if (StringUtils.startsWithIgnoreCase(value, "ENCRYPT:")) {
|
|
|
String de = StringUtils.substringAfter(value, ":");
|
|
|
- return decrypt(de, KEY);
|
|
|
+ return decrypt(de, NEVERCHANGEKEY);
|
|
|
} else {
|
|
|
String eval = ScriptFactory.functionalization(StringEscapeUtils.unescapeJson(value));
|
|
|
ScriptContext scriptContext = new SimpleScriptContext();
|
|
|
@@ -199,7 +147,7 @@ public class Crypto {
|
|
|
}
|
|
|
|
|
|
public static String defaultEncrypt(String data) throws Exception {
|
|
|
- byte[] bt = encrypt(data.getBytes(), KEY.getBytes());
|
|
|
+ byte[] bt = encrypt(data.getBytes(), NEVERCHANGEKEY.getBytes());
|
|
|
String str = Base64.encodeBase64URLSafeString(bt);
|
|
|
return URLEncoder.encode(str, utf8);
|
|
|
}
|