import java.io.InputStream; import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class TestDes { private static void printData(byte[] data) { System.out.println(""); for (int i = 0; i < data.length; i++) { System.out.print(data[i] + ","); } } /** * @param args */ public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/test", "root", "123456"); Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery("select name from test"); while (rs.next()) { Blob blob = rs.getBlob("name"); InputStream is = blob.getBinaryStream(); byte[] data = new byte[is.available()]; is.read(data); is.close(); printData(data); } SecretKey deskey = new SecretKeySpec("123456789123456789123456" .getBytes(), "DESede"); Cipher c1 = Cipher.getInstance("DESede"); c1.init(Cipher.ENCRYPT_MODE, deskey); byte[] data = c1.doFinal("111".getBytes()); printData(data); } } // $Id$