mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-30 01:46:18 +08:00
operator login interface
This commit is contained in:
51
src/main/java/love/sola/netsupport/util/AESUtil.java
Normal file
51
src/main/java/love/sola/netsupport/util/AESUtil.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class AESUtil {
|
||||
|
||||
public static final byte[] initVector = "RandomInitVector".getBytes(StandardCharsets.UTF_8);
|
||||
public static final byte[] key = "$bitch@sola.love".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
public static String encrypt(String value) {
|
||||
try {
|
||||
IvParameterSpec iv = new IvParameterSpec(initVector);
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
|
||||
|
||||
byte[] encrypted = cipher.doFinal(value.getBytes());
|
||||
|
||||
return Base64.encodeBase64String(encrypted);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String decrypt(String encrypted) {
|
||||
try {
|
||||
IvParameterSpec iv = new IvParameterSpec(initVector);
|
||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
|
||||
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
|
||||
|
||||
byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
|
||||
|
||||
return new String(original);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
24
src/main/java/love/sola/netsupport/util/Checker.java
Normal file
24
src/main/java/love/sola/netsupport/util/Checker.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/12.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class Checker {
|
||||
|
||||
public static boolean nonNull(Object... v) {
|
||||
for (Object o : v) if (o == null) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean authorized(HttpSession s, Command c) {
|
||||
return s != null && s.getAttribute("authorized") == c;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,14 +8,14 @@ import org.mindrot.jbcrypt.BCrypt;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class Crypt {
|
||||
public class Crypto {
|
||||
|
||||
public static String hash(String pw) {
|
||||
return BCrypt.hashpw(pw, BCrypt.gensalt());
|
||||
}
|
||||
|
||||
public static boolean check(String plain, String hash) {
|
||||
return BCrypt.checkpw(plain, hash);
|
||||
return BCrypt.checkpw(AESUtil.decrypt(plain), hash);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user