insert an encrypt data in a Table
Hi all,
i have encrypted a data with HmacMD5, all its fine. but when i've tried to insert encrypt data in my table, hash code may return symbols like ?愥Z弮x狼. then when i do a select data has been corrupted. how can i encrypted in stardand symbols( like mysql passwords). here is my code:
KeyGenerator kg = KeyGenerator.getInstance("HmacMD5");
SecretKey sk = kg.generateKey();
// Get instance of Mac object implementing HMAC-MD5, and
// initialize it with the above secret key
Mac mac = Mac.getInstance("HmacMD5");
mac.init(sk);
byte[] result = mac.doFinal(dirMAC.getBytes());
String macenc=new String(result);
String x ="jdbc:mysql://localhost/"+
"mydatabase?user="+user+"&password="+
pass;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(x);
conn.createStatement().executeUpdate("insert into user " +
"(User,Password) values('system','"+myPass+"')");
java.sql.ResultSet rs=conn.createStatement().executeQuery("select password "+
"from " +"user where user ='system' ");
rs.next();
if((rs.getString(1).equals(macenc))){
System.out.println(rs.getString(1)+" YES "+macenc);
}else{
System.out.println(rs.getString(1)+" NO "+macenc);
}
Output NO. and sometimes when hash has (') character Query not found.
thanks.

