Pages

2014년 3월 28일 금요일

[YouTube] 영화음악 베스트 100 (1~10)



아래클릭시 YouTube로 연결됩니다. 광고 나오는 부분은 알아서 SKIP 하세요^^









[JAVA] XML 파일 파싱

XML 파일 파싱을 위해 예제 파일이 필요하다.

아래와 같이 test.xml 파일 작성

[ test.xml ]


1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8"?>
<RESOURCE_FILELIST>
    <FILE_LIST>
        <FILE>file1.txt</FILE>
        <FILE>file2.txt</FILE>
        <FILE>file3.txt</FILE>
        <FILE>file4.txt</FILE>
    </FILE_LIST>
    <HVALUE>85e4b37328f95d91b6ec85fe90d791708f9731b0</HVALUE>
</RESOURCE_FILELIST>


[ XML 파일 파싱 JAVA 소스 ]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
String targetDir = "/temp/test.xml";
File file = new File(targetDir);
/****************** XML 파일 파싱 START ******************/
DocumentBuilderFactory docBuildFact = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuild = docBuildFact.newDocumentBuilder();
Document doc = docBuild.parse(file);
doc.getDocumentElement().normalize();
// FILE_LIST엘리먼트 리스트
NodeList fileList = doc.getElementsByTagName("FILE_LIST");
for (int i = 0; i < fileList.getLength(); i++) {
    Node fileListNode = fileList.item(i);
    if(fileListNode.getNodeType() == Node.ELEMENT_NODE){
        // FILE_LIST엘리먼트
        Element fileListElmnt = (Element) fileListNode;
        // FILE 태그
        NodeList fileNameList= fileListElmnt.getElementsByTagName("FILE");
        for(int j = 0; j < fileNameList.getLength(); j++){
            Element fileElmnt = (Element) fileNameList.item(j);
            Node fileName = fileElmnt.getFirstChild();
        }
    }
}
// HVALUE엘리먼트 리스트
NodeList hvalue = doc.getElementsByTagName("HVALUE");
Element hvalueElmnt = (Element) hvalue.item(0);
Node hvalueNode = hvalueElmnt.getFirstChild();
/****************** XML 파일 파싱 END ******************/

로깅을 해보면 XML 파일을 파싱해서 읽어 올 수 있다.

2014년 3월 27일 목요일

[JAVA] Ehcache의 HTTP Gzip 압축

web.xml에 filter 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<filter>
    <filter-name>gzipFilter</filter-name>
    <filter-class>net.sf.ehcache.constructs.web.filter.GzipFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>gzipFilter</filter-name>
    <url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>gzipFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>gzipFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>gzipFilter</filter-name>
    <url-pattern>*.js</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>gzipFilter</filter-name>
    <url-pattern>*.css</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>gzipFilter</filter-name>
    <url-pattern>*.dwr</url-pattern>
</filter-mapping>

Tomcat 7 부터는 압축을 자체 지원한다.

server.xml에 아래처럼 설정하면 mime-type을 지정할 수 있다.


1
2
3
4
5
6
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" URIEncoding="UTF-8"
           compressableMimeType="text/html,text/xml,text/plain,application/xml,application/json"
           compression="on"
/>

블로그에 예쁘게 소스코드 넣기

블로그에 코드 등 소스를 올릴때 하이라이트를 예쁘게 줄 수 있는 프로그램이 있다.

http://prev.kr/app/ColorScripter/

2014년 3월 19일 수요일

[ SECURITY ] 암호화 알고리즘

 블록 암호화
- 크기가 고정된 블록을 위한 암호화 함수
- 일정한 크기의 평문을 암호화해서 만들어 냄
- 블록 암호화 방법은 되돌리는 것이 가능. 일정한 암호문을 복호화하여 원래의 평문을 얻을 수 있음
- 평문과 암호문은 항상 같은 크기를 가지는데, 이것을 블록 암호화의 블록 크기라 함

* 대칭키 암호화
- 하나의 키를 사용하여 암호화와 복호화를 진행하는 방법
- 대표적인 알고리즘에는 AES, DES, 3DES, SEED 등이 있음
- 송신자와 수신자가 암호화에 사용된 키만 공유하면 손쉽게 사용할 수 있다는 장점이 있음
- 대칭키가 외부에 유출되었을 경우에는 안전성을 보장받지 못하며 이러한 대칭키를 안전하게 관리하기 위해서 많은 비용과 노력이 필요하다는 단점이 있음

* 비대칭키 암호화
- 공개키(Public Key)와 개인키(Private Key)라는 두 개의 서로 다른 키를 이용하여 암호화와 복호화를 진행하는 방법
- 대표적인 알고리즘에는 RSA, PKCS 등이 있음
- 공개키는 외부에 공개되는 키이고, 개인키는 해당 개인만 가지고 있는 키를 의미
- 공개키로 암호화된 메시지는 개인키로만 복호화할 수 있으며, 개인키로 암호화된 메시지는 공개키로만 복호화될 수 있음
- 비대칭키 암호화 방식은 대칭키 암호화 방식보다 높은 안전성과 보안성을 제공하지만 암복호화에 소용되는 시간이 상대적으로 오래 걸린다는 단점이 있음

