Repository navigation
Expand file tree
/
Copy pathHfsession.java
More file actions
executable file
·58 lines (51 loc) · 1.57 KB
/
Copy pathHfsession.java
File metadata and controls
executable file
·58 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package basis;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.junit.Test;
public class Hfsession {
static SessionFactory sessionFactory; //会话工厂
static Session session ; //会话
static Transaction tx ; //事务
//此方法用于会话的创建和初始化
public static Session init() {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
// tx = session.beginTransaction();
return session;
}
//关闭会话
public static void close() {
//tx.commit();
if(session.isOpen()){
session.close();
sessionFactory.close();
}
}
/**
* 秘钥
*/
public static final String KEY_MD = "MD5";
/**
* 加密
* @param inputStr
* @return
*/
public static String getResult(String inputStr) {
//System.out.println("=======加密前的数据:"+inputStr);
BigInteger bigInteger=null;
try {
MessageDigest md = MessageDigest.getInstance(KEY_MD);
byte[] inputData = inputStr.getBytes();
md.update(inputData);
bigInteger = new BigInteger(md.digest());
}
catch (NoSuchAlgorithmException e) {e.printStackTrace();}
//System.out.println("MD加密后:" + bigInteger.toString());
return bigInteger.toString();
}
}