Login   Register  
PHP Classes
elePHPant
Icontem

File: xmlsec.example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Kalendarev  >  XML Security  >  xmlsec.example.php  >  Download  
File: xmlsec.example.php
Role: Example script
Content type: text/plain
Description: example of encrypt end decrypt xml document
Class: XML Security
Encrypt and decrypt XML documents
Author: By
Last change:
Date: 2006-04-18 00:32
Size: 1,064 bytes
 

Contents

Class file image Download
<?
include "xmlsec.class.php";

 
$xmlsec = new xmlsec'deskey.xml');

 if ( !
file_exists('deskey.xml') ){
       if ( !
$xmlsec->addkey('deskey.bin''DES'XMLSEC_DES)  )
            die( 
$xmlsec->errorMsg );
 }


  
// read input xml file
  
$f =  fopen"data.xml" 'r') ;
  if ( !
$f ){
     echo 
'Error open file ';
     exit;
  }

  
$xmlstr fread($ffilesize("data.xml"));
  
fclose($f);

  
$doc domxml_open_mem$xmlstr );

 if ( !
$doc )
  {
      echo 
"Error while parsing the input xml document\n";
      exit;
  }


  
// encrypt data
  
$encryptxml $xmlsec->encrypt($doc XMLSEC_3DES );
  if ( !
$encryptxml  )
   die( 
$xmlsec->errorMsg  .'<br>'.$xmlsec->cmd);

  unset( 
$doc );
  
$doc domxml_open_mem$encryptxml );
   if ( !
$doc )
  {
      echo 
"Error while parsing the decrypt document \n";
      exit;
  }

 
// decrypt data
 
$outxml $xmlsec->decrypt$doc );
 if ( !
$outxml  )
   die( 
$xmlsec->errorMsg  .'<br>'.$xmlsec->cmd);
 else
  
header('Content-type: text/xml');

PRINT  
$outxml;

?>