operator login interface

This commit is contained in:
Sola
2015-12-12 05:00:06 +08:00
parent a3ba3377db
commit 8a8281b973
10 changed files with 185 additions and 16 deletions

View 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;
}
}

View 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;
}
}

View File

@@ -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);
}
}