mcroitor / XmlSignature

Xml Signature Implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XmlSignature

Xml Signature Implementation. This class is proposed for SOAP messages signing.

Properties description

Class XMLSignature can be initialized with an array of options:

  • private_key_path -- path to private certificate. This certificate can be stored in PEM or PFX format.
  • passkey password for private key.
  • public_key_path -- path to public certificate. If PFX private key was used, public key will be extracted from PFX store.
  • trusted_key_path -- an array of path to trusted keys. Is useful when Soap server has multiple registered clients.
  • digest_algorithm -- Algorithm for digest calculation. Default value is sha1.
  • signature_algorithm -- Algorithm for digest calculation. Default value is rsa-sha1.
  • binary_token -- Use binarySecurityToken or not. Default value is false.

Sample

$options = [
    "private_key_path" => "/path/to/private.pem",
    "public_key_path" => "/path/to/public/cer",
    "passkey" => $passkey,
    "trusted_key_path" => [ "/path/to/truested.cer" ]
];

try {
    /* ------- sign ------- */
    $signature = new XMLSignature($options);
    $request = file_get_contents("request_unsigned.xml");
    $raw = $signature->apply($request);
    file_put_contents("request_signed.xml", $raw->C14N(true));
    echo "request signed successful\n";
} catch (Exception $ex) {
    echo "error: {$ex->getCode()}, {$ex->getMessage()}";
}

try {
    /* ------- validate --- */
    $signature = new XMLSignature($options);
    $request = file_get_contents("request_signed.xml");
    $raw = $signature->validate($request);
    file_put_contents("request_validated.xml", $raw->C14N(true));
    echo "request validated successful\n";
} catch (Exception $ex) {
    echo "error: {$ex->getCode()}, {$ex->getMessage()}";
}

About

Xml Signature Implementation


Languages

Language:PHP 99.8%Language:Batchfile 0.2%