现在做的是文件的加密与解密。
我在解密时,从数据库里查到我要的记录然后赋值给另一个对象,当是在session.close()后赋值。却发现数据库里对应的字段已经被同步解密了。为什么啊?奇怪!
这是我解密的代码:
/**
* 根据知识Id号查找知识的详细信息 (用户浏览信息)
*
* @param knowledgeId
* @return
*/
public List findMyKnowledgeByKnowledgeId(int knowledgeId) {
Session session = HibernateUtil.currentSession();
List<KmsKnowledge> li = new ArrayList<KmsKnowledge>();
// knowledgeResult=2表示已通过的知识
String hql = "from KmsKnowledge as k where k.knowledgeId='"
+ knowledgeId + "' ";
List list = session.createQuery(hql).list();
KmsKnowledge k = new KmsKnowledge();
KmsKnowledge kn = new KmsKnowledge();
for (java.util.Iterator iter = list.iterator(); iter.hasNext();) {
kn = (KmsKnowledge) iter.next();
}
HibernateUtil.closeSession();
if (session.isOpen()) {
System.out.println("session马上就要关闭了");
session.close();
}
/** *******文件解密*********** */
DesEncrypt des = new DesEncrypt();
des.getKey("sneb");
String knowledgeContent = des.getDesString(kn.getKnowledgeContent());
String knowledgeSub = des.getDesString(kn.getKnowledgeSub());
String knowledgeBg = des.getDesString(kn.getKnowledgeBg());
k.setKnowledgeContent(knowledgeContent);
k.setKnowledgeSub(knowledgeSub);
k.setKnowledgeBg(knowledgeBg);
li.add(k);
return li;
}
[此贴子已经被作者于2007-10-24 11:02:34编辑过]