1: public class S260 { 2: public boolean connectTest(String url, String usr, Key key) { 3: Connection con = null; 4: byte[] b = new byte[1024]; 5: boolean result = false; 6: try { 7: FileInputStream fs = new FileInputStream("sample.cfg"); 8: if (fs == null || fs.available() <= 0) return false; 9: // 외부 파일로 부터 암호화된 입력값을 받는다. 10: int length = fs.read(b); 11: if (length == 0) { 12: result = false; 13: } else { 14: // 암호화된 패스워드를 복호화한다. 15: Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding" ); 16: cipher.init(Cipher.DECRYPT_MODE, key); 17: byte[] db = cipher.doFinal(b); 18: // 문자열 변환 19: String password = new String(db, "utf-8"); 20: // DB 연결 21: con = DriverManager.getConnection(url, usr, password); 22: } 23: } catch (FileNotFoundException e) { 24: System.err.println("File Not Found Exception Occurred!"); 25: } catch (IOException e) { 26: System.err.println("I/O Exception Occurred!"); 27: } catch (SQLException e) { 28: System.err.println("SQL Exception Occurred!"); 29: } catch (NoSuchAlgorithmException e) { 30: System.err.println("NoSuchAlgorithmException Occurred!"); 31: } catch (NoSuchPaddingException e) { 32: System.err.println("NoSuchPaddingException Occurred!"); 33: } catch (InvalidKeyException e) { 34: System.err.println("InvalidKeyException Occurred!"); 35: } catch (IllegalBlockSizeException e) { 36: System.err.println("IllegalBlockSizeException Occurred!"); 37: } catch (BadPaddingException e) { 38: System.err.println("BadPaddingException Occurred!"); 39: } finally { 40: try { 41: if (con != null) { 42: con.close(); 43: result = true; } } catch (SQLException e) { 44: System.err.println("SQL Exception Occurred!"); 45: } } return result; } }