PHP Classes

File: web/SSO/vendor/simplesamlphp/xmlseclibs/tests/sign-c14-comments.phpt

Recommend this page to a friend!
  Classes of william amed   Raptor 2   web/SSO/vendor/simplesamlphp/xmlseclibs/tests/sign-c14-comments.phpt   Download  
File: web/SSO/vendor/simplesamlphp/xmlseclibs/tests/sign-c14-comments.phpt
Role: Example script
Content type: text/plain
Description: Example script
Class: Raptor 2
Framework that takes routes from annotations
Author: By
Last change:
Date: 8 years ago
Size: 1,659 bytes
 

Contents

Class file image Download
--TEST--
C14N_COMMENTS signatures.
--DESCRIPTION--
Test signing with C14N with comments.
--FILE--
<?php
require(dirname(__FILE__) . '/../xmlseclibs.php');

if (
file_exists(dirname(__FILE__) . '/sign-c14-comments.xml')) {
   
unlink(dirname(__FILE__) . '/sign-c14-comments.xml');
}

$xml = "<ApplicationRequest xmlns=\"http://example.org/xmldata/\"><CustomerId>12345678</CustomerId><Command>GetUserInfo</Command><Timestamp>1317032524</Timestamp><Status>ALL</Status><Environment>DEVELOPMENT</Environment><SoftwareId>ExampleApp 0.1\b</SoftwareId><FileType>ABCDEFG</FileType></ApplicationRequest>";

$doc = new DOMDocument();
$doc->formatOutput = false;
$doc->preserveWhiteSpace = false;
$doc->loadXML($xml);

$objDSig = new XMLSecurityDSig();

$objDSig->setCanonicalMethod(XMLSecurityDSig::C14N_COMMENTS);

$objDSig->addReference($doc, XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature', XMLSecurityDSig::C14N_COMMENTS));

$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
/* load private key */
$objKey->loadKey(dirname(__FILE__) . '/privkey.pem', TRUE);

$objDSig->sign($objKey, $doc->documentElement);

/* Add associated public key */
$objDSig->add509Cert(file_get_contents(dirname(__FILE__) . '/mycert.pem'));

$objDSig->appendSignature($doc->documentElement);

$doc->save(dirname(__FILE__) . '/sign-c14-comments.xml');

$sign_output = file_get_contents(dirname(__FILE__) . '/sign-c14-comments.xml');
$sign_output_def = file_get_contents(dirname(__FILE__) . '/sign-c14-comments.res');
if (
$sign_output != $sign_output_def) {
    echo
"NOT THE SAME";
}
echo
"DONE";
?>
--EXPECTF--
DONE