<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>theLogicBlog</title>
	<atom:link href="http://thelogic.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://thelogic.org/blog</link>
	<description>Things for me to remember</description>
	<lastBuildDate>Tue, 08 Jun 2010 11:23:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oracle NLS settings</title>
		<link>http://thelogic.org/blog/2010/05/28/oracle-nls-settings/</link>
		<comments>http://thelogic.org/blog/2010/05/28/oracle-nls-settings/#comments</comments>
		<pubDate>Fri, 28 May 2010 09:18:35 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[nls]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=166</guid>
		<description><![CDATA[DATABASE
 -> settings from init.ora at creation of database
 -> select * from nls_instance_parameters;
INSTANCE
 -> settings from init.ora or spfile when instance was started
 -> overwrites DATABASE settings
 -> select * from nls_session_parameters;
SESSION
 -> settings changed through alter session
 -> overwrites INSTANCE settings
 -> select * from nls_session_parameters;
Character Set:
select value from nls_database_parameters where parameter = [...]]]></description>
			<content:encoded><![CDATA[<p>DATABASE<br />
 -> settings from init.ora at creation of database<br />
 -> select * from nls_instance_parameters;</p>
<p>INSTANCE<br />
 -> settings from init.ora or spfile when instance was started<br />
 -> overwrites DATABASE settings<br />
 -> select * from nls_session_parameters;</p>
<p>SESSION<br />
 -> settings changed through alter session<br />
 -> overwrites INSTANCE settings<br />
 -> select * from nls_session_parameters;</p>
<p>Character Set:<br />
select value from nls_database_parameters where parameter = &#8216;NLS_CHARACTERSET&#8217;;</p>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2010/05/28/oracle-nls-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick start for Java WebStart</title>
		<link>http://thelogic.org/blog/2010/04/08/quick-start-for-java-webstart/</link>
		<comments>http://thelogic.org/blog/2010/04/08/quick-start-for-java-webstart/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 08:02:56 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[webstart]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=158</guid>
		<description><![CDATA[1. Java Class TheTime.java

import java.awt.*;
import javax.swing.*;

public class TheTime {
  public static void main(String args[]) {
    JFrame frame =  new JFrame("Time Check");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel();
    Container content = frame.getContentPane();
    content.add(label, BorderLayout.CENTER);
    String message [...]]]></description>
			<content:encoded><![CDATA[<p>1. Java Class TheTime.java</p>
<pre lang=java>
import java.awt.*;
import javax.swing.*;

public class TheTime {
  public static void main(String args[]) {
    JFrame frame =  new JFrame("Time Check");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel label = new JLabel();
    Container content = frame.getContentPane();
    content.add(label, BorderLayout.CENTER);
    String message = "missing";
    message = "foo";
    label.setText(message);
    frame.pack();
    frame.show();
  }
</pre>
<p>javac TheTime.java<br />
java TheTime</p>
<p>2. Create a JAR</p>
<pre lang=java>
jar cf JNLPTime.jar TheTime.class
</pre lang=java>

3. Sign the JAR
<pre lang=java>
keytool -genkey -keystore myKeys -alias jdc
jarsigner -keystore myKeys JNLPTime.jar jdc
</pre>
<p>4. Create JNLP file:</p>
<pre lang=xml>
< ?xml version="1.0" encoding="UTF-8"?>
< jnlp spec="1.0+" codebase="file:///var/www/JavaWebStart/jnlp/" >
< information>
  < title>Time Check</title>
  < vendor>nf</vendor>
  < homepage href="http://www.google.de" />
  < description>desc</description>
< /information>
< offline-allowed/>
< security>
  < j2ee-application-client-permissions/>
< /security>
< resources>
  < j2se version="1.5+" />
  < jar href="JNLPTime.jar"/>
< /resources>
< application-desc main-class="TheTime" />
< /jnlp>
</pre>
<p>5. Create HTML link</p>
<pre lang=html>
 < a href=time.jnlp>Launch the application< /a>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2010/04/08/quick-start-for-java-webstart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending a message from a JSP/Servlet into JMS-Queue with GlassFish</title>
		<link>http://thelogic.org/blog/2010/02/11/sending-a-message-from-a-jspservlet-into-jms-queue-with-glassfish/</link>
		<comments>http://thelogic.org/blog/2010/02/11/sending-a-message-from-a-jspservlet-into-jms-queue-with-glassfish/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 14:19:00 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jms]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=153</guid>
		<description><![CDATA[1. Create Connection Factory and Destination Resource in GlassFish admin console:
Resources / JMS Resources / Connection Factory -> New
JNDI-Name: jms/myFactory
Resource-Type: javax.jms.ConnectionFactory
Additional Properties: Remove username and password
Resources / JMS Resources / Destination Resources -> New
JNDI-Name: jms/myQueue
Physical Destination Name: myQueue
Resource Type: javax.jms.Queue
2. Create a new web application in NetBeans, edit index.jsp:

       [...]]]></description>
			<content:encoded><![CDATA[<p>1. Create Connection Factory and Destination Resource in GlassFish admin console:</p>
<p>Resources / JMS Resources / Connection Factory -> New<br />
JNDI-Name: jms/myFactory<br />
Resource-Type: javax.jms.ConnectionFactory<br />
Additional Properties: Remove username and password</p>
<p>Resources / JMS Resources / Destination Resources -> New<br />
JNDI-Name: jms/myQueue<br />
Physical Destination Name: myQueue<br />
Resource Type: javax.jms.Queue</p>
<p>2. Create a new web application in NetBeans, edit index.jsp:</p>
<pre lang=Java line=1>
        < title>Send Message to JMS-Queue< /title>
        < form action="sendMessage">
            < table  cellspacing="20" >
                < tbody>
                    < tr>
                        < td>Message:< /td>
                        < td>< input type="text" name="message" value="" width="30" />< /td>
                    < /tr>
                < /tbody>
            < /table>
                < input type="submit" value="Send The message" name="send" />
        < /form>
</pre>
<p>3. Create new Servlet sendMessage in web application:</p>
<pre lang=Java line=1>
package dummy;
import java.io.*;
import javax.jms.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class sendMessage extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try{
            Context ctx = new InitialContext();
            ConnectionFactory connectionFactory = (ConnectionFactory)ctx.lookup("jms/myFactory");
            Queue queue = (Queue)ctx.lookup("jms/myQueue");
            javax.jms.Connection connection = connectionFactory.createConnection();
            javax.jms.Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
            MessageProducer messageProducer = session.createProducer(queue);
            TextMessage message = session.createTextMessage();
            message.setText(request.getParameter("message"));
            messageProducer.send(message);
            out.println("<html>");
            out.println("<head>");
            out.println("");
            out.println("</head>");
            out.println("<body>");
            out.println("<center>");
            out.print("Message " + request.getParameter("message") + " sent to Queue " + queue.getQueueName() +".");
            out.println("</center>");
            out.println("</body>");
            out.println("</html>");
        } catch(Exception ex){
            ex.printStackTrace();
        }
        out.close();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2010/02/11/sending-a-message-from-a-jspservlet-into-jms-queue-with-glassfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Eclipse installation with viPlugin, GlassFish, Derby</title>
		<link>http://thelogic.org/blog/2010/02/09/new-eclipse-installation-with-viplugin-glassfish-derby/</link>
		<comments>http://thelogic.org/blog/2010/02/09/new-eclipse-installation-with-viplugin-glassfish-derby/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 15:16:45 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[derby]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[viplugin]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=151</guid>
		<description><![CDATA[1. viPlugin
Name: viPlugin
Site: viplugin.com
2. GlassFish
Plugin Site: http://ajax.dev.java.net/eclipse
GlassFish download: https://glassfish.dev.java.net/downloads/v3-final.html
Servers / New Server / GlassFish v3
Preferences / GlassFish -> start Derby with GlassFish
3. Derby
http://db.apache.org/derby/derby_downloads.html (core &#038; ui) into eclipse/plugins
Data Source Explorer / Database Connections -> New -> Derby
New Driver Definition / Derby Client JDBC Driver
]]></description>
			<content:encoded><![CDATA[<p>1. viPlugin<br />
Name: viPlugin<br />
Site: viplugin.com</p>
<p>2. GlassFish<br />
Plugin Site: http://ajax.dev.java.net/eclipse<br />
GlassFish download: https://glassfish.dev.java.net/downloads/v3-final.html<br />
Servers / New Server / GlassFish v3<br />
Preferences / GlassFish -> start Derby with GlassFish</p>
<p>3. Derby<br />
http://db.apache.org/derby/derby_downloads.html (core &#038; ui) into eclipse/plugins<br />
Data Source Explorer / Database Connections -> New -> Derby<br />
New Driver Definition / Derby Client JDBC Driver</p>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2010/02/09/new-eclipse-installation-with-viplugin-glassfish-derby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing / Appending a File in Java</title>
		<link>http://thelogic.org/blog/2010/01/12/writing-appending-a-file-in-java/</link>
		<comments>http://thelogic.org/blog/2010/01/12/writing-appending-a-file-in-java/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:09:46 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[append]]></category>
		<category><![CDATA[datei]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[write]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=141</guid>
		<description><![CDATA[
try {
  BufferedWriter writer = new BufferedWriter(new FileWriter("file.txt", true));  // true defines append to file instead of overwrite
  writer.write("text into file" + "\n");
  writer.close();
} catch (Exception e) {
  System.out.println(e.getMessage());
}

]]></description>
			<content:encoded><![CDATA[<pre lang=Java line=1>
try {
  BufferedWriter writer = new BufferedWriter(new FileWriter("file.txt", true));  // true defines append to file instead of overwrite
  writer.write("text into file" + "\n");
  writer.close();
} catch (Exception e) {
  System.out.println(e.getMessage());
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2010/01/12/writing-appending-a-file-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date and Time in Java</title>
		<link>http://thelogic.org/blog/2010/01/12/date-and-time-in-java/</link>
		<comments>http://thelogic.org/blog/2010/01/12/date-and-time-in-java/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:07:31 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=137</guid>
		<description><![CDATA[

import java.util.*;
import java.text.*;

// actual date and time
Date d = new Date();
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = f.format(d));

// other time zone
df.setTimeZone(TimeZone.getTimeZone("America/New_York");
String nowNY = f.format(d));

]]></description>
			<content:encoded><![CDATA[<pre lang=Java line=1>

import java.util.*;
import java.text.*;

// actual date and time
Date d = new Date();
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = f.format(d));

// other time zone
df.setTimeZone(TimeZone.getTimeZone("America/New_York");
String nowNY = f.format(d));
</pre>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2010/01/12/date-and-time-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML: SAX or DOM?</title>
		<link>http://thelogic.org/blog/2009/09/22/xml-sax-or-dom/</link>
		<comments>http://thelogic.org/blog/2009/09/22/xml-sax-or-dom/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 11:25:54 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[SAX]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=135</guid>
		<description><![CDATA[There are some differences between the SAX and DOM XML parser. The main difference in one sentence are:
1. SAX reads the XML document once and can react on events but it won&#8217;t save the XML structure in memory.
2. DOM reads the XML document and stores it in a tree which allows manipulation or to extract [...]]]></description>
			<content:encoded><![CDATA[<p>There are some differences between the SAX and DOM XML parser. The main difference in one sentence are:</p>
<p>1. SAX reads the XML document once and can react on events but it won&#8217;t save the XML structure in memory.</p>
<p>2. DOM reads the XML document and stores it in a tree which allows manipulation or to extract information from the XML document more than once.</p>
<p>SAX is easy and fast, DOM builds a tree and allows manipulation.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2009/09/22/xml-sax-or-dom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining the type of a file using the extension</title>
		<link>http://thelogic.org/blog/2009/08/06/determining-the-type-of-a-file-using-the-extension/</link>
		<comments>http://thelogic.org/blog/2009/08/06/determining-the-type-of-a-file-using-the-extension/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 09:05:49 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=132</guid>
		<description><![CDATA[This is how the type of a file can be determined using the extension of the file:

1
2
3
4
5
6
7
8
9
10
public class FileType &#123;
	public static void main&#40;String&#91;&#93; args&#41; &#123;
		String fileName = &#34;foo.pdf&#34;;
		String extension = fileName.substring&#40;fileName.lastIndexOf&#40;&#34;.&#34;&#41;&#41;;
		System.out.println&#40;&#34;Extension: &#34; + extension&#41;;
		if &#40;fileName.equalsIgnoreCase&#40;&#34;.pdf&#34;&#41;&#41; &#123;
			System.out.println&#40;&#34;It is a PDF-File.&#34;&#41;;
		&#125;
	&#125;
&#125;

]]></description>
			<content:encoded><![CDATA[<p>This is how the type of a file can be determined using the extension of the file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FileType <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> fileName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;foo.pdf&quot;</span>;
		<span style="color: #003399;">String</span> extension <span style="color: #339933;">=</span> fileName.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>fileName.<span style="color: #006633;">lastIndexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Extension: &quot;</span> <span style="color: #339933;">+</span> extension<span style="color: #009900;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fileName.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;It is a PDF-File.&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2009/08/06/determining-the-type-of-a-file-using-the-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSL-encrypted Client/Server connection in Java</title>
		<link>http://thelogic.org/blog/2009/05/06/ssl-encrypted-clientserver-connection-in-java/</link>
		<comments>http://thelogic.org/blog/2009/05/06/ssl-encrypted-clientserver-connection-in-java/#comments</comments>
		<pubDate>Wed, 06 May 2009 14:46:32 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=130</guid>
		<description><![CDATA[1. Generating a key pair (public key + private key) for the server and store those as certificate in the keystore &#8220;ServerKeystore&#8221;

keytool -genkey -keystore ServerKeystore -alias SSLCertificate -keyalg RSA -validity 360

2. Export the public key of the server and import it into the keystore &#8220;ClientKeystore&#8221;

keytool -keystore ServerKeystore -export -alias ServerKeystore -file ServerCertificate.crt
keytool -keystore ClientKeystore -import [...]]]></description>
			<content:encoded><![CDATA[<p>1. Generating a key pair (public key + private key) for the server and store those as certificate in the keystore &#8220;ServerKeystore&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">keytool <span style="color: #660033;">-genkey</span> <span style="color: #660033;">-keystore</span> ServerKeystore <span style="color: #660033;">-alias</span> SSLCertificate <span style="color: #660033;">-keyalg</span> RSA <span style="color: #660033;">-validity</span> <span style="color: #000000;">360</span></pre></div></div>

<p>2. Export the public key of the server and import it into the keystore &#8220;ClientKeystore&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">keytool <span style="color: #660033;">-keystore</span> ServerKeystore <span style="color: #660033;">-export</span> <span style="color: #660033;">-alias</span> ServerKeystore <span style="color: #660033;">-file</span> ServerCertificate.crt
keytool <span style="color: #660033;">-keystore</span> ClientKeystore <span style="color: #660033;">-import</span> <span style="color: #660033;">-file</span> ServerCertificate.cer</pre></div></div>

<p>3. List the contents of the two keystores</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">keytool <span style="color: #660033;">-list</span> <span style="color: #660033;">-keystore</span> ServerKeystore <span style="color: #660033;">-v</span>
keytool <span style="color: #660033;">-list</span> <span style="color: #660033;">-keystore</span> ClientKeystore <span style="color: #660033;">-v</span></pre></div></div>

<p>4. Generate the Java class for the SSLServer</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.OutputStream</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Scanner</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.concurrent.ExecutorService</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.concurrent.Executors</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLServerSocket</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLServerSocketFactory</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLSocket</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SSLServer <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Runnable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		ExecutorService executor <span style="color: #339933;">=</span> Executors.<span style="color: #006633;">newSingleThreadExecutor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
		executor.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SSLServer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Server started on port 7777&quot;</span><span style="color: #009900;">&#41;</span>;
		executor.<span style="color: #006633;">shutdown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// create a server socket and listen on it</span>
			SSLServerSocket serverSocket <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SSLServerSocket<span style="color: #009900;">&#41;</span> SSLServerSocketFactory
					.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createServerSocket</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">7777</span><span style="color: #009900;">&#41;</span>;
			SSLSocket server <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SSLSocket<span style="color: #009900;">&#41;</span> serverSocket.<span style="color: #006633;">accept</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
			<span style="color: #666666; font-style: italic;">// input and output stream</span>
			<span style="color: #003399;">InputStream</span> in <span style="color: #339933;">=</span> server.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #003399;">OutputStream</span> out <span style="color: #339933;">=</span> server.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
			<span style="color: #666666; font-style: italic;">// receive data from client and echo it back</span>
			Scanner scanner <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Scanner<span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span>;
			<span style="color: #003399;">PrintWriter</span> printWriter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">PrintWriter</span><span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span>;
			<span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span>;
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>scanner.<span style="color: #006633;">hasNextLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				line <span style="color: #339933;">=</span> scanner.<span style="color: #006633;">nextLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Server received: &quot;</span> <span style="color: #339933;">+</span> line<span style="color: #009900;">&#41;</span>;
				printWriter.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span>;
				printWriter.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
			scanner.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			server.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			serverSocket.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>5. Generate the Java class for the SSLClient</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.OutputStream</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLSocket</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.net.ssl.SSLSocketFactory</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SSLClient <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// create a client socket and connect to server</span>
			SSLSocket client <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SSLSocket<span style="color: #009900;">&#41;</span> SSLSocketFactory.<span style="color: #006633;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #006633;">createSocket</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span>, <span style="color: #cc66cc;">7777</span><span style="color: #009900;">&#41;</span>;
&nbsp;
			<span style="color: #666666; font-style: italic;">// output stream to server</span>
			<span style="color: #003399;">OutputStream</span> out <span style="color: #339933;">=</span> client.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
			<span style="color: #666666; font-style: italic;">// input stream for user input</span>
			<span style="color: #003399;">InputStream</span> in <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">in</span>;
			<span style="color: #003399;">InputStreamReader</span> reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span>;
			<span style="color: #003399;">BufferedReader</span> breader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>reader<span style="color: #009900;">&#41;</span>;
&nbsp;
			<span style="color: #666666; font-style: italic;">// send data to server</span>
			<span style="color: #003399;">PrintWriter</span> printWriter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">PrintWriter</span><span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span>;
			<span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span>;
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> breader.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				printWriter.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span>;
				printWriter.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>6. Run the SSLServer and SSLClient classes with the following JRE parameters</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">SSLServer<span style="color: #339933;">:</span> <span style="color: #339933;">-</span>Djavax.<span style="color: #006633;">net</span>.<span style="color: #006633;">debug</span><span style="color: #339933;">=</span>all <span style="color: #339933;">-</span>Djavax.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">keyStore</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/path/to/ServerKeystore&quot;</span>  <span style="color: #339933;">-</span>Djavax.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">keyStorePassword</span><span style="color: #339933;">=</span>serverKeystorePassword</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">SSLClient<span style="color: #339933;">:</span> <span style="color: #339933;">-</span>Djavax.<span style="color: #006633;">net</span>.<span style="color: #006633;">debug</span><span style="color: #339933;">=</span>all <span style="color: #339933;">-</span>Djavax.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">trustStore</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/path/to/ClientKeystore&quot;</span> <span style="color: #339933;">-</span>Djavax.<span style="color: #006633;">net</span>.<span style="color: #006633;">ssl</span>.<span style="color: #006633;">trustStorePassword</span><span style="color: #339933;">=</span>clientKeystorePassword</pre></div></div>

<p>Using -Djavax.net.debug=all as additional JRE parameter will print some debug information.</p>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2009/05/06/ssl-encrypted-clientserver-connection-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encrypt USB-stick on Ubuntu in three steps</title>
		<link>http://thelogic.org/blog/2009/05/02/encrypt-usb-stick-on-ubuntu-in-three-steps/</link>
		<comments>http://thelogic.org/blog/2009/05/02/encrypt-usb-stick-on-ubuntu-in-three-steps/#comments</comments>
		<pubDate>Sat, 02 May 2009 21:13:28 +0000</pubDate>
		<dc:creator>Frank Niedermann</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[usb-stick]]></category>

		<guid isPermaLink="false">http://thelogic.org/blog/?p=118</guid>
		<description><![CDATA[1. Install the required package:

sudo apt-get install cryptsetup

2. Create a partition on the USB-stick:

sudo cfdisk /dev/sdX

3. Encrypt the partition:

sudo luksformat -t ext2 /dev/sdX
Creating encrypted device on /dev/sdX...
Are you sure? &#40;Type uppercase yes&#41;: YES
Enter LUKS passphrase:

Entering the USB-stick into Ubuntu will bring up the following window:

To edit the label of the USB-stick (by default it&#8217;s just [...]]]></description>
			<content:encoded><![CDATA[<p>1. Install the required package:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> cryptsetup</pre></div></div>

<p>2. Create a partition on the USB-stick:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> cfdisk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdX</pre></div></div>

<p>3. Encrypt the partition:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> luksformat <span style="color: #660033;">-t</span> ext2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdX
Creating encrypted device on <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdX...
Are you sure? <span style="color: #7a0874; font-weight: bold;">&#40;</span>Type uppercase <span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: YES
Enter LUKS passphrase:</pre></div></div>

<p>Entering the USB-stick into Ubuntu will bring up the following window:<br />
<img src="http://thelogic.org/blog/wp-content/uploads/2009/05/unlockencryptedusbstick.png" alt="unlockencryptedusbstick" title="unlockencryptedusbstick" width="360" height="251" class="aligncenter size-full wp-image-119" /></p>
<p>To edit the label of the USB-stick (by default it&#8217;s just &#8216;disk&#8217;) use e2label for ext filesystems and mtools for fat filesystems. Details: https://help.ubuntu.com/community/RenameUSBDrive</p>
]]></content:encoded>
			<wfw:commentRss>http://thelogic.org/blog/2009/05/02/encrypt-usb-stick-on-ubuntu-in-three-steps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
