Example AES technology
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.io.IOUtils;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Listing all table name in Database!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
String name="";
String address="";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
System.out.println("Table name:");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select AES_DECRYPT(name, 'usa2010'), AES_DECRYPT(address, 'usa2010') FROM test.table1");
while (rs.next()){
name = IOUtils.toString(rs.getBinaryStream(1), "UTF-8"); ;
address = IOUtils.toString(rs.getBinaryStream(2), "UTF-8");
System.out.println("name: "+name);
System.out.println("address: "+address);
}
}
catch (SQLException s){
s.printStackTrace();
}
}
catch(Exception e){
}
}
}
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.io.IOUtils;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Listing all table name in Database!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
String name="";
String address="";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
System.out.println("Table name:");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select AES_DECRYPT(name, 'usa2010'), AES_DECRYPT(address, 'usa2010') FROM test.table1");
while (rs.next()){
name = IOUtils.toString(rs.getBinaryStream(1), "UTF-8"); ;
address = IOUtils.toString(rs.getBinaryStream(2), "UTF-8");
System.out.println("name: "+name);
System.out.println("address: "+address);
}
}
catch (SQLException s){
s.printStackTrace();
}
}
catch(Exception e){
}
}
}
Comments
Post a Comment