2007년 11월 16일 금요일

Using base 64 Crypto 2 Md5 Algorithm.

package raphyr.util;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

public class SecurityUtil

{

private Base64 Base64 = null;

/**

* byte[] ret = HashUtil.digest("MD5", "abcd".getBytes());

*/

public byte[] digest(String alg, byte[] input) throws NoSuchAlgorithmException

{

MessageDigest md = MessageDigest.getInstance(alg);

return md.digest(input);

}

public String getCryptoMD5String(String inputValue) throws Exception

{

Base64 = new Base64();

if( inputValue == null ) throw new Exception("Can't conver to Message Digest 5 String value!!");

byte[] ret = digest("MD5", inputValue.getBytes());

String result = Base64.encode(ret);

return result;

}

}

------------

package raphyr.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64
{
public String encode(byte[] encodeBytes)
{
BASE64Encoder base64Encoder = new BASE64Encoder();
ByteArrayInputStream bin = new ByteArrayInputStream(encodeBytes);
ByteArrayOutputStream bout = new ByteArrayOutputStream();

byte[] buf = null;

try
{
base64Encoder.encodeBuffer(bin, bout);
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
buf = bout.toByteArray();

return new String(buf).trim();
}
public byte[] decode(String strDecode)
{
BASE64Decoder base64Decoder = new BASE64Decoder();
ByteArrayInputStream bin = new ByteArrayInputStream(strDecode.getBytes());
ByteArrayOutputStream bout = new ByteArrayOutputStream();

byte[] buf = null;

try
{
base64Decoder.decodeBuffer(bin, bout);
}
catch(Exception e)
{
System.out.println("Exception");
e.printStackTrace();
}
buf = bout.toByteArray();

return buf;
}
}

struts-config.xml

<?xml version="1.0" encoding="EUC-KR"?>

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>

<action-mappings>

<action path="/sangpum" type="raphyr.action.List">

<forward name="sang_list" path="/sang_list.jsp" />

</action>

</action-mappings>

</struts-config>

2007년 11월 14일 수요일

struts 1.3.9.

default web.xml

<?xml version="1.0" encoding="UTF-8"?>

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

<display-name>struts application</display-name>

<!-- Register by ActionServlet -->

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/config/struts-config.xml</param-value>

</init-param>

<init-param>

<param-name>debug</param-name>

<param-value>2</param-value>

</init-param>

<init-param>

<param-name>detail</param-name>

<param-value>2</param-value>

</init-param>

<!-- Starting with ActionServlet at this application -->

<load-on-startup>1</load-on-startup>

</servlet>

<!-- Run at ActionServlet with starting "*.do" url pattern -->

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<!-- constraint user access -->

<security-constraint>

<web-resource-collection>

<web-resource-name>PreventViewingJSPs</web-resource-name>

<description>Access denine directive JSP page</description>

<url-pattern>*.jsp</url-pattern>

<http-method>GET</http-method>

<http-method>POST</http-method>

</web-resource-collection>

<auth-constraint>

<role-name></role-name>

</auth-constraint>

</security-constraint>

</web-app>