1) DES (Data Encryption Standard)

- 64비트 단위로 나뉘어 진 데이터 블록을 56비트의 비밀키를 이용하여 암호화하는 대칭키 암호 알고리즘
- 64비트 블록과 56비트 키를 바탕으로 만든 16개의 보조키가 총 16번이 혼돈과 확산을 거쳐 완료
- 56비트라는 짧은 키 길이로 인해 더 이상 안전하지 않다고 판단되어 DES를 3회 반복하는 3DES를 사용하도록 권고

2) AES (Advanced Encryption Standard)

- DES의 안전성에 대한 여러가지 공격 방법들이 발표되면서 미국의 NIST에서는 1998년에 차세대 블록 암호 알고리즘인 AES를 공모함
- 2000년 10월에 Rijindael이 AES 알고리즘으로 선정되었으며, 2001년 11월 FIPS-197로 등록
- 처음에 개발된 Rijindael 알고리즘은 암호화에 사용하는 키의 길이와 입력 평문의 길이가 128비트, 196비트, 256비트 중 하나를 선택할 수 있었으나 FIPS-197에 등록된 AES 알고리즘은 입력 평문의 길이는 128비트로 고정시키고, 사용하는 암호화 키의 길이만 128비트, 192비트, 256비트 중에서 선택할 수 있도록 정의
- AES는 지금까지 알려진 블록 암호 알고리즘에 대한 모든 공격 방법들에 대해 안전하도록 설계되었으며, 하드웨어나 소프트웨어 구현시 속도나 코드 compactness 면에서 효율적이므로 스마트 카드와 같은 응용에 적합하다는 장점이 있음

3) SEED

정보통신 및 정보보호의 비밀성 서비스를 제공하기 위하여 한국정보보호 진흥원이 주관하여 1998년 개발, 공개하여 한국 표준 암호 방식으로 선정한 128비트 블록 암호 방식
- 평문 128비트와 암호화 키 128비트가 입력되어 128비트의 암호문을 출력

4) ARIA (Academy, Research Institute, Agency)

- 국가보안기술연구소 주도로 학계, 국가정보원 등의 암호기술 전문가들이 공동 개발한 128, 192, 256비트 암호알고리즘
- 지난 2004년 한국 산업 규격 KS 표준으로 제정
- ARIA는 민간 암호 알고리즘 SEED와 함께 전자정부의 대국민 행정 서비스용으로 보급되고 있으며, 스마트 카드 등의 초경량 환경 및 고성능 서버 환경 등에서 SEED에 비하여 상대적으로 장점을 가지고 있음
- 국가기관 표준알고리즘(KS표준, KSX-1312)으로 모든 공공기관 및 산하기관은 ARIA로 암호화해야 함

5) RSA (Rivest Shamir Adleman)

- 서로 연관성이 있는 상이한 두 개의 키를 각각 암호화와 복호화에 이용하는 비대칭키 암호화 방식 
- RSA 는 최초로 공개키 암호화의 개념을 구현 
- 현재 공개키 암호화에서 가장 널리 쓰이고 있는 공개키 알고리즘
- 안정성이 십 여년 이상을 통해 검증이 되었고그 동안 발표 되어온 공개키 암호화 알고리즘 중에서 이해와 구현이 쉬움



[출처] 암호화 알고리즘|작성자 유즈

2014년 3월 18일 화요일

[SPRING] 다국어 한글 메시지 properties 관리

아래와 같이 COMMAND 창에서 실행하게 되면 messages_ko.properties의 한글로 작성된

문구가 인코딩되어 messages_ko.properties2 에 저장되게 된다.

native2ascii -encoding UTF8 messages_ko.properties messages_ko.properties2

2014년 3월 9일 일요일

[YouTube] 7080 가요 베스트 200 (121 ~ 140)

아래 링크 클릭시 YouTube로 연결됩니다. 광고 나오는 부분은 알아서 

SKIP 하세요 ^^



[YouTube] 7080 가요 베스트 200 (101 ~ 120)

아래 링크 클릭시 YouTube로 연결됩니다. 광고 나오는 부분은 알아서 

SKIP 하세요 ^^




2014년 3월 6일 목요일

[YouTube] 7080 가요 베스트 200 (61 ~ 80)

아래 링크 클릭시 YouTube로 연결됩니다. 
항상 힘나게 해 주셔서 감사합니다.




[YouTube] 7080 가요 베스트 200 (41 ~ 60)

아래 링크 클릭시 YouTube로 연결됩니다. 
항상 힘나게 해 주셔서 감사합니다.



2014년 3월 5일 수요일

