Location: PHPKode > scripts > XML Security > xml-security/xmlsec.example.php
<?
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;

?>
Return current item: XML Security