PHP Classes

File: web/SSO/vendor/simplesamlphp/xmlseclibs/tests/xmlsec-encrypt-noreplace.phpt

Recommend this page to a friend!
  Classes of william amed   Raptor 2   web/SSO/vendor/simplesamlphp/xmlseclibs/tests/xmlsec-encrypt-noreplace.phpt   Download  
File: web/SSO/vendor/simplesamlphp/xmlseclibs/tests/xmlsec-encrypt-noreplace.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: 937 bytes
 

Contents

Class file image Download
--TEST--
Encryption without modifying original data
--FILE--
<?php
require(dirname(__FILE__) . '/../xmlseclibs.php');

$dom = new DOMDocument();
$dom->load(dirname(__FILE__) . '/basic-doc.xml');

$origData = $dom->saveXML();

$objKey = new XMLSecurityKey(XMLSecurityKey::AES256_CBC);
$objKey->generateSessionKey();

$siteKey = new XMLSecurityKey(XMLSecurityKey::RSA_OAEP_MGF1P, array('type'=>'public'));
$siteKey->loadKey(dirname(__FILE__) . '/mycert.pem', TRUE, TRUE);

$enc = new XMLSecEnc();
$enc->setNode($dom->documentElement);
$enc->encryptKey($siteKey, $objKey);

$enc->type = XMLSecEnc::Element;
$encNode = $enc->encryptNode($objKey, FALSE);

$newData = $dom->saveXML();
if (
$newData !== $origData) {
    echo
"Original data was modified.\n";
}

if (
$encNode->namespaceURI !== XMLSecEnc::XMLENCNS || $encNode->localName !== 'EncryptedData') {
    echo
"Encrypted node wasn't a <xenc:EncryptedData>-element.\n";
}

?>
--EXPECTF--