[JAVA] VO와 MAP중에 어떤것을 사용해야 할까?


    무엇이 좋을까? 어디까지나 개인적인 생각이지만 솔루션 및 유지보수가 필요한

개발에는 VO가 좋은 것 같다. VO 클래스를 생성하는데 Getter와 Setter를 요즘

누가 다 코딩을 해주는가? 없을 것이다. 아마도 Eclipse의 메뉴를 보면 Source

아래 Generate Getters and Setters를 사용해서 코딩을 단축 시킬 것이다. 아니면

Lombok 라이브러리를 사용하게 되면 class 앞에 @Data를 넣어 주게되면 화면에는

소스가 보이지 않지만 Eclipse의 Outline에서 get, set 함수를 확인 할 수 있다.

위 두가지를 모르는 초보 개발자라고 하면 VO 클래스 하나 만드는 것도 일이 될 것

이다.

    그렇다면, MAP은 어떤가? 막말로 SI개발하는데서 주로 MAP을 많이 사용한다.

이유는 간단하다. 개발자들이 다시 이 부분을 유지 보수 할 생각으로 만들지는

않는다는 것이다. 여기서 우리나라 개발자의 고질적인 문제점이 나오는 것 같다.

뒤에서 유지보수 해야 할 사람은 생각하지 않고 현재 개발만 편하면 된다는게

많은 개발자들의 생각이다.

    MAP은 개발자 입장에서 너무나도 편하다는 생각이 든다. 그래서 나도 모르게

단순 페이지 개발은 누가 봐도 크게 분석이 필요 없는 부분에서는 MAP을 사용하고,

파라미터등 기본적으로 값이 이동이 눈에 보여야 하는 부분에 대해서는 VO를

사용한다. 지극히 개인적인 생각이지만 개발하는 부분에 있어서 두가지를 잘 사용

하는 것이 효율적이지 않을까 싶다.

[JAVA] JAVA 7의 새로운 언어 기능

Here are 7 of the new features that have been completed:
  • Language support for collections ( Postponed to Java 8 )
  • Automatic Resource Management
  • Improved Type Inference for Generic Instance Creation (diamond)
  • Underscores in numeric literals
  • Strings in switch
  • Binary literals
  • Simplified Varargs Method Invocation
There is a lot more to Java 7 then just these language changes. I’ll be exploring the rest of the release in future posts. One of the big debates is currently around Closures, which are a separate JSR.

Language support for collections

This has been postponed to Java 8! You could use my simple alternative until then.
Java will be getting first class language support for creating collections. The style change means that collections can be created like they are in Ruby, Perl etc.
Instead of:
List<String> list = new ArrayList<String>();
list.add("item");
String item = list.get(0);
  
Set<String> set = new HashSet<String>();
set.add("item");
  
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key", 1);
int value = map.get("key");
You will be able to use:
List<String> list = ["item"];
String item = list[0];
  
Set<String> set = {"item"};
  
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
These collections are immutable.

Automatic Resource Management

Some resources in Java need to be closed manually like InputStream, Writers, Sockets, Sql classes. This language feature allows the try statement itself to declare one of more resources. These resources are scoped to the try block and are closed automatically.
This:
BufferedReader br = new BufferedReader(new FileReader(path));
try {
   return br.readLine();
} finally {
   br.close();
}
becomes:
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
   return br.readLine();
}
You can declare more than one resource to close:
try (
   InputStream in = new FileInputStream(src); 
   OutputStream out = new FileOutputStream(dest)) 
{
 // code
}
To support this behaviour all closable classes will be retro-fitted to implement a Closableinterface.

Improved Type Inference for Generic Instance Creation (diamond)

This is a particular annoyance which is best served with an example:
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
becomes:
Map<String, List<String>> anagrams = new HashMap<>();
This is called the diamond operator: <> which infers the type from the reference declaration.

Underscores in numeric literals

Long numbers are hard to read. You can now split them up using an underscore in ints and longs:
int one_million = 1_000_000;

Strings in switch

Currently you can only use numbers or enums in switch statements. String has been added as a candidate:
String s = ...
switch(s) {
 case "quux":
    processQuux(s);
    // fall-through

  case "foo":
  case "bar":
    processFooOrBar(s);
    break;

  case "baz":
     processBaz(s);
    // fall-through

  default:
    processDefault(s);
    break;
}

Binary literals

Java code, due to its C heritage, has traditionally forced programmers to represent numbers in only decimal, octal, or hexadecimal.
As quite a few domains are bit orientated, this restriction can introduce errors. You can now create binary numbers using an 0b prefix.
int binary = 0b1001_1001;

Simplified Varargs Method Invocation

When a programmer tries to invoke a *varargs* (variable arity) method with a non-reifiable varargs type, the compiler currently generates an “unsafe operation” warning. JDK 7 moves the warning from the call site to the method declaration. This will enable API designers to use varargs due to the reduction of warnings reported.
This one is slightly more involved so you are better off looking at the proposal.