mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-11-01 02:46:19 +08:00 
			
		
		
		
	| @@ -28,7 +28,6 @@ import love.sola.netsupport.sql.SQLCore; | ||||
| import love.sola.netsupport.sql.TableOperator; | ||||
| import love.sola.netsupport.sql.TableUser; | ||||
| import love.sola.netsupport.util.Crypto; | ||||
| import love.sola.netsupport.util.RSAUtil; | ||||
| import love.sola.netsupport.wechat.Command; | ||||
|  | ||||
| import javax.servlet.ServletException; | ||||
| @@ -73,7 +72,7 @@ public class Login extends HttpServlet { | ||||
|             else if (op.getAccess() >= Access.NO_LOGIN) | ||||
|                 return Error.PERMISSION_DENIED; | ||||
|  | ||||
|             if (!Crypto.check(bypass ? password : RSAUtil.decrypt(password), op.getPassword())) { | ||||
|             if (!Crypto.check(password, op.getPassword())) { | ||||
|                 return Error.WRONG_PASSWORD; | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -1,59 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of WechatTicketSystem. | ||||
|  * | ||||
|  * WechatTicketSystem is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * WechatTicketSystem is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with WechatTicketSystem.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| package love.sola.netsupport.config; | ||||
|  | ||||
| import org.yaml.snakeyaml.Yaml; | ||||
|  | ||||
| import java.io.InputStream; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.regex.Pattern; | ||||
|  | ||||
| /** | ||||
|  * @author Sola {@literal <dev@sola.love>} | ||||
|  */ | ||||
| public class Cortana { | ||||
|  | ||||
|     public static List<Compiled> entries; | ||||
|  | ||||
|     public static void load() { | ||||
|         InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml"); | ||||
|         RawConfig root = new Yaml().loadAs(in, RawConfig.class); | ||||
|     } | ||||
|  | ||||
|     static class Compiled { | ||||
|         Pattern[] patterns; | ||||
|         String[] replies; | ||||
|     } | ||||
|  | ||||
|     public static class Rule { | ||||
|         String[] regexp; | ||||
|         String[] replies; | ||||
|  | ||||
|         public Rule() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static class RawConfig { | ||||
|         Map<String, Rule> rules; | ||||
|  | ||||
|         public RawConfig() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,81 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of WechatTicketSystem. | ||||
|  * | ||||
|  * WechatTicketSystem is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Lesser General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * WechatTicketSystem is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public License | ||||
|  * along with WechatTicketSystem.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| package love.sola.netsupport.util; | ||||
|  | ||||
| import org.apache.commons.codec.binary.Base64; | ||||
|  | ||||
| import javax.crypto.Cipher; | ||||
| import java.nio.charset.StandardCharsets; | ||||
| import java.security.Key; | ||||
| import java.security.KeyPair; | ||||
| import java.security.KeyPairGenerator; | ||||
|  | ||||
| /** | ||||
|  * @author Sola {@literal <dev@sola.love>} | ||||
|  */ | ||||
| public class RSAUtil { | ||||
|  | ||||
|  | ||||
|     public static Key publicKey; | ||||
|     public static Key privateKey; | ||||
|     public static String publicKey_s; | ||||
|     public static String privateKey_s; | ||||
|  | ||||
|     static { | ||||
|         genKeyPair(); | ||||
|     } | ||||
|  | ||||
|     public static void genKeyPair() { | ||||
|         try { | ||||
|             KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); | ||||
|             kpg.initialize(1024); | ||||
|             KeyPair kp = kpg.genKeyPair(); | ||||
|             publicKey = kp.getPublic(); | ||||
|             privateKey = kp.getPrivate(); | ||||
|             publicKey_s = Base64.encodeBase64String(publicKey.getEncoded()); | ||||
|             privateKey_s = Base64.encodeBase64String(privateKey.getEncoded()); | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static String encrypt(String value) { | ||||
|         try { | ||||
|             Cipher cipher = Cipher.getInstance("RSA"); | ||||
|             cipher.init(Cipher.ENCRYPT_MODE, publicKey); | ||||
|             byte[] encrypted = cipher.doFinal(value.getBytes(StandardCharsets.UTF_8)); | ||||
|             return Base64.encodeBase64String(encrypted); | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     public static String decrypt(String encrypted) { | ||||
|         try { | ||||
|             Cipher cipher = Cipher.getInstance("RSA"); | ||||
|             cipher.init(Cipher.DECRYPT_MODE, privateKey); | ||||
|             byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); | ||||
|             return new String(original, StandardCharsets.UTF_8); | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola