PHP Classes

File: xmlsec.example.php

Recommend this page to a friend!
  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: 15 years ago
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($f, filesize("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;

?>

For more information send a message to info at phpclasses dot org.