I have been searching for examples where update query is performed in Advanced Encryption Standard with java, but couldn't find any except for update query in MySQL with AES_ENCRYPT? .
The code below functions, but the data is not encrypted, my question is how can I update the data with AES_ENCRYPT
try{
String value1 = jTextFieldID.getText();
String value2 = jTextFieldFirstname.getText();
String value3 = jTextFieldMiddlename.getText();
String value4 = jTextFieldLastname.getText();
String value5 = ((JTextField)txt_Date.getDateEditor().getUiComponent()).getText();
String value6= Gander.toString();
String value7= jTextFieldAddress.getText();
String value8 = jTextFieldCity.getText();
String value9 = jTextFieldPostcode.getText();
String sql = "update Customer set ID='"
+value1+"',FirstName='"
+value2+"',MiddleName='"
+value3+"',LastName='"
+value4+"',DOB='"
+value5+"',Gander='"
+value6+"',Address='"
+value7+"',City='"
+value8+"',PostCode='"
+value9+"'where ID='"
+value1+"'";
pst = conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null, "Data is updated");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
The AES_DECRYPT
SELECT ID, AES_DECRYPT( FirstName, 'uk112' ) AS FirstName, AES_DECRYPT( MiddleName, 'uk112' ) AS MiddleName, AES_DECRYPT( LastName, 'uk112' ) AS LastName, AES_DECRYPT( DOB, 'uk112' ) AS DOB, AES_DECRYPT( Gander, 'uk112' ) AS Gander, AES_DECRYPT( Address, 'uk112' ) AS Address, AES_DECRYPT( City, 'uk112' ) AS City, AES_DECRYPT( PostCode, 'uk112' ) AS PostCode FROM Customer
Hi have you tried this?
String sql = "update Customer set FirstName= AES_ENCRYPT(?,'uk112'),MiddleName= AES_ENCRYPT(?,'uk112'),LastName= AES_ENCRYPT(?,'uk112'),DOB=?,Gander= AES_ENCRYPT(?,'uk112'),Address= AES_ENCRYPT(?,'uk112'),City= AES_ENCRYPT(?,'uk112'),PostCode= AES_ENCRYPT(?,'uk112') where ID=?";
pst = conn.prepareStatement(sql);
pst.setString(1, value2);
pst.setString(2, value3);
pst.setString(3, value4);
pst.setString(4, value5);
pst.setString(5, value6);
pst.setString(6, value7);
pst.setString(7, value8);
pst.setString(8, value9);
pst.setString(9, value1);
pst.execute();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.