public void setMacKey(String field, String key) {
try {
Class.forName("org.sqlite.JDBC");
String jdbcURL =
"jdbc:sqlite://G:/rbcmb/epay/demo/CMBEpayDemo/epay.db";
Connection conn = DriverManager.getConnection(jdbcURL);
Statement stat = conn.createStatement();
String update = "update st_tab_merch_key set " + field
+ " = '" + key + "' where keyindex = '" + merchId + "' ;";
stat.executeUpdate(update);
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void getMacKey(String merchId) {
this.merchId = merchId;
try {
Class.forName("org.sqlite.JDBC");
String jdbcURL =
"jdbc:sqlite://G:/rbcmb/epay/demo/CMBEpayDemo/epay.db";
Connection conn = DriverManager.getConnection(jdbcURL);
Statement stat = conn.createStatement();
String query = "select dekey, mackey from tab_merch_key where keyindex = '"
+ merchId + "' ;";
ResultSet rs =
stat.executeQuery(query);
while (rs.next()) { // 将查询到的数据打印出来
String dekey = rs.getString("dekey");
macKey = CDesHelper.decrypt(rs.getString("mackey"), dekey);
//System.out.println("key = " + macKey);
}
rs.close(); // 关闭结果集
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}