메뉴 건너뛰기

infra

[XML] 임의의 데이터(Arbitrary Data)와 XML문서 암호화

박영식2010.04.22 05:03조회 수 3967댓글 1

  • 2
    • 글자 크기
 DES로 전문을 암호화 하는 방법이다.

개발환경
OS : LINUX
SERVER : APACHE2
SERVERSIDE SCRIPT : PHP5
CLASS LIBRARY : XMLWriter
Encryption tool : xmlsec1
ed.png

PHP5로 설정된 서버에서 XMLWriter를 설치한다. (밑에글에 쓰여져 있다.)

업로드된 파일의 압축을 풀면, 아래의 파일들이 들어있다.

data.xml - 암호화할 예제 xml 파일
deskey.bin - 예제 암호화 cafile
deskey.xml - 예제 deskey
dsig.example.php - not tested
verify.example.php - not tested
xmlsec.class.php - 암호화 및 복호화 클래스
xmlsec.example.php - 예제

[xmlsec.example.php]
include "xmlsec.class.php"; // 클래스 라이브러리 인클루드
 $xmlsec = new xmlsec( 'deskey.xml');//deskey 파일 설정
 if ( !file_exists('deskey.xml') ){
       if ( !$xmlsec->addkey('deskey.bin', 'DES', XMLSEC_DES)  )//ca파일 설정
            die( $xmlsec->errorMsg );
 }
  $f =  fopen( "data.xml" , 'r') ;//암호화할 파일 읽기
  if ( !$f ){
     echo 'Error open file ';
     exit;
  }
  $xmlstr = fread($f, filesize("data.xml"));
  fclose($f);

    $doc = new DomDocument($xmlstr);//dom object로 만들기
 if ( !$doc )
  {
      echo "Error while parsing the input xml documentn";
      exit;
  }

  $encryptxml = $xmlsec->encrypt($doc , XMLSEC_3DES );//암호화
  if ( !$encryptxml  )
   die( $xmlsec->errorMsg  .'<br>'.$xmlsec->cmd);
  unset( $doc );
  $doc = new DomDocument( $encryptxml );//암호화한 xml을 dom object로 만들기
   if ( !$doc )
  {
      echo "Error while parsing the decrypt document n";
      exit;
  }

 $outxml = $xmlsec->decrypt( $doc );//복호화
 if ( !$outxml  )
   die( $xmlsec->errorMsg  .'<br>'.$xmlsec->cmd);

echo "<br/>암호화 된 xml<br/>";
echo"<pre>";
echo htmlspecialchars($encryptxml);
echo "<br/>복호화 된 xml<br/>";
echo htmlspecialchars($outxml);
echo "</pre>";

http://archi.ssu.ac.kr/xmlenc-core/xmlsec/xmlsec.example.php

위 링크에서 확인할 수 있다.

박영식 (비회원)
  • 2
    • 글자 크기
[xmlsec1] 설치와 test (by 박영식) [domxml] php에서 phpize, pecl을 이용해 사용가능하게 하기 (by 박영식)

댓글 달기

댓글 1
박영식
2011.03.17 조회 1710
박영식
2011.03.07 조회 2059
박영식
2010.04.22 조회 3234
박영식
2010.01.09 조회 3316
첨부 (2)
xmlsec.zip
6.8KB / Download 73
ed.png
50.5KB / Download 71
위로