Skip to content

Instantly share code, notes, and snippets.

@brankoajzele
Created January 7, 2013 08:52
Show Gist options
  • Save brankoajzele/4473443 to your computer and use it in GitHub Desktop.
Save brankoajzele/4473443 to your computer and use it in GitHub Desktop.
Fiskalizacija - digitalni potpis
<?php
public function digitallySignXml($XMLContent, $ReferenceNodeName, $store)
{
$cert = Mage::getModel('inchoo_fiskalizacija/cert');
//$cert->load(Mage::app()->getWebsite()->getId(), 'website_id');
$cert->load(Mage::getModel('core/store')->load($store)->getWebsiteId(), 'website_id');
$doc = new DOMDocument();
$doc->loadXML($XMLContent);
$objDSig = new XMLSecurityDSig(true);
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
$options['id_name'] = 'Id';
$options['overwrite'] = false;
$objDSig->addReference($doc->getElementsByTagName($ReferenceNodeName)->item(0), XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#'), $options);
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
$objKey->passphrase = $cert->getPemPrivateKeyPassphrase();
$objKey->loadKey($cert->getPemPrivateKey(), false);
$objDSig->sign($objKey);
$objDSig->loadCertData($cert->getPemPublicCert(), false);
$objDSig->add509Cert($cert->getPemPublicCert());
$objDSig->insertSignature($doc->getElementsByTagName($ReferenceNodeName)->item(0));
return $doc->saveXML();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment