<?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/"
	>

<channel>
	<title>CLaY's Notes</title>
	<atom:link href="http://www.vinclay.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vinclay.com</link>
	<description>A Place to store my Notes</description>
	<pubDate>Fri, 20 Nov 2009 12:48:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Simple Example of creating a Scheduled Job using Spring and Quartz</title>
		<link>http://www.vinclay.com/2009/11/20/a-simple-example-of-creating-a-scheduled-job-using-spring-and-quartz/</link>
		<comments>http://www.vinclay.com/2009/11/20/a-simple-example-of-creating-a-scheduled-job-using-spring-and-quartz/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 12:43:33 +0000</pubDate>
		<dc:creator>vinclay</dc:creator>
		
		<category><![CDATA[IT Stuff]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.vinclay.com/?p=103</guid>
		<description><![CDATA[This example use the MethodInvokingJobDetailFactoryBean

Required Jars:

spring-core.jar
spring-beans.jar
spring-context.jar
spring-context-support.jar
spring-tx.jar
quartz-1.5.2.jar


Create the class that you want to be executed by the job (this should be your bussiness object)
package com.scheduler.job;

public class Jobs {
	public void processSomething(){
		System.out.println("execute processSomething()");
	}
}


Create the spring quartz configuration and import the file on your application context configuration
&#60;?xml version="1.0" encoding="UTF-8"?&#62;
&#60;beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&#62;

	&#60;!-- Create bean of Jobs object --&#62;
	&#60;bean id="jobs" class="com.scheduler.job.Jobs"/&#62;

	&#60;!-- Create [...]]]></description>
			<content:encoded><![CDATA[<p>This example use the <strong>MethodInvokingJobDetailFactoryBean</strong><br />
<strong></strong></p>
<p><strong>Required Jars:</strong></p>
<ul>
<li>spring-core.jar</li>
<li>spring-beans.jar</li>
<li>spring-context.jar</li>
<li>spring-context-support.jar</li>
<li>spring-tx.jar</li>
<li>quartz-1.5.2.jar</li>
</ul>
<p><strong></strong></p>
<p><strong>Create the class that you want to be executed by the job (this should be your bussiness object)</strong></p>
<pre>package <span style="color: #993300;">com.scheduler.job</span>;

public class <span style="color: #ff6600;">Jobs </span>{
	public void <span style="color: #0000ff;">processSomething</span>(){
		System.out.println("execute processSomething()");
	}
}</pre>
<p><strong></strong></p>
<p><span id="more-103"></span></p>
<p><strong>Create the spring quartz configuration and import the file on your application context configuration</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

	&lt;!-- Create bean of Jobs object --&gt;
	&lt;bean id="<span style="color: #ff0000;">jobs</span>" class="<span style="color: #993300;">com.scheduler.job</span>.<span style="color: #ff6600;">Jobs</span>"/&gt;

	&lt;!-- Create the Jobs Detail using Method Invocation --&gt;
	&lt;bean id="<span style="color: #339966;">doJob</span>" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;
	  &lt;property name="targetObject" ref="<span style="color: #ff0000;">jobs</span>" /&gt;
	  &lt;property name="targetMethod" value="<span style="color: #0000ff;">processSomething</span>" /&gt;
	  &lt;property name="concurrent" value="false" /&gt;
	&lt;/bean&gt;

	&lt;!-- Create the trigger for the Job (doJob) --&gt;
	&lt;bean id="<span style="color: #800080;">theTrigger</span>" class="org.springframework.scheduling.quartz.SimpleTriggerBean"&gt;
		&lt;property name="jobDetail" ref="<span style="color: #339966;">doJob</span>" /&gt;
		&lt;property name="startDelay" value="1000" /&gt;
		&lt;property name="repeatInterval" value="5000" /&gt;
	&lt;/bean&gt;

	&lt;!-- This is an example triger using cron expression --&gt;
	&lt;!--
	&lt;bean id="<span style="color: #000000;">theTrigger</span>" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;
		&lt;property name="jobDetail" ref="doJob" /&gt;
		&lt;property name="cronExpression" value="0 59 23 * * ?"/&gt;
	&lt;/bean&gt;
	--&gt;

	&lt;!-- Add the triggers to SchedulerFactoryBean --&gt;
	&lt;bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;
		&lt;property name="triggers"&gt;
			&lt;list&gt;
				&lt;ref bean="<span style="color: #800080;">theTrigger</span>" /&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

&lt;/beans&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/11/20/a-simple-example-of-creating-a-scheduled-job-using-spring-and-quartz/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Spring Web Mvc with Annotation</title>
		<link>http://www.vinclay.com/2009/11/20/spring-web-mvc-with-annotation/</link>
		<comments>http://www.vinclay.com/2009/11/20/spring-web-mvc-with-annotation/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 09:58:37 +0000</pubDate>
		<dc:creator>vinclay</dc:creator>
		
		<category><![CDATA[IT Stuff]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.vinclay.com/?p=89</guid>
		<description><![CDATA[Required Jars:

spring-core.jar
spring-beans.jar
spring-web.jar
spring-webmvc.jar
spring-context.jar


Configuration on WEB.XML :
&#60;?xml version="1.0" encoding="UTF-8"?&#62;
&#60;web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&#62;

    &#60;display-name&#62;App Name&#60;/display-name&#62;

    &#60;servlet&#62;
        &#60;servlet-name&#62;app-name&#60;/servlet-name&#62;
        &#60;servlet-class&#62;
            org.springframework.web.servlet.DispatcherServlet
        &#60;/servlet-class&#62;
        &#60;load-on-startup&#62;1&#60;/load-on-startup&#62;
    &#60;/servlet&#62;
    &#60;servlet-mapping&#62;
        &#60;servlet-name&#62;app-name&#60;/servlet-name&#62;
        &#60;url-pattern&#62;/service/*&#60;/url-pattern&#62;
    &#60;/servlet-mapping&#62;

&#60;/web-app&#62;


Configuration Servlet Context &#8220;app-name-servlet.xml&#8221;, put it on WEB-INF/:
&#60;?xml version="1.0" encoding="UTF-8"?&#62;
&#60;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
           [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Required Jars:</strong></p>
<ul>
<li>spring-core.jar</li>
<li>spring-beans.jar</li>
<li>spring-web.jar</li>
<li>spring-webmvc.jar</li>
<li>spring-context.jar</li>
</ul>
<p><strong><br />
Configuration on WEB.XML :</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;

    &lt;display-name&gt;App Name&lt;/display-name&gt;

    &lt;servlet&gt;
        &lt;servlet-name&gt;<span style="color: #993300;">app-name</span>&lt;/servlet-name&gt;
        &lt;servlet-class&gt;
            org.springframework.web.servlet.DispatcherServlet
        &lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;<span style="color: #993300;">app-name</span>&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/<span style="color: #800080;">service</span>/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

&lt;/web-app&gt;</pre>
<p><span id="more-89"></span></p>
<p><strong><br />
Configuration Servlet Context &#8220;<span style="color: #993300;">app-name</span>-servlet.xml&#8221;, put it on WEB-INF/:</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;

    &lt;!--Enable Spring Annotation--&gt;
    &lt;context:annotation-config/&gt;
    &lt;context:component-scan base-package="<span style="color: #ff6600;">com.springmvc</span>"/&gt;

    &lt;!--Resolver--&gt;
    &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
        &lt;property name="cache" value="true"/&gt;
        &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt;
        &lt;property name="prefix" value="/WEB-INF/pages/"/&gt;
        &lt;property name="suffix" value=".jsp"/&gt;
    &lt;/bean&gt;

&lt;/beans&gt;</pre>
<p><strong><br />
The Controller Class:</strong></p>
<pre>package <span style="color: #ff6600;">com.springmvc</span>.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class TheController{

    @RequestMapping(value = "<span style="color: #339966;">/helloworld</span>", method = RequestMethod.GET)
    public String helloWorld(){
        return "<span style="color: #ff0000;">hello_world</span>";
    }
}</pre>
<p><strong><br />
The page &#8220;<span style="color: #ff0000;">hello_world</span>.jsp&#8221;, put it on WEB-INF/pages/:</strong></p>
<pre>&lt;html&gt;
	&lt;head&gt;
	&lt;title&gt;Test Spring Web Mvc with Annotation&lt;/title&gt;
	&lt;/head&gt;

	&lt;body&gt;
		Hello World
	&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Convert to war and deploy on your tomcat and then access it on your browser:<br />
<span style="color: #0000ff;">http://yourhost/app-name/<span style="color: #800080;">service</span><span style="color: #339966;">/helloworld</span></span></p>
<p><strong>Other things that we can do on Controller :</strong></p>
<pre>package <span style="color: #ff6600;">com.springmvc</span>.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class TheController{
@RequestMapping(value = "/helloworld", method = RequestMethod.GET)
	public String helloWorld() {
		return "hello_world";
	}

	<span style="color: #808080;">/* USING HttpServletResponse */</span>
	@RequestMapping(value = "/servletresponse", method = RequestMethod.GET)
	public void testServletResponse(final HttpServletResponse response) throws IOException {
		PrintWriter out = response.getWriter();
		out.print("Hello, this use response print writer");
	}

	<span style="color: #808080;">/* USING HttpServletRequest */</span>
	@RequestMapping(value = "/servletrequest", method = RequestMethod.GET)
	public void testServletRequest(final HttpServletRequest request, final HttpServletResponse response) throws IOException{
		PrintWriter out = response.getWriter();

		String name = request.getParameter("name");

		out.print("Hello "+name+", test using HttpServletRequest");
	}

	<span style="color: #808080;">/* USING @SpringParam Required*/</span>
	@RequestMapping(value = "/spring-param-required", method = RequestMethod.GET)
	public void testSpringParamRequired(@RequestParam(value="name") String name, final HttpServletResponse response) throws IOException{
		PrintWriter out = response.getWriter();
		out.print("Hello "+name+", test using @SpringParam Required");
	}

	<span style="color: #808080;">/* USING @SpringParam NOT Required*/</span>
	@RequestMapping(value = "/spring-param-notrequired", method = RequestMethod.GET)
	public void testSpringParamNotRequired(@RequestParam(value="name", required=false) String name, final HttpServletResponse response) throws IOException{
		PrintWriter out = response.getWriter();
		out.print("Hello "+name+", test using @SpringParam Not Required");
	}

	<span style="color: #808080;">/* USING MODEL and EL
	 * note: you need to create "<span style="color: #ff0000;">test_model</span>.jsp" on WEB-INF/pages:
	 &lt;html&gt;
		&lt;head&gt;
			&lt;title&gt;Test Spring Web Mvc with Annotation&lt;/title&gt;
		&lt;/head&gt;

		&lt;body&gt;
			Hello ${<span style="color: #008000;">thename</span>}, this page is using model
		&lt;/body&gt;
	 &lt;/html&gt;
	 */</span>
	@RequestMapping(value = "/usemodel", method = RequestMethod.GET)
	public String testModel(Model model, @RequestParam(value="name") String name){
		model.addAttribute("<span style="color: #008000;">thename</span>", name);
		return "<span style="color: #ff0000;">test_model</span>";
	}

	<span style="color: #808080;">/* USING MODEL and JSTL
	 * note: you need to create "<span style="color: #ff00ff;">test_model_jstl</span>.jsp" on WEB-INF/pages:
	 &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
	 &lt;html&gt;
		&lt;head&gt;
			&lt;title&gt;Test Spring Web Mvc with Annotation&lt;/title&gt;
		&lt;/head&gt;

		&lt;body&gt;
			Hello ${<span style="color: #008000;">thename</span>}, this page is using model &lt;br&gt;
			And this is some list generated on controller:
			&lt;c:forEach var="values" items="${<span style="color: #008000;">thelist</span>}"&gt;
		 		&lt;br&gt; ${values}
			&lt;/c:forEach&gt;
		&lt;/body&gt;
	 &lt;/html&gt;
	 */</span>
	@RequestMapping(value = "/usemodel-n-jstl", method = RequestMethod.GET)
	public String testModelnJstl(Model model, @RequestParam(value="name") String name){
		List list = new ArrayList();
		list.add("value 01");
		list.add("value 02");
		list.add("value 03");
		model.addAttribute("<span style="color: #008000;">thelist</span>", list);
		model.addAttribute("<span style="color: #008000;">thename</span>", name);
		return "<span style="color: #ff00ff;">test_model_jstl</span>";
	}
}</pre>
<p><strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/11/20/spring-web-mvc-with-annotation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Send and receive encrypted data between PHP and JAVA. part 2</title>
		<link>http://www.vinclay.com/2009/06/26/send-and-receive-encrypted-data-between-php-and-java-part-2/</link>
		<comments>http://www.vinclay.com/2009/06/26/send-and-receive-encrypted-data-between-php-and-java-part-2/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 10:18:27 +0000</pubDate>
		<dc:creator>vinclay</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[encryption]]></category>

		<guid isPermaLink="false">http://www.vinclay.com/?p=69</guid>
		<description><![CDATA[previous post: Send and receive encrypted data between PHP and JAVA. part 1
Part2. Using public and private key to encrypt and decrypt data
Encrypt Decrypt using public and private key is called Asynchronus Encryption, which mean the key used to encrypt is different from the key used to decrypt, but both keys must be a pairs [...]]]></description>
			<content:encoded><![CDATA[<p>previous post: <a rel="bookmark" href="http://www.vinclay.com/2009/06/25/send-and-receive-encrypted-data-between-php-and-java-part-1/" title="Send and receive encrypted data between PHP and JAVA. part 1">Send and receive encrypted data between PHP and JAVA. part 1</a></p>
<h2>Part2. Using public and private key to encrypt and decrypt data</h2>
<p>Encrypt Decrypt using public and private key is called Asynchronus Encryption, which mean the key used to encrypt is different from the key used to decrypt, but both keys must be a pairs so they match to each other.<br />
The point is, when we encrypt a message using a private key, so we only can decrypt that message with its public key, and when we encrypt a message using a public key, so we only can decrypt that message with its private key.<br />
To create a private key and public key you can read my other article <a rel="bookmark" href="http://www.vinclay.com/2009/03/04/common-ssl-commands/" title="Common SSL Commands">Common SSL Commands</a><br />
<span id="more-69"></span></p>
<h3>Encrypt message using Private Key and then Decrypt it using Public Key (JAVA)</h3>
<p><strong>Encrypt a message using Private Key</strong></p>
<pre><span style="color: #808080;">//-------------------- Get the private key (DER format) --------------------</span>
KeyFactory keyFactory;
PrivateKey privateKey = null;
File privKeyFile = new File("<span style="color: #ff0000;">/path_to/privatekey.der</span>");

<span style="color: #808080;">// read private key DER file</span>
DataInputStream dis;
try {
    dis = new DataInputStream(new FileInputStream(privKeyFile));
    byte[] privKeyBytes = new byte[(int) privKeyFile.length()];
    dis.read(privKeyBytes);
    dis.close();
    keyFactory = KeyFactory.getInstance("<span style="color: #ff0000;">RSA</span>");
    // decode private key
    PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(privKeyBytes);
    privateKey = (PrivateKey) keyFactory.generatePrivate(privSpec);
} catch (Exception e) {
    e.printStackTrace();
}

<span style="color: #808080;">// -------------------- Encryption using the private key --------------------</span>
BASE64Encoder encoder = new BASE64Encoder();
Cipher privateChiper = null;
byte[] encrypted = null;
String encryptedText = null;
String plaintext =  "<span style="color: #008000;">This is the message that we want to encrypt with private key on java</span>";
try {
    privateChiper = Cipher.getInstance("<span style="color: #ff0000;">RSA</span>");
    privateChiper.init(Cipher.<span style="color: #ff0000;">ENCRYPT_MODE</span>, privateKey);
    encrypted =  privateChiper.doFinal(plaintext.getBytes());
    encryptedText = encoder.encode(encrypted);
} catch (Exception e) {
    e.printStackTrace();
}

System.out.println(encryptedText);
<span style="color: #808080;">//output:
//<span style="color: #ff6600;">HNDERrUmko0gqwzeW4XUWIIeds8FaW0eKH9qO4DkI7eq2DSPBCKjnxsggSBvTU4AHtroOrVbl39M42tJFjRHN19iG7osda4Y0vWBNlPnsSxfSLipeypMIktqbIQnl5uarZXtqi/PDQNzC7HNTns508fXHax8cLIqE6J6aWmsD9M=</span>
</span></pre>
<p><strong>Decrypt the encrypted message from above script using Public Key</strong></p>
<pre><span style="color: #808080;">// -------------------- Get the public key --------------------</span>
BASE64Decoder decoder = new BASE64Decoder();
FileInputStream is;
CertificateFactory cf;
PublicKey publicKey = null;
try {
    is = new FileInputStream("<span style="color: #ff0000;">/path_to/publickey.crt</span>");
    cf = CertificateFactory.getInstance("<span style="color: #ff0000;">X.509</span>");
    Certificate cert = cf.generateCertificate(is);
    publicKey = cert.getPublicKey();
} catch (Exception e) {
    e.printStackTrace();
} 

<span style="color: #808080;">// -------------------- Decryption using the public key --------------------
</span>Cipher publicChiper = null;
String decryptedText = null;
String cryptedText = "<span style="color: #ff6600;">HNDERrUmko0gqwzeW4XUWIIeds8FaW0eKH9qO4DkI7eq2DSPBCKjnxsggSBvTU4AHtroOrVbl39M42tJFjRHN19iG7osda4Y0vWBNlPnsSxfSLipeypMIktqbIQnl5uarZXtqi/PDQNzC7HNTns508fXHax8cLIqE6J6aWmsD9M=</span>";
try {
    publicChiper = Cipher.getInstance("<span style="color: #ff0000;">RSA</span>");
    publicChiper.init(Cipher.<span style="color: #ff0000;">DECRYPT_MODE</span>, publicKey);
    byte[] decodedMessage = decoder.decodeBuffer(cryptedText);
    byte[] decrypted = publicChiper.doFinal(decodedMessage);
    decryptedText =  new String(decrypted);
} catch (Exception e) {
    e.printStackTrace();
}

System.out.println(decryptedText);
<span style="color: #808080;">// output: <span style="color: #008000;">This is the message that we want to encrypt with private key on java</span></span></pre>
<p>&nbsp;</p>
<h3>Encrypt message using Public Key and then Decrypt it using Private Key (JAVA)</h3>
<p><strong>Encrypt a message using Public Key</strong></p>
<pre><span style="color: #808080;">// -------------------- Get the public key --------------------</span>
FileInputStream is;
CertificateFactory cf;
PublicKey publicKey = null;
try {
    is = new FileInputStream("<span style="color: #ff0000;">/path_to/publickey.crt</span>");
    cf = CertificateFactory.getInstance("<span style="color: #ff0000;">X.509</span>");
    Certificate cert = cf.generateCertificate(is);
    publicKey = cert.getPublicKey();
} catch (Exception e) {
    e.printStackTrace();
} 

<span style="color: #808080;">// -------------------- Encryption using the public key --------------------</span>
BASE64Encoder encoder = new BASE64Encoder();
Cipher publicChiper = null;
byte[] encrypted = null;
String encryptedText = null;
String plaintext =  "<span style="color: #008000;">This is the message that we want to encrypt with public key on java</span>";
try {
    publicChiper = Cipher.getInstance("<span style="color: #ff0000;">RSA</span>");
    publicChiper.init(Cipher.<span style="color: #ff0000;">ENCRYPT_MODE</span>, publicKey);
    encrypted =  publicChiper.doFinal(plaintext.getBytes());
    encryptedText = encoder.encode(encrypted);
} catch (Exception e) {
    e.printStackTrace();
}
System.out.println(encryptedText);
<span style="color: #808080;">//output:
//<span style="color: #ff6600;">EFB5fOc0vP30+v3lIHrtuuNgyWu+4tYjLBBN4VEY+YPqMGA4CM+jJLfXfSHbWXUEacQ5KsVzliQLh5GB/u14qmNBqlE5WlhY8XMdCW3jbXo6NFk89cPE2HveRVeIQNb5UU7ogBwcBcvR2scmqcBzbP6Z2Ixf0NFjQWEpwOwj+bw=</span>
</span></pre>
<p><strong>Decrypt the encrypted message from above script using Private Key</strong></p>
<pre><span style="color: #808080;">//-------------------- Get the private key (DER format) --------------------</span>
KeyFactory keyFactory;
PrivateKey privateKey = null;
File privKeyFile = new File("<span style="color: #ff0000;">/path_to/privatekey.der</span>");

<span style="color: #808080;">// read private key DER file</span>
DataInputStream dis;
try {
    dis = new DataInputStream(new FileInputStream(privKeyFile));
    byte[] privKeyBytes = new byte[(int) privKeyFile.length()];
    dis.read(privKeyBytes);
    dis.close();
    keyFactory = KeyFactory.getInstance("<span style="color: #ff0000;">RSA</span>");
    // decode private key
    PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(privKeyBytes);
    privateKey = (PrivateKey) keyFactory.generatePrivate(privSpec);
} catch (Exception e) {
    e.printStackTrace();
}

<span style="color: #808080;">// -------------------- Decryption using the private key --------------------</span>
BASE64Decoder decoder = new BASE64Decoder();
Cipher privateChiper = null;
String decryptedText = null;
String cryptedText = "<span style="color: #ff6600;">EFB5fOc0vP30+v3lIHrtuuNgyWu+4tYjLBBN4VEY+YPqMGA4CM+jJLfXfSHbWXUEacQ5KsVzliQLh5GB/u14qmNBqlE5WlhY8XMdCW3jbXo6NFk89cPE2HveRVeIQNb5UU7ogBwcBcvR2scmqcBzbP6Z2Ixf0NFjQWEpwOwj+bw=</span>";
try {
    privateChiper = Cipher.getInstance("<span style="color: #ff0000;">RSA</span>");
    privateChiper.init(Cipher.<span style="color: #ff0000;">DECRYPT_MODE</span>, privateKey);
    byte[] decodedMessage = decoder.decodeBuffer(cryptedText);
    byte[] decrypted = privateChiper.doFinal(decodedMessage);
    decryptedText =  new String(decrypted);
} catch (Exception e) {
    e.printStackTrace();
}

System.out.println(decryptedText);
<span style="color: #808080;">// output: <span style="color: #008000;">This is the message that we want to encrypt with public key on java</span></span></pre>
<p>&nbsp;</p>
<h3>Encrypt message using Private Key and then Decrypt it using Public Key (PHP)</h3>
<p><strong>Encrypt a message using Private Key</strong></p>
<pre><span style="color: #808080;">// Get the private key</span>
$private_key_file = "<span style="color: #ff0000;">/path_to/privatekey.key</span>";
$private_key_passphrase = "<span style="color: #ff0000;">the_key_pasphrase</span>";
$handle = fopen($private_key_file, "r");
$content = fread($handle, filesize($private_key_file));
fclose($handle);
$privateKey = openssl_get_privatekey($content, $private_key_passphrase);

<span style="color: #808080;">// Encrypt message with private key</span>
$plaintext = "<span style="color: #008000;">This is the message that we want to encrypt with private key on php</span>";
$encryptedText = "";
if (openssl_private_encrypt($plaintext, $cryptedMessage, $privateKey)){
	$encryptedText = base64_encode($cryptedMessage);
	echo $encryptedText;
	<span style="color: #808080;">// output: <span style="color: #ff6600;">SFWPsRitclLqRAB/mf3w7FwhJgN0ASiKioiNwOM3DGzkvZx+rWN6j0DaAFDue1iUJY+t1uUlpOVm1qctaHYQeRx+C2wnr1B75CUO5mvsrr7FTCJivuwAErCxGZubaIQNmq+MnAqAF52AA9st3Ri8OtrMISV5/ODcpOOLQKlBZvs=</span>
</span>} else {
	echo "cannot encrypt the message using private key";
}</pre>
<p><strong>Decrypt the encrypted message from above script using Public Key (PHP)</strong></p>
<pre><span style="color: #808080;">// Get the public key</span>
$public_key_file = "<span style="color: #ff0000;">/path_to/publickey.crt</span>";
$handle = fopen ($public_key_file, "r");
$content = fread($handle, filesize($public_key_file));
fclose($handle);
$publicKey = openssl_get_publickey($content);

<span style="color: #808080;">// Decrypt the message using public key</span>
$cryptedText = "<span style="color: #ff6600;">SFWPsRitclLqRAB/mf3w7FwhJgN0ASiKioiNwOM3DGzkvZx+rWN6j0DaAFDue1iUJY+t1uUlpOVm1qctaHYQeRx+C2wnr1B75CUO5mvsrr7FTCJivuwAErCxGZubaIQNmq+MnAqAF52AA9st3Ri8OtrMISV5/ODcpOOLQKlBZvs=</span>";
$decodedText = base64_decode($cryptedText);
$decryptedText = "";
if (openssl_public_decrypt($decodedText, $decryptedText, $publicKey)){
	echo $decryptedText;
} else {
	echo "cannot decrypt the message using public key";
}</pre>
<p>&nbsp;</p>
<h3>Encrypt message using Public Key and then Decrypt it using Private Key (PHP)</h3>
<p><strong>Encrypt a message using Public Key</strong></p>
<pre>// Get the public key
$public_key_file = "<span style="color: #ff0000;">/path_to/publickey.crt</span>";
$handle = fopen ($public_key_file, "r");
$content = fread($handle, filesize($public_key_file));
fclose($handle);
$publicKey = openssl_get_publickey($content);

// Encrypt the message using public key
$plaintext = "<span style="color: #008000;">This is the message that we want to encrypt with public key on php</span>";
$encryptedText = "";
if (openssl_public_encrypt($plaintext, $cryptedMessage, $publicKey)){
	$encryptedText = base64_encode($cryptedMessage);
	echo $encryptedText;
	<span style="color: #808080;">// output: <span style="color: #ff6600;">TiwOZrKmlPVvGy97TUA7i4kxnSgD+VTWIiklTuIaJqeQjDHqwFulpJ5WDdXh1vrj+AJQXlGfa1EH/BnMCBVeabP2jTEpivWJhNqXn+M0oma7ytXEjGAeg8FHszntN7P/RY4wqLWQj1sbKCgtUjjO8FWK9xCYRQbqc27vvgwKwPI=</span>
</span>}else{
	echo "cannot encrypt the message using public key";
}</pre>
<p><strong>Decrypt the encrypted message from above script using Private Key (PHP)</strong></p>
<pre>// Get the private key
$private_key_file = "<span style="color: #ff0000;">/path_to/privatekey.key</span>";
$private_key_passphrase = "<span style="color: #ff0000;">the_key_pasphrase</span>";
$handle = fopen($private_key_file, "r");
$content = fread($handle, filesize($private_key_file));
fclose($handle);
$privateKey = openssl_get_privatekey($content, $private_key_passphrase);

// Decrypt the message using private key
$cryptedText = "<span style="color: #ff6600;">TiwOZrKmlPVvGy97TUA7i4kxnSgD+VTWIiklTuIaJqeQjDHqwFulpJ5WDdXh1vrj+AJQXlGfa1EH/BnMCBVeabP2jTEpivWJhNqXn+M0oma7ytXEjGAeg8FHszntN7P/RY4wqLWQj1sbKCgtUjjO8FWK9xCYRQbqc27vvgwKwPI=</span>";
$decodedText = base64_decode($cryptedText);
$decryptedText = "";
if (openssl_private_decrypt($decodedText, $decryptedText, $privateKey)){
	echo $decryptedText;
}else{
	echo "cannot decrypt the message using private key";
}</pre>
<p>note: all encrypted results from this code wont be the same with your result</p>
<p>You also can do something like this:</p>
<ul>
<li>encrypt a message using Private Key in JAVA and then decrypt it using Public Key in PHP</li>
<li>encrypt a message using Private Key in PHP and then decrypt it using Public Key in JAVA</li>
<li>encrypt a message using Public Key in JAVA and then decrypt it using Private Key in PHP</li>
<li>encrypt a message using Public Key in PHP and then decrypt it using Private Key in JAVA</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/06/26/send-and-receive-encrypted-data-between-php-and-java-part-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Send and receive encrypted data between PHP and JAVA. part 1</title>
		<link>http://www.vinclay.com/2009/06/25/send-and-receive-encrypted-data-between-php-and-java-part-1/</link>
		<comments>http://www.vinclay.com/2009/06/25/send-and-receive-encrypted-data-between-php-and-java-part-1/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 08:57:26 +0000</pubDate>
		<dc:creator>vinclay</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[encryption]]></category>

		<guid isPermaLink="false">http://www.vinclay.com/?p=46</guid>
		<description><![CDATA[Part1. Using a secret key to encrypt and decrypt data
In this example we use AES-128 (rijndael-128) and CBC method, so we use a secret key and an initial vector key (iv key) to encrypt and decrypt data.
Encryption in JAVA
// The keys
String secretKey = "1234567890abcde";
String ivKey = "fedcba9876543210";

// Create key specs
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "AES");
IvParameterSpec [...]]]></description>
			<content:encoded><![CDATA[<h2>Part1. Using a secret key to encrypt and decrypt data</h2>
<p>In this example we use AES-128 (rijndael-128) and CBC method, so we use a secret key and an initial vector key (iv key) to encrypt and decrypt data.</p>
<h3>Encryption in JAVA</h3>
<pre>// The keys
String secretKey = "</span>1234567890abcde</span>";
String ivKey = "<span style="color: #ff0000;">fedcba9876543210</span>";

// Create key specs
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "<span style="color: #ff0000;">AES</span>");
IvParameterSpec ivSpec = new IvParameterSpec(ivKey.getBytes());

// the text that we want to encrypt
String plaintext = "<span style="color: #008000;">this is the text that we want to encrypt in java</span>";

// pad the string
String padded = <span style="color: #0000ff;">padString16</span>(plaintext);

// Instance the chipper
Cipher cipherEc = Cipher.getInstance("<span style="color: #ff0000;">AES/CBC/NoPadding</span>");

// init the chipper with key specs
cipherEc.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);

// Encrypt the text
byte[] encrypted = cipherEc.doFinal(padded.getBytes());

// Encode the text with base 64
BASE64Encoder encoder = new BASE64Encoder();
System.out.println(encoder.encode(encrypted));</pre>
<p><span id="more-46"></span><br />
The output of script above is:</p>
<pre><span style="color: #008000;">VD9X9nF6uENC+H8TKazjztadnp6wO7kqUBvpH7tQPrWYGLaB8ltR99U2VZ/MGtIeE5yhNr2aYE3hM6Mgm+jhRg==</span></pre>
<p><strong>The pad string method</strong></p>
<pre>// pad string needed because the string lenght must be a multiplication of 16
private String <span style="color: #0000ff;">padString16</span>(String text) {
   int mod = 16 - (text.length() % 16);
   String empty = "";
   for (int i = 0 ; i &lt; mod ; i++){
      empty = empty.concat(" ");
   }
   return text.concat(empty);
}</pre>
<p>&nbsp;</p>
<h3>Decryption in PHP</h3>
<pre>// The keys
String secretKey = "</span>1234567890abcde</span>";
String ivKey = "<span style="color: #ff0000;">fedcba9876543210</span>";

$cryptedText = "<span style="color: #008000;">VD9X9nF6uENC+H8TKazjztadnp6wO7kqUBvpH7tQPrWYGLaB8ltR99U2VZ/MGtIeE5yhNr2aYE3hM6Mgm+jhRg==</span>";

// Decode the encrypted text
$text = base64_decode($cryptedText);

// open and init the mcrypt module
$td = mcrypt_module_open("<span style="color: #ff0000;">rijndael-128</span>", "", "<span style="color: #ff0000;">cbc</span>", $ivKey);
mcrypt_generic_init($td, $secretKey, $ivKey);

// decrypt the text
$decrypted = mdecrypt_generic($td, $text);

// deinit and close the mcrypt module
mcrypt_generic_deinit($td);
mcrypt_module_close($td);

echo $decrypted;</pre>
<p>the output of script above is &#8220;<span style="color: #008000;">this is the text that we want to encrypt in java</span>&#8221;<br />
<br />&nbsp;</p>
<hr />
<br />&nbsp;</p>
<h3>Encryption in PHP</h3>
<pre>// The keys
String secretKey = "</span>1234567890abcde</span>";
String ivKey = "<span style="color: #ff0000;">fedcba9876543210</span>";

$plaintext = "<span style="color: #ff6600;">this is the text that we want to encrypt in php</span>";

// Open and init the mcrypt library with the keys
$td = mcrypt_module_open("<span style="color: #ff0000;">rijndael-128</span>", "", "<span style="color: #ff0000;">cbc</span>", $ivKey);
mcrypt_generic_init($td, $secretKey, $ivKey);

// encrypt the text
$crypt_text = mcrypt_generic($td, $plaintext);

// deinit and close mcrypt module
mcrypt_generic_deinit($td);
mcrypt_module_close($td);

// encode with base 64
echo base64_encode($crypt_text);</pre>
<p>The output of above script is</p>
<pre><span style="color: #ff6600;">VD9X9nF6uENC+H8TKazjztadnp6wO7kqUBvpH7tQPrU/WKCMgKV6cPwoP+75ju5u</span></pre>
<p>&nbsp;</p>
<h3>Decryption in JAVA</h3>
<pre>// The keys
String secretKey = "</span>1234567890abcde</span>";
String ivKey = "<span style="color: #ff0000;">fedcba9876543210</span>";

// Create key specs
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "<span style="color: #ff0000;">AES</span>");
IvParameterSpec ivSpec = new IvParameterSpec(ivKey.getBytes());

// Instance the chipper
Cipher cipherDc = Cipher.getInstance("<span style="color: #ff0000;">AES/CBC/NoPadding</span>");

// init the chipper with key specs
cipherDc.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

// insert the encrypted string
String message = "<span style="color: #ff6600;">VD9X9nF6uENC+H8TKazjztadnp6wO7kqUBvpH7tQPrU/WKCMgKV6cPwoP+75ju5u</span>";

// Decode the encrypted string with base 64
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedMessage = decoder.decodeBuffer(message);

byte[] outText = cipherDc.doFinal(decodedMessage);
System.out.println(new String(outText).trim());</pre>
<p>the output of script above is &#8220;<span style="color: #ff6600;">this is the text that we want to encrypt in php</span>&#8220;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/06/25/send-and-receive-encrypted-data-between-php-and-java-part-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Integrating iBatis with Spring on  Web Application</title>
		<link>http://www.vinclay.com/2009/04/19/integrating-ibatis-with-spring-on-web-application/</link>
		<comments>http://www.vinclay.com/2009/04/19/integrating-ibatis-with-spring-on-web-application/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 08:43:21 +0000</pubDate>
		<dc:creator>vinclay</dc:creator>
		
		<category><![CDATA[IT Stuff]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[iBatis]]></category>

		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.vinclay.com/?p=31</guid>
		<description><![CDATA[ibatis-config.xml:
&#60;?xml version="1.0" encoding="UTF-8" ?&#62;
&#60;!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd"&#62;
&#60;!-- Always ensure to use the correct XML header as above! --&#62;
&#60;sqlMapConfig&#62;

   &#60;settings
      cacheModelsEnabled="true"
      enhancementEnabled="true"
      lazyLoadingEnabled="true"
      maxRequests="128"
      maxSessions="24"
  [...]]]></description>
			<content:encoded><![CDATA[<p><strong>ibatis-config.xml:</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd"&gt;
&lt;!-- Always ensure to use the correct XML header as above! --&gt;
&lt;sqlMapConfig&gt;

   &lt;settings
      cacheModelsEnabled="true"
      enhancementEnabled="true"
      lazyLoadingEnabled="true"
      maxRequests="128"
      maxSessions="24"
      maxTransactions="12"
      defaultStatementTimeout="60"
      useStatementNamespaces="true"
   /&gt;

   &lt;!-- path is started from classpath (WEB-INF/classes/) --&gt;
   &lt;sqlMap resource="sqlmap/<span style="color: #0000ff;">sqlmap-config.xml</span>" /&gt;
&lt;/sqlMapConfig&gt;</pre>
<p><span id="more-31"></span><br />
<strong>sqlmap-config.xml:</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL MAP 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd"&gt;
&lt;sqlMap namespace="<span style="color: #ff6600;">notification</span>"&gt;

   &lt;typeAlias alias="<span style="color: #0000ff;">notification</span>" type="com.domain.Notification" /&gt;

   &lt;!-- Defines result mapping --&gt;
   &lt;resultMap id="<span style="color: #808000;">notificationResult</span>" class="notification"&gt;
      &lt;result property="id" column="id" /&gt;
      &lt;result property="deleted" column="deleted" /&gt;
      &lt;result property="description" column="description" /&gt;
      &lt;result property="level" column="level" /&gt;
      &lt;result property="time" column="time" /&gt;
  &lt;/resultMap&gt;

  &lt;statement id="<span style="color: #339966;">insertNotification</span>" parameterClass="<span style="color: #0000ff;">notification</span>"&gt;
      insert into NOTIFICATION
         (id, deleted, description, level, time)
      values
         (#id#, #deleted#, #description#, #level#, #time#)
   &lt;/statement&gt;

   &lt;!-- Declares getTrade query --&gt;
   &lt;select id="<span style="color: #339966;">findNotificationById</span>" parameterClass="long" resultMap="<span style="color: #808000;">notificationResult</span>"&gt;
      SELECT * FROM NOTIFICATION WHERE id = #id#
   &lt;/select&gt;

   &lt;update id="<span style="color: #339966;">deleteNotification</span>" parameterClass="long"&gt;
      UPDATE NOTIFICATION SET deleted = true WHERE id = #id#
   &lt;/update&gt;
&lt;/sqlMap&gt;</pre>
<p><strong>spring-context.xml:</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
       default-lazy-init="true"&gt;

   &lt;!--Enable Spring Controller Annotation--&gt;
   &lt;context:annotation-config/&gt; 

   &lt;!-- Scan Controllers --&gt;
   &lt;context:component-scan base-package="com.controller"/&gt;

   &lt;!-- Data Source (iBatis) Property --&gt;
   &lt;import resource="classpath:<span style="color: #0000ff;">spring-ds.xml</span>"/&gt;

   &lt;!--Resolver--&gt;
   &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="cache" value="true"/&gt;
      &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;
   &lt;/bean&gt;
&lt;/beans&gt;</pre>
<p><strong>spring-ds.xml:</strong></p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
      default-lazy-init="true"&gt;

   &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost/notificationdb/&gt;
      &lt;property name="username" value="userdb"/&gt;
      &lt;property name="password" value="passdb"/&gt;
      &lt;property name="defaultAutoCommit" value="false" /&gt;
      &lt;property name="initialSize" value="5" /&gt;
      &lt;property name="maxActive" value="20" /&gt;
      &lt;property name="maxIdle" value="5" /&gt;
      &lt;property name="maxOpenPreparedStatements" value="50" /&gt;
   &lt;/bean&gt;

   &lt;bean id="<span style="color: #ff00ff;">sqlMapClient</span>" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"&gt;
      &lt;property name="configLocation" value="classpath:<span style="color: #0000ff;">ibatis-config.xml</span>" /&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
   &lt;/bean&gt;

   &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
   &lt;/bean&gt;

   &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

&lt;/beans&gt;<strong>
</strong></pre>
<p><strong>NotificationDao.java:</strong></p>
<pre>import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;
import com.amt.mis.msc.domain.Notification;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository(value = "notificationDao")
public class NotificationDao extends SqlMapClientDaoSupport {

   @Autowired
   public void setSqlMapClnt(SqlMapClient <span style="color: #ff00ff;">sqlMapClient</span>){
      this.setSqlMapClient(sqlMapClient);
   }

   public Notification findNotificationById(Long id){
      return (Notification) getSqlMapClientTemplate().queryForObject("<span style="color: #ff6600;">notification</span>.<span style="color: #339966;">findNotificationById</span>", id);
   }

   public Notification insertNotification(Notification notification){
      return (Notification) getSqlMapClientTemplate().insert("<span style="color: #ff6600;">notification</span>.<span style="color: #339966;">insertNotification</span>", notification);
   }
}</pre>
<p><strong>NotificationService.java:</strong></p>
<pre>import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.amt.mis.msc.dao.NotificationDao;
import com.amt.mis.msc.domain.Notification;

@Service(value = "notificationService")
public class NotificationService {

   @Autowired
   private NotificationDao notificationDao;

   @Transactional
   public Notification insert(Notification notification){
      return notificationDao.insertNotification(notification);
   }

   public Notification findById(Long id){
      return notificationDao.findNotificationById(id);
   }
}</pre>
<p><strong>Minimal Jars dependencies:</strong></p>
<ul>
<li>aopalliance.jar</li>
<li>asm.jar</li>
<li>commons-dbcp.jar</li>
<li>commons-pool.jar</li>
<li>ibatis-2.3.4.726.jar</li>
<li>spring-aop.jar</li>
<li>spring-beans.jar</li>
<li>spring-context.jar</li>
<li>spring-context-support.jar</li>
<li>spring-core.jar</li>
<li>spring-jdbc.jar</li>
<li>spring-orm.jar</li>
<li>spring-tx.jar</li>
<li>spring-web.jar</li>
<li>spring-webmvc.jar</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/04/19/integrating-ibatis-with-spring-on-web-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Common Postgre Command</title>
		<link>http://www.vinclay.com/2009/03/04/common-postgre-command/</link>
		<comments>http://www.vinclay.com/2009/03/04/common-postgre-command/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 01:08:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DB]]></category>

		<category><![CDATA[postgre]]></category>

		<guid isPermaLink="false">http://localhost/project/vinclay.com/?p=25</guid>
		<description><![CDATA[# Restore database from .sql
  psql -d db_name -U userdb_name < dump.sql
# Dump database
  pg_dump -U postgres -d -O db_name
# To dump a database:
  $ pg_dump mydb > db.out
# To reload this database:
  $ psql -d database -f db.out
# To dump a database called mydb that contains large objects to a [...]]]></description>
			<content:encoded><![CDATA[<p># Restore database from .sql<br />
  <code>psql -d db_name -U userdb_name < dump.sql</code></p>
<p># Dump database<br />
  <code>pg_dump -U postgres -d -O db_name</code></p>
<p># To dump a database:<br />
  <code>$ pg_dump mydb > db.out</code></p>
<p># To reload this database:<br />
  <code>$ psql -d database -f db.out</code></p>
<p># To dump a database called mydb that contains large objects to a tar file:<br />
  <code>$ pg_dump -Ft -b mydb > db.tar</code></p>
<p># To reload this database (with large objects) to an existing database called newdb:<br />
  <code>$ pg_restore -d newdb db.tar</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/03/04/common-postgre-command/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Common SSL Commands</title>
		<link>http://www.vinclay.com/2009/03/04/common-ssl-commands/</link>
		<comments>http://www.vinclay.com/2009/03/04/common-ssl-commands/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 00:54:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://localhost/project/vinclay.com/?p=20</guid>
		<description><![CDATA[OPENSSL
=======
CREATE OWN CA (Example: CLaYCA)
1. Setting .cfg file n setting directories:

     CLaYCA
        &#124;-- ca
        &#124;-- server
        &#124;-- user
2. Create Private Key (Remember the password)
	openssl genrsa -des3 -out ca/CLaYCA.key 1024
3. Create [...]]]></description>
			<content:encoded><![CDATA[<p><strong>OPENSSL</strong><br />
=======</p>
<p><strong>CREATE OWN CA (Example: CLaYCA)</strong><br />
1. Setting .cfg file n setting directories:
<pre>
     CLaYCA
        |-- ca
        |-- server
        |-- user</pre>
<p>2. Create Private Key (Remember the password)<br />
	<code>openssl genrsa -des3 -out ca/CLaYCA.key 1024</code></p>
<p>3. Create CSR<br />
	<code>openssl req -new -key ca/CLaYCA.key -out ca/CLaYCA.csr</code></p>
<p>4. Self-sign certificate:<br />
	<code>openssl x509 -req -days 3650 -in ca/CLaYCA.csr-out ca/CLaYCA.crt -signkey ca/CLaYCA.key</code></p>
<p>5. To check the certificate<br />
	<code>openssl x509 -in ca/CLaYCA.crt -text</code></p>
<p>6. Create DER Format from private key<br />
	<code>openssl pkcs8 -topk8 -in ca/CLaYCA.key -outform DER -out ca/CLaYCA.der -nocrypt</code><br />
<span id="more-20"></span>	</p>
<p><br/><br />
<strong>CREATE CERTIFICATE FOR APACHE SERVER TO BE SIGNED BY CLaYCA (Example: localhost)</strong><br />
1. Create Private Key (Remember the password)<br />
	<code>openssl genrsa -des3 -out server/localhost/localhost.key 1024</code></p>
<p>2. Create CSR<br />
	<code>openssl req -new -key server/localhost/localhost.key -out server/localhost/localhost.csr</code></p>
<p>3. Sign Server CSR with CLaYCA Key<br />
	<code>openssl x509 -req -in server/localhost/localhost.csr -CA ca/CLaYCA.crt -CAkey ca/CLaYCA.key -CAcreateserial -out server/localhost/localhost.crt -days 365</code></p>
<p><br/><br />
<strong>CREATE CERTIFICATE FOR XAMPP SERVER TO BE SIGNED BY CLaYCA (Example: server)</strong><br />
1. Run xampp/apache/makecert.bat	 (Remember the password)</p>
<p>2. Create CSR<br />
	<code>openssl req -new -key ssl.key/server.key -out ssl.ca/server.csr</code></p>
<p>3. Sign Server CSR with CLaYCA Key<br />
	<code>openssl x509 -req -in server/xampp/server.csr -CA ca/CLaYCA.crt -CAkey ca/CLaYCA.key -CAcreateserial -out server/xampp/server.crt -days 3650</code></p>
<p><br/><br />
<strong>CREATE CERTIFICATE FOR USER (Example: dummyphp)</strong><br />
1. Create Private Key (Remember the password)<br />
	<code>openssl genrsa -des3 -out user/dummyphp/dummyphp.key 1024</code></p>
<p>2. Create CSR<br />
	<code>openssl req -new -key user/dummyphp/dummyphp.key -out user/dummyphp/dummyphp.csr</code></p>
<p>3. Sign Server CSR with CLaYCA Key<br />
	<code>openssl x509 -req -in user/dummyphp/dummyphp.csr -CA ca/CLaYCA.crt -CAkey ca/CLaYCA.key -CAcreateserial -out user/dummyphp/dummyphp.crt -days 3650</code></p>
<p>4. Convert to P12 (Remember the password)<br />
	<code>openssl pkcs12 -export -out user/dummyphp/dummyphp.p12 -inkey user/dummyphp/dummyphp.key -in user/dummyphp/dummyphp.crt</code></p>
<p>5. Convert to PEM<br />
	<code>openssl pkcs12 -in user/dummyphp/dummyphp.p12 -out user/dummyphp/dummyphp.pem</code></p>
<p><br/><br />
<strong>JAVA KEYTOOL</strong><br />
===========</p>
<p><strong>CREATE CERTIFICATE FOR SERVER (Example: tomcat)</strong><br />
1. Create the keystore (Remember the password)<br />
	<code>keytool -genkey  -keyalg RSA -alias "tomcat" -keystore server/tomcat/tomcat-keystore.jks -validity 360</code></p>
<p>2. Create CSR<br />
	<code>keytool -certreq -alias "tomcat" -keystore motiondev.jks -file server/tomcat/tomcat.csr</code></p>
<p>3. Sign Server CSR with CLaYCA Key<br />
	<code>openssl x509 -req -in server/tomcat/tomcat.csr -CA ca/CLaYCA.crt -CAkey ca/CLaYCA.key -CAcreateserial -out server/tomcat/tomcat.crt -days 3650</code></p>
<p>4. Import the Certificate to tomcat-keystore.jks<br />
	<code>keytool -import -keystore server/tomcat/tomcat-keystore.jks -storepass "12345678" -file server/tomcat/tomcat.crt</code></p>
<p><br/><br />
<strong>TRUSTED CA CERTIFICATES ACTIONS</strong></p>
<p>- Import NEW CA to TRUSTSTORE<br />
	<code>keytool -import -trustcacerts -file NEWCA.crt -keystore jre/lib/security/cacerts -storepass changeit</code></p>
<p>- Export Certificate of a CA<br />
	<code>keytool -export -alias mykey -file theca.crt -keystore jre/lib/security/cacerts -storepass changeit</code></p>
<p>- List CAs in TRUSTSTORE<br />
	<code>keytool -list -v -keystore jre/lib/security/cacerts -storepass changeit</code></p>
<p>- Delete CA on TRUSTSTORE<br />
	<code>Keytool -delete -alias caalias jre/lib/security/cacerts -storepass changeit</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/03/04/common-ssl-commands/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Get Elapsed Hours between 2 Dates</title>
		<link>http://www.vinclay.com/2009/03/04/get-elapsed-hours-between-2-dates/</link>
		<comments>http://www.vinclay.com/2009/03/04/get-elapsed-hours-between-2-dates/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:59:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DB]]></category>

		<guid isPermaLink="false">http://localhost/project/vinclay.com/?p=17</guid>
		<description><![CDATA[For PostgreSQL:
SELECT
    jam.days,
    jam.hours,
    jam.minutes,
    jam.seconds,
    ((to_number(jam.days, 9999)*24) + to_number(jam.hours, 9999) &#124;&#124;':'&#124;&#124; to_number(jam.minutes, 9999) )as jumlah
from
 (SELECT
    to_char(age(date1 ,date2), 'DD') as days,
    to_char(age(date1 ,date2), 'HH24') as hours,
    to_char(age(date1 ,date2), 'MI') as [...]]]></description>
			<content:encoded><![CDATA[<p>For PostgreSQL:</p>
<pre>SELECT
    jam.days,
    jam.hours,
    jam.minutes,
    jam.seconds,
    ((to_number(jam.days, 9999)*24) + to_number(jam.hours, 9999) ||':'|| to_number(jam.minutes, 9999) )as jumlah
from
 (SELECT
    to_char(age(date1 ,date2), 'DD') as days,
    to_char(age(date1 ,date2), 'HH24') as hours,
    to_char(age(date1 ,date2), 'MI') as minutes,
    to_char(age(date1 ,date2), 'SS') as seconds
  FROM
    table_name ) as jam</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/03/04/get-elapsed-hours-between-2-dates/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Regex Date</title>
		<link>http://www.vinclay.com/2009/03/04/regex-date/</link>
		<comments>http://www.vinclay.com/2009/03/04/regex-date/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:52:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Regex]]></category>

		<guid isPermaLink="false">http://localhost/project/vinclay.com/?p=13</guid>
		<description><![CDATA[ddMMyyyy:
^(0[1-9]&#124;[12][0-9]&#124;3[01])(0[1-9]&#124;1[012])(19&#124;20)[0-9]{2}$
dd/MM/yyyy or dd-MM-yyyy or dd.MM.yyyy:
^(0[1-9]&#124;[12][0-9]&#124;3[01])[- /.](0[1-9]&#124;1[012])[- /.](19&#124;20)[0-9]{2}$
]]></description>
			<content:encoded><![CDATA[<p>ddMMyyyy:<br />
<code>^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])(19|20)[0-9]{2}$</code></p>
<p>dd/MM/yyyy or dd-MM-yyyy or dd.MM.yyyy:<br />
<code>^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}$</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/03/04/regex-date/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Regex Hour</title>
		<link>http://www.vinclay.com/2009/03/04/regex-hour/</link>
		<comments>http://www.vinclay.com/2009/03/04/regex-hour/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:48:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Regex]]></category>

		<guid isPermaLink="false">http://localhost/project/vinclay.com/?p=10</guid>
		<description><![CDATA[HH:mm (from 00:00 to 23:59)
^((?:[01]\d)&#124;(?:2[0-3])):([0-5]\d)$
]]></description>
			<content:encoded><![CDATA[<p>HH:mm (from 00:00 to 23:59)<br />
<code>^((?:[01]\d)|(?:2[0-3])):([0-5]\d)$</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vinclay.com/2009/03/04/regex-hour/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

