한국어

스마트폰앱

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


http://stilius.net/java/java_ssl.php

 

http://www.java2s.com/Tutorial/Java/0490__Security/SSLServerSession.htm

 

http://www.koders.com/java/fid199C1E3C46D2644420D8B81790C79185FBAD8316.aspx

 

http://stackoverflow.com/questions/6559859/is-it-possible-to-change-plain-socket-to-sslsocket

 

JAVA + SSL Tutorial (server and client examples)

Certificate

First we need to make certificate, this is done by using keytool that is part of J2SE SDK (program will ask for certificate owner information and password, enter 123456 as password, or you can enter your password, but notice that you have to change it in other commands listen in this tutorial):

keytool -genkey -keystore mySrvKeystore -keyalg RSA

After this command you will have certificate file in working directory of issuing keytool command.

Server source code (EchoServer.java)

import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public
class EchoServer {
    public
            static
    void
            main(String[] arstring) {
        try {
            SSLServerSocketFactory sslserversocketfactory =
                    (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
            SSLServerSocket sslserversocket =
                    (SSLServerSocket) sslserversocketfactory.createServerSocket(9999);
            SSLSocket sslsocket = (SSLSocket) sslserversocket.accept();

            InputStream inputstream = sslsocket.getInputStream();
            InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
            BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

            String string = null;
            while ((string = bufferedreader.readLine()) != null) {
                System.out.println(string);
                System.out.flush();
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
      

Compile it by using simple command:

javac EchoServer.java

Client source code (EchoClient.java)

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;

public
class EchoClient {
    public
            static
    void
            main(String[] arstring) {
        try {
            SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("localhost", 9999);

            InputStream inputstream = System.in;
            InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
            BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

            OutputStream outputstream = sslsocket.getOutputStream();
            OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
            BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);

            String string = null;
            while ((string = bufferedreader.readLine()) != null) {
                bufferedwriter.write(string + '\n');
                bufferedwriter.flush();
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
      

Compile it by using simple command:

javac EchoClient.java

Running server and client using SSL

First copy certificate file that you created before into working directory and run server with these parameters (notice that you have to change keyStore name and/or trustStrorePassword if you specified different options creating certificate:

java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=123456 EchoServer

And now again copy certificate file that you created before into working directory and run client with these parameters (notice that you have to change keyStore name and/or trustStrorePassword if you specified different options creating certificate:

java -Djavax.net.ssl.trustStore=mySrvKeystore -Djavax.net.ssl.trustStorePassword=123456 EchoClient

If you want SSL debug information just add these parameters when running server and/or client:

-Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol -Djavax.net.debug=ssl

Playing with server and client

Now just type any string on client console and press return. The same string has to appear on server console.

Copyright

This document is copyrighted to Tomas Vilda. You can use it in all ways, but don't change this section and allways include it.

조회 수 :
31611
등록일 :
2012.10.07
14:17:29 (*.160.42.233)
엮인글 :
http://webs.co.kr/index.php?document_srl=12632&act=trackback&key=467
게시글 주소 :
http://webs.co.kr/index.php?document_srl=12632
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
66 Csipsimple code rebuilding source 주요인터페이스분석 admin 2014-02-09 274167
65 Csipsimple code rebuilding source sip 통신 Call Mechanism admin 2014-02-09 108938
64 Android 2.0 주소록 동기화 기능 admin 2012-09-30 73624
63 안드로이드마켓에 앱 등록하는 순서 admin 2012-08-19 68136
62 Unicode Tables v4 admin 2012-10-16 56841
61 Android User Session Management using Shared Preferences admin 2012-10-16 55853
60 안드로이드 타이머 절적한 설명과 간단한소스코드 등 안드로이드 프로그램 설명 깔끔 admin 2012-09-23 51085
59 How to Show Alert Dialog in Android (간단하고 쉬운설명) admin 2012-10-15 43902
58 [안드로이드] 서버/클라이언트 소켓(Socket) 통신하기 admin 2012-09-20 43039
57 [안드로이드/개발] Intent admin 2012-09-23 40491
56 통신사별 와이파이 비밀번호 admin 2012-10-31 38926
» JAVA + SSL (server and client examples) admin 2012-10-07 31611
54 WIFI 3G 인터넷 연결 실시간 체크 소스코드 Broadcast Receiver 사용 (Adnroid) admin 2012-10-31 30743
53 Android Detect Internet Connection Status admin 2012-10-12 29722
52 안드로이드 주소록 전체가져오기 이름만가져오기 사진가져오기 코드 admin 2015-04-13 29632
51 Rotary Dialer clip art admin 2013-04-20 24918
50 WIFI 3G 인터넷 연결 체크 소스코드 직접 사용한 코드 android admin 2012-10-14 24410
49 안드로이드용 앱 개발 마켓등록 까지 해본거 샘플 무료국제전화 앱 FreeDialer admin 2012-09-27 23879
48 Android Contacts API 2 example admin 2012-09-30 23479
47 Android SQlite 사용 admin 2012-09-04 22871
46 전화관련 안드로이드함수 admin 2012-08-18 22822
45 자바 ,이클립스,Android SDK, ADT 설치하여 무료국제전화 다이얼러를 만들어봅시다. admin 2012-08-06 22623
44 안드로이드 인터넷연결체크 ( 3g/lte/wifi ) 메서드 admin 2013-12-19 21573
43 How to read contacts on Android 2.0 admin 2012-10-14 21187
42 Java 프로그램 실행화일 만들기 : Launch4j admin 2013-02-21 20677
41 접속번호 + 상대방번호 # 를 주소록에 전화번호로 저장하여 사용하면 편리하다 admin 2012-06-17 20491
40 FreeDial 무료국제전화는 프리미엄 국제전화 다이렉트 회선사용 admin 2012-09-20 20383
39 Manage Contacts android admin 2012-09-30 20254
38 아이폰 IPhone 앱 개발 기본 admin 2012-09-27 20207
37 2X Client Configuration | Android Remote Desktop 안드로이드 PC 리모트 데스크탑 admin 2012-12-02 19683